1#ifndef DUNE_FEM_OPERATOR_COMMON_LOCALCONTRIBUTION_HH
2#define DUNE_FEM_OPERATOR_COMMON_LOCALCONTRIBUTION_HH
12#include <dune/fem/common/utility.hh>
13#include <dune/fem/function/common/localcontribution.hh>
14#include <dune/fem/operator/common/operator.hh>
15#include <dune/fem/operator/common/temporarylocalmatrix.hh>
16#include <dune/fem/storage/rowreferencevector.hh>
17#include <dune/fem/storage/subvector.hh>
34 template<
class AssembledOperator >
35 struct AddBase< AssembledOperator,
std::enable_if_t< Fem::IsAssembledOperator< AssembledOperator >::value > >
37 template <
class DF,
class RF>
39 template <
class DF,
class RF>
48 template<
class AssembledOperator >
49 struct SetBase< AssembledOperator,
std::enable_if_t< Fem::IsAssembledOperator< AssembledOperator >::value > >
51 template <
class DF,
class RF>
53 template <
class DF,
class RF>
65 template<
class LocalMatrix >
66 struct LocalMatrixGetter
68 typedef typename LocalMatrix::value_type value_type;
70 explicit LocalMatrixGetter (
const LocalMatrix &localMatrix ) : localMatrix_( localMatrix ) {}
72 decltype( auto )
operator[] (
int row )
const {
return localMatrix_[ row ]; }
74 value_type
get (
int row,
int col )
const {
return localMatrix_[ row ][ col ]; }
76 const LocalMatrix & localMatrix()
const {
return localMatrix_; }
79 const LocalMatrix &localMatrix_;
89 template<
class AssembledOperator >
90 struct AddBase< AssembledOperator,
std::enable_if_t< Fem::IsAssembledOperator< AssembledOperator >::value > >
94 typedef Global::Add< AssembledOperator > GlobalOperationType;
96 template<
class DomainEntity,
class RangeEntity,
class LocalMatrix >
97 void begin (
const DomainEntity &domainEntity,
const RangeEntity &rangeEntity,
const AssembledOperator &op, LocalMatrix &localMatrix )
const
102 template<
class DomainEntity,
class RangeEntity,
class LocalMatrix >
103 void end (
const DomainEntity &domainEntity,
const RangeEntity &rangeEntity, LocalMatrix &localMatrix, AssembledOperator &op )
const
105 op.addLocalMatrix( domainEntity, rangeEntity, Impl::LocalMatrixGetter< LocalMatrix >( localMatrix ) );
114 template<
class AssembledOperator >
115 struct AddScaledBase< AssembledOperator,
std::enable_if_t< Fem::IsAssembledOperator< AssembledOperator >::value > >
116 :
public AddBase< AssembledOperator >
120 AddScaledBase ( value_type factor ) : factor_(
std::move( factor ) ) {}
122 template<
class DomainEntity,
class RangeEntity,
class LocalMatrix >
123 void end (
const DomainEntity &domainEntity,
const RangeEntity &rangeEntity, LocalMatrix &localMatrix, AssembledOperator &op )
const
125 op.addScaledLocalMatrix( domainEntity, rangeEntity, Impl::LocalMatrixGetter< LocalMatrix >( localMatrix ), factor_ );
137 template<
class AssembledOperator, const
bool getAndSet >
138 struct SetAndSelectBaseImpl
142 typedef Global::Set< AssembledOperator > GlobalOperationType;
144 template<
class DomainEntity,
class RangeEntity,
class LocalMatrix >
145 void begin (
const DomainEntity &domainEntity,
const RangeEntity &rangeEntity,
const AssembledOperator &op, LocalMatrix &localMatrix )
const
147 if constexpr ( getAndSet )
150 op.getLocalMatrix( domainEntity, rangeEntity, localMatrix );
158 template<
class DomainEntity,
class RangeEntity,
class LocalMatrix >
159 void end (
const DomainEntity &domainEntity,
const RangeEntity &rangeEntity, LocalMatrix &localMatrix, AssembledOperator &op )
const
161 op.setLocalMatrix( domainEntity, rangeEntity, Impl::LocalMatrixGetter< LocalMatrix >( localMatrix ) );
167 template<
class AssembledOperator >
168 struct SetBase< AssembledOperator,
std::enable_if_t< Fem::IsAssembledOperator< AssembledOperator >::value > >
169 :
public SetAndSelectBaseImpl< AssembledOperator, false >
176 template<
class AssembledOperator >
177 struct SetSelectedBase< AssembledOperator,
std::enable_if_t< Fem::IsAssembledOperator< AssembledOperator >::value > >
178 :
public SetAndSelectBaseImpl< AssembledOperator, true >
193 template<
class AssembledOperator,
template<
class >
class AssemblyOperation >
194 class LocalContribution< AssembledOperator, AssemblyOperation,
std::enable_if_t< Fem::IsAssembledOperator< AssembledOperator >::value > >
195 :
public TemporaryLocalMatrix< typename AssembledOperator::DomainFunctionType::DiscreteFunctionSpaceType,
196 typename AssembledOperator::RangeFunctionType::DiscreteFunctionSpaceType
200 typedef AssembledOperator AssembledOperatorType;
201 typedef AssemblyOperation< AssembledOperator > AssemblyOperationType;
203 typedef typename AssembledOperatorType::DomainFunctionType::DiscreteFunctionSpaceType DomainSpaceType;
204 typedef typename AssembledOperatorType::RangeFunctionType::DiscreteFunctionSpaceType RangeSpaceType;
207 typedef LocalContribution< AssembledOperator, AssemblyOperation > ThisType;
208 typedef TemporaryLocalMatrix< DomainSpaceType, RangeSpaceType > BaseType;
211 typedef typename DomainSpaceType::BasisFunctionSetType DomainBasisFunctionSetType;
212 typedef typename RangeSpaceType::BasisFunctionSetType RangeBasisFunctionSetType;
214 typedef typename DomainBasisFunctionSetType::EntityType DomainEntityType;
215 typedef typename RangeBasisFunctionSetType::EntityType RangeEntityType;
217 typedef typename AssembledOperatorType::RangeFieldType value_type;
219 typedef typename BaseType :: MatrixEntriesType LocalMatrixEntriesType;
220 typedef typename LocalMatrixEntriesType::size_type SizeType;
222 typedef RowReferenceVector< value_type > row_reference;
223 typedef RowReferenceVector< const value_type > const_row_reference;
226 template<
class T,
class... U >
228 :
public std::integral_constant< bool, Std::Or( std::is_same< T, U >::value... ) >
233 :
public InTypeRange< T, typename RangeBasisFunctionSetType::RangeType,
234 typename RangeBasisFunctionSetType::JacobianRangeType,
235 typename RangeBasisFunctionSetType::HessianRangeType >
238 struct ColIndexMapper
240 ColIndexMapper ( SizeType j, SizeType cols ) : j_( j ), cols_( cols ) {}
242 SizeType operator[] ( SizeType i )
const {
return (i*cols_ + j_); }
249 using BaseType::mat_cols;
252 using BaseType::domainBasisFunctionSet;
253 using BaseType::rangeBasisFunctionSet;
255 template<
class... Args >
256 explicit LocalContribution ( AssembledOperator &assembledOperator, Args &&... args )
257 : BaseType( assembledOperator.domainSpace(), assembledOperator.rangeSpace() ),
258 assembledOperator_( assembledOperator ),
259 assemblyOperation_(
std::forward< Args >( args )... )
261 assembledOperator.template beginAssemble< typename AssemblyOperationType::GlobalOperationType >();
264 LocalContribution (
const ThisType & ) =
delete;
265 LocalContribution ( ThisType && ) =
delete;
267 ~LocalContribution () { assembledOperator().template endAssemble< typename AssemblyOperationType::GlobalOperationType >(); }
269 ThisType &operator= (
const ThisType & ) =
delete;
270 ThisType &operator= ( ThisType && ) =
delete;
272 const AssembledOperatorType &assembledOperator ()
const {
return assembledOperator_; }
273 AssembledOperatorType &assembledOperator () {
return assembledOperator_; }
275 SubVector< LocalMatrixEntriesType, ColIndexMapper > column ( SizeType j )
277 return SubVector< LocalMatrixEntriesType, ColIndexMapper >( localMatrixEntries(), ColIndexMapper( j, mat_cols() ) );
280 SubVector< const LocalMatrixEntriesType, ColIndexMapper > column ( SizeType j )
const
282 return SubVector< const LocalMatrixEntriesType, ColIndexMapper >( localMatrixEntries(), ColIndexMapper( j, mat_cols() ) );
286 typename BaseType::MatrixColumnType matrixColumn( SizeType j )
288 return BaseType::column( j );
292 using BaseType :: axpy;
294 template<
class Point,
class... Factors >
295 auto axpy (
const Point &x,
const Factors &... factors )
296 -> std::enable_if_t< Std::And( (IsRangeValue< std::decay_t< decltype( std::declval< Factors & >()[ 0 ] ) > >::value)... ) >
298 const SizeType matCols = mat_cols();
299 for( SizeType j = 0; j < matCols; ++j )
301 auto col = column( j );
302 rangeBasisFunctionSet().axpy( x, factors[ j ]..., col );
317 int order ()
const {
return domainBasisFunctionSet().order() + rangeBasisFunctionSet().order(); }
320 void bind (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
322 BaseType::bind( domainEntity, rangeEntity );
323 assemblyOperation_.begin( domainEntity, rangeEntity, assembledOperator(), *
this );
329 assemblyOperation_.end( domainBasisFunctionSet().entity(), rangeBasisFunctionSet().entity(), *
this, assembledOperator() );
334 const LocalMatrixEntriesType &localMatrixEntries ()
const {
return fields_; }
336 LocalMatrixEntriesType &localMatrixEntries () {
return fields_; }
339 using BaseType::fields_;
340 AssembledOperatorType &assembledOperator_;
341 AssemblyOperationType assemblyOperation_;
abstract matrix operator
Definition: operator.hh:133
virtual void flushAssembly()
commit intermediate states of linear operator assembly
Definition: operator.hh:136
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
This file implements a dense vector with a dynamic size.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
RangeFunction::RangeFieldType RangeFieldType
field type of the operator's range
Definition: operator.hh:43