1#ifndef DUNE_FEM_DISCRETEFUNCTION_INLINE_HH
2#define DUNE_FEM_DISCRETEFUNCTION_INLINE_HH
6#include <dune/geometry/referenceelements.hh>
25 template<
class Impl >
33 ldvAllocator_( &ldvStack_ ),
34 localFunction_( space() ),
36 scalarProduct_( dfSpace )
41 template<
class Impl >
43 : dfSpace_(
std::move( dfSpace ) ),
47 ldvAllocator_( &ldvStack_ ),
48 localFunction_( space() ),
49 name_(
std::move( name ) ),
50 scalarProduct_( dfSpace )
54 template<
class Impl >
56 : BaseType( static_cast< const BaseType & >( other ) ),
57 dfSpace_( other.dfSpace_ ),
58 ldvStack_(
std::
max(
std::
max( sizeof( DofType ), sizeof( DofType* ) ),
59 sizeof(typename LocalDofVectorType::value_type) )
60 * space().blockMapper().maxNumDofs() * DiscreteFunctionSpaceType::localBlockSize ),
61 ldvAllocator_( &ldvStack_ ),
62 localFunction_( space() ),
64 scalarProduct_( other.scalarProduct_ )
67 DUNE_THROW( InvalidStateException,
"Cannot copy discrete function during assembly" );
72 template<
class Impl >
75 : BaseType( static_cast< BaseType&& >( other ) ),
76 dfSpace_(
std::move( other.dfSpace_ ) ),
77 ldvStack_(
std::move( other.ldvStack_ ) ),
78 ldvAllocator_( &ldvStack_ ),
79 localFunction_( space() ),
80 name_(
std::move( other.name_ ) ),
81 scalarProduct_(
std::move( other.scalarProduct_ ) )
84 DUNE_THROW( InvalidStateException,
"Cannot move discrete function during assembly" );
89 template<
class Impl >
93 const auto end = BaseType :: dend();
94 for(
auto dit = BaseType :: dbegin(); dit != end; ++dit )
95 out << (*dit) << std::endl;
99 template<
class Impl >
103 const auto end = BaseType :: dend();
104 for(
auto it = BaseType :: dbegin(); it != end; ++it )
106 if( ! std::isfinite( *it ) )
114 template<
class Impl >
115 template<
class DFType >
119 if( BaseType::size() != g.
size() )
120 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in axpy");
123 const auto end = BaseType::dend();
125 for(
auto it = BaseType::dbegin(); it != end; ++it, ++git )
130 template<
class Impl >
131 template<
class DFType >
135 if( BaseType::size() != g.
size() )
137 std::cout << BaseType::size() <<
" vs " << g.
size() << std::endl;
138 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in assign");
142 const auto end = BaseType::dend();
144 for(
auto it = BaseType::dbegin(); it != end; ++it, ++git )
149 template<
class Impl >
150 template<
class Operation >
152 :: template CommDataHandle< Operation > :: Type
155 return BaseType :: space().createDataHandle( asImp(), operation );
159 template<
class Impl >
160 template<
class Functor >
164 typedef typename DiscreteFunctionSpaceType::GridPartType
GridPartType;
167 const auto& entity(entitySearch( x ));
168 const auto geometry = entity.geometry();
171 auto guard =
bindGuard( localFunction_, entity );
173 getLocalDofs( entity, localFunction_.localDofVector());
175 functor( geometry.local( x ), localFunction_ );
179 template<
class Impl >
180 template<
class DFType >
185 if( BaseType::size() != g.
size() )
186 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in operator +=");
188 const auto end = BaseType::dend();
190 for(
auto it = BaseType::dbegin(); it != end; ++it, ++git )
196 template<
class Impl >
197 template<
class DFType >
202 if( BaseType::size() != g.
size() )
203 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in operator -=");
205 const auto end = BaseType :: dend();
207 for(
auto it = BaseType :: dbegin(); it != end; ++it, ++git )
213 template<
class Impl >
214 template<
class StreamTraits >
218 auto versionId =
in.readUnsignedInt();
219 if( versionId < DUNE_VERSION_ID(0,9,1) )
220 DUNE_THROW( IOError,
"Trying to read outdated file." );
221 else if( versionId > DUNE_MODULE_VERSION_ID(DUNE_FEM) )
222 std :: cerr <<
"Warning: Reading discrete function from newer version: "
223 << versionId << std :: endl;
226 if( versionId >= DUNE_VERSION_ID(1,5,0) )
230 const auto spaceId = space().type();
235 if( spaceId != mySpaceId )
236 DUNE_THROW( IOError,
"Trying to read discrete function from different space: DFSpace (" <<
spaceName( spaceId ) <<
") != DataSpace (" <<
spaceName( mySpaceId ) <<
")" );
247 if(
static_cast< int >( mysize ) != BaseType::size() )
248 DUNE_THROW( IOError,
"Trying to read discrete function of different size." );
249 if( BaseType::size() !=
static_cast< int >( this->space().size() ) )
250 DUNE_THROW( InvalidStateException,
"Trying to read discrete function in uncompressed state." );
253 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
254 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
255 typedef typename BlockMapperType::SizeType
SizeType;
257 const BlockMapperType &blockMapper = this->space().blockMapper();
258 const SizeType nBlocks = blockMapper.size();
259 for(
SizeType i = 0; i < nBlocks; ++i )
261 auto &&block = this->dofVector()[ i ];
267 asImp().enableDofCompression();
271 template<
class Impl >
272 template<
class StreamTraits >
276 unsigned int versionId = DUNE_MODULE_VERSION_ID(DUNE_FEM);
280 auto spaceId = space().type();
287 if( BaseType::size() !=
static_cast< int >( this->space().size() ) )
288 DUNE_THROW( InvalidStateException,
"Trying to write DiscreteFunction in uncompressed state." );
291 const int32_t mysize = BaseType::size();
295 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
296 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
297 typedef typename BlockMapperType::SizeType
SizeType;
299 const BlockMapperType &blockMapper = this->space().blockMapper();
300 const SizeType nBlocks = blockMapper.size();
301 for(
SizeType i = 0; i < nBlocks; ++i )
303 const auto block = this->dofVector()[ i ];
309 template<
class Impl >
313 typedef typename DiscreteFunctionSpaceType::IndexSetType IndexSetType;
314 IndexSetType& indexSet = (IndexSetType&)space().indexSet();
320 if( persistentIndexSet )
321 persistentIndexSet->addBackupRestore();
325 template<
class Impl >
329 typedef typename DiscreteFunctionSpaceType::IndexSetType IndexSetType;
330 IndexSetType& indexSet = (IndexSetType&)space().indexSet();
336 if( persistentIndexSet )
337 persistentIndexSet->removeBackupRestore();
342 template<
class Impl >
343 template<
class DFType >
347 if( BaseType :: size() != g.
size() )
350 const auto end = BaseType :: dend();
352 auto fit = BaseType :: dbegin();
354 for( ; fit != end; ++fit, ++git )
356 if(
std::abs( *fit - *git ) > 1e-15 )
375 template<
class Impl >
376 inline std :: ostream &
395 template<
class StreamTraits,
class Impl >
415 template<
class StreamTraits,
class Impl >
416 inline InStreamInterface< StreamTraits > &
DFSpaceIdentifier
enumerator for identification of spaces
Definition: discretefunctionspace.hh:94
std::string spaceName(const DFSpaceIdentifier id)
Definition: discretefunctionspace.hh:109
Dune::Fem::Double abs(const Dune::Fem::Double &a)
Definition: double.hh:942
Definition: bindguard.hh:11
OutStreamInterface< StreamTraits > & operator<<(OutStreamInterface< StreamTraits > &out, const DiscreteFunctionInterface< Impl > &df)
write a discrete function into an output stream
Definition: discretefunction_inline.hh:397
static double max(const Double &v, const double p)
Definition: double.hh:398
static auto bindGuard(Object &object, Args &&... args) -> std::enable_if_t< isBindable< Object, Args... >::value, BindGuard< Object > >
Definition: bindguard.hh:67
static std::shared_ptr< T > referenceToSharedPtr(T &t)
Definition: memory.hh:19
InStreamInterface< StreamTraits > & operator>>(InStreamInterface< StreamTraits > &in, DiscreteFunctionInterface< Impl > &df)
read a discrete function from an input stream
Definition: discretefunction_inline.hh:417
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
Definition: common/discretefunction.hh:578
void print(std ::ostream &out) const
print all DoFs to a stream (for debugging purposes)
Definition: discretefunction_inline.hh:91
DiscreteFunctionDefault(const std::string &name, const DiscreteFunctionSpaceType &dfSpace)
Constructor storing discrete function space and local function factory.
Definition: discretefunction_inline.hh:27
DiscreteFunctionType & operator-=(const DiscreteFunctionInterface< DFType > &g)
substract all degrees of freedom from given discrete function using the dof iterators
Definition: discretefunction_inline.hh:200
void write(OutStreamInterface< StreamTraits > &out) const
write the discrete function into a stream
Definition: discretefunction_inline.hh:274
DiscreteFunctionType & operator+=(const DiscreteFunctionInterface< DFType > &g)
add another discrete function to this one
Definition: discretefunction_inline.hh:183
bool dofsValid() const
check for NaNs
Definition: discretefunction_inline.hh:101
DofVectorType::SizeType SizeType
size type of the block vector
Definition: common/discretefunction.hh:646
Traits::LocalDofVectorType LocalDofVectorType
type of LocalDofVector
Definition: common/discretefunction.hh:628
std::type_index assembleOperation_
Definition: common/discretefunction.hh:1042
void evaluateGlobal(const DomainType &x, Functor functor) const
evaluate functor in global coordinate
Definition: discretefunction_inline.hh:162
void read(InStreamInterface< StreamTraits > &in)
read the discrete function from a stream
Definition: discretefunction_inline.hh:216
virtual void insertSubData()
Definition: discretefunction_inline.hh:311
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: common/discretefunction.hh:600
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:133
virtual void removeSubData()
Definition: discretefunction_inline.hh:327
CommDataHandle< Operation >::Type dataHandle(const Operation &operation)
return reference to data handle object
void axpy(const RangeFieldType &s, const DiscreteFunctionInterface< DFType > &g)
axpy operation
Definition: discretefunction_inline.hh:117
std::size_t assembleCount_
Definition: common/discretefunction.hh:1043
bool operator==(const DiscreteFunctionInterface< DFType > &g) const
Definition: discretefunction_inline.hh:345
Definition: common/discretefunction.hh:86
void write(OutStreamInterface< StreamTraits > &out) const
write the discrete function into a stream
Definition: common/discretefunction.hh:537
ConstDofIteratorType dbegin() const
obtain an iterator pointing to the first DoF (read-only)
Definition: common/discretefunction.hh:354
void print(std ::ostream &out) const
print all DoFs to a stream (for debugging purposes)
Definition: common/discretefunction.hh:437
void read(InStreamInterface< StreamTraits > &in)
read the discrete function from a stream
Definition: common/discretefunction.hh:527
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
type of range field, i.e. dof type
Definition: common/discretefunction.hh:109
DiscreteFunctionSpaceType::DomainType DomainType
type of domain, i.e. type of coordinates
Definition: common/discretefunction.hh:111
Traits::DofType DofType
Definition: common/discretefunction.hh:136
DiscreteFunctionSpaceType::GridPartType GridPartType
type of the underlying grid part
Definition: common/discretefunction.hh:118
int size() const
obtain total number of DoFs
Definition: common/discretefunction.hh:333
Definition: entitysearch.hh:131
capability for persistent index sets
Definition: persistentindexset.hh:92
static constexpr PersistentIndexSetInterface * map(IndexSet &indexSet) noexcept
please doc me
Definition: persistentindexset.hh:101
abstract interface for an output stream
Definition: streams.hh:46
abstract interface for an input stream
Definition: streams.hh:179