1#ifndef DUNE_FEM_FUNCTION_COMMON_LOCALCONTRIBUTION_HH
2#define DUNE_FEM_FUNCTION_COMMON_LOCALCONTRIBUTION_HH
12#include <dune/fem/common/hybrid.hh>
13#include <dune/fem/common/localcontribution.hh>
14#include <dune/fem/space/common/commoperations.hh>
15#include <dune/fem/function/localfunction/temporary.hh>
27 struct DiscreteFunctionTraits;
29 class IsDiscreteFunction;
42 template<
class DiscreteFunction >
43 struct AddBase< DiscreteFunction,
std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > >
45 typedef typename DiscreteFunction::DofType DofType;
47 static void begin ( DiscreteFunction &df )
49 typedef typename DiscreteFunction::DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
52 auto &dofVector = df.dofVector();
53 for(
const auto &auxiliaryDof : df.space().auxiliaryDofs() )
54 Hybrid::forEach( LocalBlockIndices(), [ &dofVector, &auxiliaryDof ] (
auto &&j ) { dofVector[ auxiliaryDof ][ j ] = DofType( 0 ); } );
57 static void end ( DiscreteFunction &df,
const bool communicate )
61 df.space().communicate( df, DFCommunicationOperation::Add() );
71 template<
class DiscreteFunction >
72 struct SetBase< DiscreteFunction,
std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > >
74 static void begin ( DiscreteFunction &df ) {}
75 static void end ( DiscreteFunction &df,
const bool communicate )
79 df.space().communicate( df, DFCommunicationOperation::Copy() );
91 template<
class DiscreteFunction >
92 struct AddBase< DiscreteFunction,
std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > >
94 typedef typename DiscreteFunction::DofType DofType;
96 typedef Global::Add< DiscreteFunction > GlobalOperationType;
98 template<
class Entity,
class LocalDofVector >
99 void begin (
const Entity &entity,
const DiscreteFunction &df, LocalDofVector &localDofVector )
const
101 std::fill( localDofVector.begin(), localDofVector.end(), DofType( 0 ) );
104 template<
class Entity,
class LocalDofVector >
105 void end (
const Entity &entity, LocalDofVector &localDofVector, DiscreteFunction &df )
const
107 df.addLocalDofs( entity, localDofVector );
116 template<
class DiscreteFunction >
117 struct AddScaledBase< DiscreteFunction,
std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > >
118 :
public AddBase< DiscreteFunction >
120 AddScaledBase (
typename DiscreteFunction::DofType factor ) : factor_(
std::move( factor ) ) {}
122 template<
class Entity,
class LocalDofVector >
123 void end (
const Entity &entity, LocalDofVector &localDofVector, DiscreteFunction &df )
const
125 df.addScaledLocalDofs( entity, factor_, localDofVector );
129 typename DiscreteFunction::DofType factor_;
136 template<
class DiscreteFunction, const
bool getAndSet >
137 struct SetAndSelectDFImpl
139 typedef typename DiscreteFunction::DofType DofType;
141 typedef Global::Set< DiscreteFunction > GlobalOperationType;
143 template<
class Entity,
class LocalDofVector >
144 void begin (
const Entity &entity,
const DiscreteFunction &df, LocalDofVector &localDofVector )
const
146 if constexpr ( getAndSet )
149 df.getLocalDofs ( entity, localDofVector );
154 std::fill( localDofVector.begin(), localDofVector.end(), DofType( 0 ) );
158 template<
class Entity,
class LocalDofVector >
159 void end (
const Entity &entity, LocalDofVector &localDofVector, DiscreteFunction &df )
const
161 df.setLocalDofs( entity, localDofVector );
170 template<
class DiscreteFunction >
171 struct SetBase< DiscreteFunction,
std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > >
172 :
public detail::SetAndSelectDFImpl< DiscreteFunction, false >
178 template<
class DiscreteFunction >
179 struct SetSelectedBase< DiscreteFunction,
std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > >
180 :
public detail::SetAndSelectDFImpl< DiscreteFunction, true >
187 template<
class DiscreteFunction,
template<
class >
class AssemblyOperation >
188 struct FieldTraits< Fem::LocalContribution< DiscreteFunction, AssemblyOperation, std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > > >
189 :
public FieldTraits< typename DiscreteFunction::DofType >
200 template<
class DiscreteFunction,
template<
class >
class AssemblyOperation >
201 class LocalContribution< DiscreteFunction, AssemblyOperation,
std::enable_if_t< std::is_base_of< Fem::IsDiscreteFunction, DiscreteFunction >::value > >
202 :
public TemporaryLocalFunction< typename DiscreteFunction::DiscreteFunctionSpaceType >
204 typedef typename DiscreteFunction::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
205 typedef LocalContribution< DiscreteFunction, AssemblyOperation > ThisType;
210 typedef AssemblyOperation< typename DiscreteFunctionTraits< DiscreteFunctionType >::DiscreteFunctionType > AssemblyOperationType;
212 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType::BasisFunctionSetType BasisFunctionSetType;
213 typedef typename DiscreteFunctionType::DofType DofType;
216 typedef typename RangeType::field_type RangeFieldType;
219 typedef typename BaseType :: LocalDofVectorType LocalDofVectorType;
220 typedef typename LocalDofVectorType::size_type SizeType;
222 typedef typename BasisFunctionSetType::EntityType EntityType;
224 using BaseType::entity;
225 using BaseType::localDofVector;
226 using BaseType::axpy;
228 template<
class... Args >
229 explicit LocalContribution (
DiscreteFunctionType &discreteFunction,
const bool communicate, Args &&... args )
230 : BaseType( discreteFunction.space() ),
231 discreteFunction_( discreteFunction ),
232 assemblyOperation_(
std::forward< Args >( args )... ),
233 communicate_( communicate ),
236 discreteFunction.template beginAssemble< typename AssemblyOperationType::GlobalOperationType >();
239 template<
class... Args >
241 : LocalContribution( discreteFunction, true, args... )
244 LocalContribution (
const ThisType & ) =
delete;
245 LocalContribution ( ThisType && ) =
delete;
247 ~LocalContribution () { discreteFunction().template endAssemble< typename AssemblyOperationType::GlobalOperationType >( communicate_ ); }
249 ThisType &operator= (
const ThisType & ) =
delete;
250 ThisType &operator= ( ThisType && ) =
delete;
255 void bind (
const EntityType &entity )
257 BaseType::bind( entity );
259 assemblyOperation_.begin( entity, discreteFunction(), localDofVector() );
267 assemblyOperation_.end( entity(), localDofVector(), discreteFunction() );
276 using BaseType::evaluate;
277 using BaseType::evaluateQuadrature;
278 using BaseType::jacobian;
279 using BaseType::hessian;
283 AssemblyOperationType assemblyOperation_;
284 const bool communicate_;
DiscreteFunctionSpaceType::RangeType RangeType
type of range vector
Definition: discretefunction.hh:614
DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType
type of jacobian
Definition: discretefunction.hh:616
forward declaration
Definition: discretefunction.hh:51
Implements the dense vector interface, with an exchangeable storage class.
Type traits to determine the type of reals (when working with complex numbers)
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13