DUNE-ACFEM (2.5.1)

l2projection.hh
1 #ifndef __DUNE_ACFEM_L2PROJECTION_HH__
2 #define __DUNE_ACFEM_L2PROJECTION_HH__
3 
4 #include "functionals/linearfunctional.hh"
5 #include "../models/basicmodels.hh"
6 #include "../models/modelexpression.hh"
7 #include "../algorithms/ellipticfemscheme.hh"
8 
9 namespace Dune {
10 
11  namespace ACFem {
12 
51  template<class DiscreteFunction, class Functional>
53  {
54  public:
55  typedef Functional FunctionalType;
56  typedef typename FunctionalType::TraitsType TraitsType;
57  typedef typename FunctionalType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
58  typedef DiscreteFunction DiscreteFunctionType;
59  typedef
62  typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
63  public:
64 
65  void operator()(const FunctionalInterfaceType& phi,
66  DiscreteFunctionType& result)
67  {
68  // skip the initialization, just do a quick loop over "result"
69  // in order to determine that all values are finite
70  auto dend(result.dend());
71  for (auto it = result.dbegin(); it != dend; ++it) {
72  if (!std::isfinite(*it)) {
73  result.clear();
74  break;
75  }
76  }
77 
78  // In principle it should be fine to stuff a MassModel into the
79  // EllipticFemScheme and only call the method scheme.solve() ...
80  //
81  // Let's try. We do not maintain any state, the constructor is
82  // trivial. After all, as all default implementations in
83  // principle should reduce to nothing, this should be fairly
84  // efficient.
85 
86  auto model = massModel(result) - phi;
87  typedef
88  EllipticFemScheme<DiscreteFunctionType, decltype(model)>
89  SolverSchemeType;
90 
91  SolverSchemeType solverScheme(result, model);
92 
93  solverScheme.solve();
94 
95  // And that should be it ...
96  }
97  };
98 
100  template<class FunctionSpace, class GridFunction, class DiscreteFunction>
101  static inline
102  void L2Projection(const Fem::Function<FunctionSpace, GridFunction>& fct,
103  DiscreteFunction& result)
104  {
105  typedef DiscreteFunction DiscreteFunctionType;
106  typedef typename DiscreteFunction::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
107  typedef L2InnerProductFunctional<DiscreteFunctionSpaceType, GridFunction> FunctionalType;
109 
110  FunctionalType functional(result.space(), fct);
111  L2ProjectionType projection;
112 
113  projection(functional, result);
114  }
115 
117  template<class Traits, class DiscreteFunction>
118  static inline
120  DiscreteFunction& result)
121  {
122  typedef typename Traits::GlobalFunctionalType FunctionalType;
123  typedef DiscreteFunction DiscreteFunctionType;
125 
126  const FunctionalType& functional(static_cast<const FunctionalType&>(phi));
127  L2ProjectionType projection;
128 
129  projection(functional, result);
130  }
131 
133 
135 
136  } // ACFem::
137 
138 } // Dune::
139 
140 #endif // __DUNE_ACFEM_L2PROJECTION_HH__
Interface class for a discrete linear functional.
Definition: linearfunctional.hh:52
Constructor for the elliptic fem-scheme.
Definition: ellipticfemscheme.hh:570
Compute the L2-projection of the given functional to a discrete space.
Definition: l2projection.hh:53
static OperatorPartsAdapterModel< MassOperatorParts< typename Object::FunctionSpaceType >, typename Object::GridPartType > massModel(const Object &object, const std::string &name="")
Generate a mass model fitting the specified object.
Definition: massmodel.hh:149
static void L2Projection(const Fem::Function< FunctionSpace, GridFunction > &fct, DiscreteFunction &result)
Perform an L2-projection for any GridFunction.
Definition: l2projection.hh:102
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)