3 #include <amdis/Output.hpp> 4 #include <amdis/common/DerivativeTraits.hpp> 5 #include <amdis/common/FieldMatVec.hpp> 6 #include <amdis/common/Math.hpp> 7 #include <amdis/functions/NodeIndices.hpp> 8 #include <amdis/functions/Order.hpp> 9 #include <amdis/typetree/FiniteElementType.hpp> 10 #include <amdis/utility/LocalToGlobalAdapter.hpp> 12 #include <dune/common/ftraits.hh> 18 template <
class Coeff,
class LocalView,
class LocalCoeff,
19 class = decltype(std::declval<Coeff>().gather(std::declval<LocalView>(), std::declval<LocalCoeff&>()))>
20 void gather(Coeff
const& coeff, LocalView
const& localView, LocalCoeff& localCoeff, Dune::PriorityTag<2>)
22 coeff.gather(localView, localCoeff);
26 template <
class Coeff,
class LocalView,
class LocalCoeff>
27 void gather(Coeff
const& coeff, LocalView
const& localView, LocalCoeff& localCoeff, Dune::PriorityTag<1>)
29 localCoeff.resize(localView.size());
30 auto it = localCoeff.begin();
38 template <
class Coeff,
class GB,
class TP>
42 using Domain =
typename EntitySet::LocalCoordinate;
43 using Range =
typename DiscreteFunction::Range;
45 enum { hasDerivative =
true };
49 using Element =
typename EntitySet::Element;
50 using Geometry =
typename Element::Geometry;
55 : globalFunction_(globalFunction)
56 , localView_(globalFunction_.basis().localView())
57 , subTreeCache_(&
Dune::TypeTree::child(localView_.treeCache(), globalFunction_.treePath()))
62 : globalFunction_(other.globalFunction_)
63 , localView_(globalFunction_.basis().localView())
64 , subTreeCache_(&
Dune::TypeTree::child(localView_.treeCache(), globalFunction_.treePath()))
68 void bind(Element
const& element)
70 localView_.bind(element);
71 Impl::gather(globalFunction_.coefficients(), localView_, localCoefficients_, Dune::PriorityTag<4>{});
88 auto&& nodeToRangeEntry = globalFunction_.nodeToRangeEntry_;
91 auto const& shapeFunctionValues = node.localBasisValuesAt(x);
92 std::size_t size = node.finiteElement().size();
95 auto re = Dune::Functions::flatVectorView(nodeToRangeEntry(node, tp, y));
97 for (std::size_t i = 0; i < size; ++i) {
99 auto c = Dune::Functions::flatVectorView(localCoefficients_[node.localIndex(i)]);
102 auto v = Dune::Functions::flatVectorView(shapeFunctionValues[i]);
104 std::size_t dimC = c.size();
105 std::size_t dimV = v.size();
106 assert(dimC*dimV == std::size_t(re.size()));
107 for(std::size_t j = 0; j < dimC; ++j) {
109 for(std::size_t k = 0; k < dimV; ++k)
110 re[j*dimV + k] += c_j*v[k];
146 return localView_.element();
151 LocalView localView_;
152 SubTreeCache
const* subTreeCache_;
154 std::vector<ValueType> localCoefficients_;
159 template <
class Coeff,
class GB,
class TP>
160 template <
class Type>
163 using R =
typename DiscreteFunction::Range;
164 using D =
typename DiscreteFunction::Domain;
165 using RawSignature =
typename Dune::Functions::SignatureTraits<R(D)>::RawSignature;
169 using Domain =
typename EntitySet::LocalCoordinate;
170 using Range =
typename Traits::Range;
172 enum { hasDerivative =
false };
176 using Element =
typename EntitySet::Element;
177 using Geometry =
typename Element::Geometry;
182 : globalFunction_(globalFunction)
184 , localView_(globalFunction_.basis().localView())
185 , subTreeCache_(&
Dune::TypeTree::child(localView_.treeCache(), globalFunction_.treePath()))
190 : globalFunction_(other.globalFunction_)
192 , localView_(globalFunction_.basis().localView())
193 , subTreeCache_(&
Dune::TypeTree::child(localView_.treeCache(), globalFunction_.treePath()))
196 void bind(Element
const& element)
198 localView_.bind(element);
199 geometry_.emplace(element.geometry());
201 Impl::gather(globalFunction_.coefficients(), localView_, localCoefficients_, Dune::PriorityTag<4>{});
223 return localView_.element();
226 Geometry
const& geometry()
const 229 return geometry_.value();
232 LocalView
const& localView()
const 240 LocalView localView_;
241 SubTreeCache
const* subTreeCache_;
242 std::optional<Geometry> geometry_;
243 std::vector<ValueType> localCoefficients_;
248 template <
class Coeff,
class GB,
class TP>
254 using Range =
typename Super::Range;
255 using Domain =
typename Super::Domain;
263 assert( this->bound_ );
266 auto&& nodeToRangeEntry = this->globalFunction_.nodeToRangeEntry_;
273 auto re = Dune::Functions::flatVectorView(nodeToRangeEntry(node, tp, dy));
275 for (std::size_t i = 0; i < localBasis.
size(); ++i) {
277 auto c = Dune::Functions::flatVectorView(this->localCoefficients_[node.localIndex(i)]);
280 auto grad = Dune::Functions::flatVectorView(gradients[i]);
282 std::size_t dimC = c.size();
283 std::size_t dimV = grad.size();
284 assert(dimC*dimV == std::size_t(re.size()));
285 for(std::size_t j = 0; j < dimC; ++j) {
287 for(std::size_t k = 0; k < dimV; ++k)
288 re[j*dimV + k] += c_j*grad[k];
296 using Super::localCoefficients_;
300 template <
class Coeff,
class GB,
class TP>
307 using Range =
typename Super::Range;
308 using Domain =
typename Super::Domain;
316 return evaluate_node(x,
bool_t<SubTree::isPower && SubTree::degree() == GridView::dimensionworld>{});
320 Range evaluate_node(Domain
const& x, std::false_type)
const 322 error_exit(
"Cannot calculate divergence(node) where node is not a power node.");
326 Range evaluate_node(Domain
const& x, std::true_type)
const 328 static_assert(static_size_v<Range> == 1,
"Implemented for scalar coefficients only.");
330 assert( this->bound_ );
333 auto&& node = *this->subTreeCache_;
338 auto re = Dune::Functions::flatVectorView(dy);
339 assert(
int(re.size()) == 1);
340 for (std::size_t i = 0; i < localBasis.size(); ++i) {
341 auto grad = Dune::Functions::flatVectorView(gradients[i]);
343 assert(
int(grad.size()) == GridView::dimensionworld);
344 for (std::size_t j = 0; j < GridView::dimensionworld; ++j)
345 re[0] += localCoefficients_[node.child(j).localIndex(i)] * grad[j];
351 using Super::localCoefficients_;
355 template <
class Coeff,
class GB,
class TP>
362 using Range =
typename Super::Range;
363 using Domain =
typename Super::Domain;
370 assert( this->bound_ );
373 std::size_t comp = this->type_.comp;
375 auto&& nodeToRangeEntry = this->globalFunction_.nodeToRangeEntry_;
379 auto const& partial = localBasis.
partialsAt(x, comp);
382 auto re = Dune::Functions::flatVectorView(nodeToRangeEntry(node, tp, dy));
384 for (std::size_t i = 0; i < localBasis.
size(); ++i) {
386 auto c = Dune::Functions::flatVectorView(this->localCoefficients_[node.localIndex(i)]);
389 auto d_comp = Dune::Functions::flatVectorView(partial[i]);
391 std::size_t dimC = c.size();
392 std::size_t dimV = d_comp.size();
393 assert(dimC*dimV == std::size_t(re.size()));
394 for(std::size_t j = 0; j < dimC; ++j) {
396 for(std::size_t k = 0; k < dimV; ++k)
397 re[j*dimV + k] += c_j*d_comp[k];
405 using Super::localCoefficients_;
void for_each_leaf_node(Tree &&tree, LeafFunc &&leafFunc)
Traverse tree and visit each leaf node.
Definition: Traversal.hpp:127
Definition: DiscreteLocalFunction.inc.hpp:161
DerivativeLocalFunctionBase(DerivativeLocalFunctionBase const &other)
Copy constructor.
Definition: DiscreteLocalFunction.inc.hpp:189
Range operator()(Domain const &x) const
Evaluate LocalFunction at bound element in local coordinates.
Definition: DiscreteLocalFunction.inc.hpp:83
GradientLocalFunction makeDerivative(tag::gradient type) const
Create a LocalFunction representing the gradient.
Definition: DiscreteLocalFunction.inc.hpp:119
Range operator()(Domain const &x) const
Evaluate Gradient at bound element in local coordinates.
Definition: DiscreteLocalFunction.inc.hpp:261
Convert a simple (scalar) local basis into a global basis.
Definition: LocalToGlobalAdapter.hpp:64
Definition: AdaptiveGrid.hpp:373
Definition: DerivativeTraits.hpp:21
void error_exit(std::string const &str, Args &&... args)
print a message and exit
Definition: Output.hpp:142
Definition: FieldMatVec.hpp:12
AMDiS::LocalView< Self > LocalView
Type of the local view on the restriction of the basis to a single element.
Definition: GlobalBasis.hpp:70
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
constexpr bool LocalView
A Dune::Functions::LocalView type.
Definition: Concepts.hpp:182
A mutable view on the subspace of a DOFVector,.
Definition: DiscreteFunction.hpp:33
Definition: DerivativeTraits.hpp:20
std::size_t size() const
Return the number of local basis functions.
Definition: LocalToGlobalAdapter.hpp:96
Definition: DerivativeTraits.hpp:19
auto order(F const &f) -> decltype(&F::operator(), f.order())
polynomial order of functions
Definition: Order.hpp:11
auto const & partialsAt(typename Traits::DomainLocal const &x, std::size_t comp) const
Definition: LocalToGlobalAdapter.hpp:176
Definition: DiscreteLocalFunction.inc.hpp:356
DerivativeLocalFunctionBase(DiscreteFunction const &globalFunction, Type const &type)
Constructor. Stores a copy of the DiscreteFunction.
Definition: DiscreteLocalFunction.inc.hpp:181
void bind(Element const &element)
Bind the LocalView to the element.
Definition: DiscreteLocalFunction.inc.hpp:68
LocalFunction(DiscreteFunction const &globalFunction)
Constructor. Stores a copy of the DiscreteFunction.
Definition: DiscreteLocalFunction.inc.hpp:54
Range operator()(Domain const &x) const
Evaluate divergence at bound element in local coordinates.
Definition: DiscreteLocalFunction.inc.hpp:314
Element const & localContext() const
Return the bound element.
Definition: DiscreteLocalFunction.inc.hpp:220
LocalFunction(LocalFunction const &other)
Copy constructor.
Definition: DiscreteLocalFunction.inc.hpp:61
Definition: DerivativeTraits.hpp:28
void unbind()
Unbind the LocalView from the element.
Definition: DiscreteLocalFunction.inc.hpp:76
auto order() const -> decltype(AMDiS::order(std::declval< SubTree >()))
The polynomial degree of the LocalFunctions basis-functions.
Definition: DiscreteLocalFunction.inc.hpp:135
std::integral_constant< bool, B > bool_t
A wrapper for bool types.
Definition: Logical.hpp:12
Element const & localContext() const
Return the bound element.
Definition: DiscreteLocalFunction.inc.hpp:143
Range operator()(Domain const &x) const
Evaluate partial derivative at bound element in local coordinates.
Definition: DiscreteLocalFunction.inc.hpp:368
auto nodeIndices(LocalView const &localView, Node const &node)
Returns a range over (flat) DOF indices on a node, given by the localView.
Definition: NodeIndices.hpp:13
Definition: DiscreteLocalFunction.inc.hpp:39
Definition: DiscreteLocalFunction.inc.hpp:249
Definition: DiscreteLocalFunction.inc.hpp:301
auto const & gradientsAt(typename Traits::DomainLocal const &x) const
Definition: LocalToGlobalAdapter.hpp:147