From 6e9f47b678b3a6ff4aed7af11a7eda52c2ebd924 Mon Sep 17 00:00:00 2001
From: Max Kahnt <max.kahnt@fu-berlin.de>
Date: Fri, 21 Nov 2014 12:25:45 +0100
Subject: [PATCH] Remove necessity to specify fallback QuadRuleKey in
 SubgridL2FunctionalAssembler.

Provide two separate constructors instead.
---
 .../subgridl2functionalassembler.hh           | 45 +++++++++++++------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/dune/fufem/assemblers/localassemblers/subgridl2functionalassembler.hh b/dune/fufem/assemblers/localassemblers/subgridl2functionalassembler.hh
index 3d991ad5..da0f7cfb 100644
--- a/dune/fufem/assemblers/localassemblers/subgridl2functionalassembler.hh
+++ b/dune/fufem/assemblers/localassemblers/subgridl2functionalassembler.hh
@@ -50,22 +50,41 @@ class SubgridL2FunctionalAssembler :
          * It can assemble functionals on the subgrid given by grid
          * functions on the underlying hostgrid exactly.
          *
-         * The QuadratureRuleKey given here does only specify what is
-         * needed to integrate f if f is not a BasisGridFunction on
-         * the hostgrid. Otherwise a quadrature rule is determined
-         * automatically.
-         *
-         * \param f the (hostgrid) function representing the functional
+         * \param f the basisgrid function representing the functional
          * \param grid the subgrid (!)
-         * \param fQuadKey A fallback QuadratureRuleKey that specifies how to integrate f if its not a BasisGridFunction on the hostgrid
          */
-        SubgridL2FunctionalAssembler(const HostGridFunction& f, const GridType& grid, const QuadratureRuleKey& fQuadKey) :
-            functionQuadKey_(fQuadKey),
+        template<typename B, typename C, std::enable_if<std::is_base_of<HostGridFunction, BasisGridFunction<B,C>>::value_type>>
+        SubgridL2FunctionalAssembler(const BasisGridFunction<B, C>& f, const GridType& grid) :
+            functionQuadKey_(0),
             grid_(grid),
             f_(f),
-            hostBasisGridFunctionInfo_(dynamic_cast<const HostBasisGridFunctionInfo*>(&f))
+            hostBasisGridFunctionInfo_(&f)
         {}
 
+        /** \brief constructor
+         *
+         * Creates a local functional assembler for an L2-functional.
+         * It can assemble functionals on the subgrid given by grid
+         * functions on the underlying hostgrid exactly.
+         *
+         * The QuadratureRuleKey given here does specify what is
+         * needed to integrate f. It can be used to override the
+         * automatically determined QuadratureRule if f is a BasisGridFunction.
+         *
+         * \param f the hostgrid function representing the functional
+         * \param grid the subgrid (!)
+         * \param fQuadKey A QuadratureRuleKey that specifies how to integrate f
+         */
+         SubgridL2FunctionalAssembler(const HostGridFunction& f, const GridType& grid, const QuadratureRuleKey& fQuadKey) :
+            functionQuadKey_(&fQuadKey),
+            grid_(grid),
+            f_(f),
+            hostBasisGridFunctionInfo_(0)
+        {
+            if(dynamic_cast<const HostBasisGridFunctionInfo*>(&f))
+                Dune::dwarn << "Overriding HostBasis Quadrature rule." << std::endl;
+        }
+
         /** \copydoc L2FunctionalAssembler::assemble
          */
         void assemble(const Element& element, LocalVector& localVector, const TrialLocalFE& tFE) const
@@ -90,7 +109,7 @@ class SubgridL2FunctionalAssembler :
                 if (hostBasisGridFunctionInfo_)
                   quadKey = quadKey.product(hostBasisGridFunctionInfo_->quadratureRuleKey(*baseHostElement));
                 else
-                  quadKey = quadKey.product(functionQuadKey_);
+                  quadKey = quadKey.product(*functionQuadKey_);
                 const Dune::template QuadratureRule<double, dim>& quad = QuadratureRuleCache<double, dim>::rule(quadKey);
 
                 // loop over quadrature points
@@ -136,7 +155,7 @@ class SubgridL2FunctionalAssembler :
                         if (hostBasisGridFunctionInfo_)
                           quadKey = quadKey.product(hostBasisGridFunctionInfo_->quadratureRuleKey(hostElement));
                         else
-                          quadKey = quadKey.product(functionQuadKey_);
+                          quadKey = quadKey.product(*functionQuadKey_);
                         const Dune::template QuadratureRule<double, dim>& quad = QuadratureRuleCache<double, dim>::rule(quadKey);
 
 
@@ -171,7 +190,7 @@ class SubgridL2FunctionalAssembler :
         }
 
     private:
-        const QuadratureRuleKey functionQuadKey_;
+        const QuadratureRuleKey* functionQuadKey_;
         const GridType& grid_;
         const HostGridFunction& f_;
         const HostBasisGridFunctionInfo* hostBasisGridFunctionInfo_;
-- 
GitLab