1#ifndef DUNE_FEM_DISCRETEFUNCTION_INLINE_HH
2#define DUNE_FEM_DISCRETEFUNCTION_INLINE_HH
6#include <dune/geometry/referenceelements.hh>
24 template<
class Impl >
25 inline DiscreteFunctionDefault< Impl >
26 :: DiscreteFunctionDefault (
const std::string &name,
32 ldvAllocator_( &ldvStack_ ),
33 localFunction_( space() ),
35 scalarProduct_( dfSpace )
40 template<
class Impl >
42 : dfSpace_(
std::move( dfSpace ) ),
46 ldvAllocator_( &ldvStack_ ),
47 localFunction_( space() ),
48 name_(
std::move( name ) ),
49 scalarProduct_( dfSpace )
53 template<
class Impl >
56 dfSpace_( other.dfSpace_ ),
60 ldvAllocator_( &ldvStack_ ),
61 localFunction_( space() ),
63 scalarProduct_( other.scalarProduct_ )
66 DUNE_THROW( InvalidStateException,
"Cannot copy discrete function during assembly" );
71 template<
class Impl >
75 dfSpace_(
std::move( other.dfSpace_ ) ),
76 ldvStack_(
std::move( other.ldvStack_ ) ),
77 ldvAllocator_( &ldvStack_ ),
78 localFunction_( space() ),
79 name_(
std::move( other.name_ ) ),
80 scalarProduct_(
std::move( other.scalarProduct_ ) )
82 if( other.assembleOperation_ != std::type_index(
typeid(
void ) ) )
83 DUNE_THROW( InvalidStateException,
"Cannot move discrete function during assembly" );
84 assert( other.assembleCount_ == 0 );
88 template<
class Impl >
92 const auto end = BaseType :: dend();
93 for(
auto dit = BaseType :: dbegin(); dit != end; ++dit )
94 out << (*dit) << std::endl;
98 template<
class Impl >
102 const auto end = BaseType :: dend();
103 for(
auto it = BaseType :: dbegin(); it != end; ++it )
105 if( ! std::isfinite( *it ) )
113 template<
class Impl >
114 template<
class DFType >
118 if( BaseType::size() != g.
size() )
119 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in axpy");
122 const auto end = BaseType::dend();
124 for(
auto it = BaseType::dbegin(); it != end; ++it, ++git )
129 template<
class Impl >
130 template<
class DFType >
134 if( BaseType::size() != g.
size() )
136 std::cout << BaseType::size() <<
" vs " << g.
size() << std::endl;
137 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in assign");
141 const auto end = BaseType::dend();
143 for(
auto it = BaseType::dbegin(); it != end; ++it, ++git )
148 template<
class Impl >
149 template<
class Operation >
151 :: template CommDataHandle< Operation > :: Type
154 return BaseType :: space().createDataHandle( asImp(), operation );
158 template<
class Impl >
159 template<
class Functor >
163 typedef typename DiscreteFunctionSpaceType::GridPartType
GridPartType;
166 const auto& entity(entitySearch( x ));
167 const auto geometry = entity.geometry();
170 auto guard =
bindGuard( localFunction_, entity );
172 getLocalDofs( entity, localFunction_.localDofVector());
174 functor( geometry.local( x ), localFunction_ );
178 template<
class Impl >
179 template<
class DFType >
184 if( BaseType::size() != g.
size() )
185 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in operator +=");
187 const auto end = BaseType::dend();
189 for(
auto it = BaseType::dbegin(); it != end; ++it, ++git )
195 template<
class Impl >
196 template<
class DFType >
201 if( BaseType::size() != g.
size() )
202 DUNE_THROW(InvalidStateException,
"DiscreteFunctionDefault: sizes do not match in operator -=");
204 const auto end = BaseType :: dend();
206 for(
auto it = BaseType :: dbegin(); it != end; ++it, ++git )
212 template<
class Impl >
213 template<
class StreamTraits >
217 auto versionId =
in.readUnsignedInt();
218 if( versionId < DUNE_VERSION_ID(0,9,1) )
219 DUNE_THROW( IOError,
"Trying to read outdated file." );
220 else if( versionId > DUNE_MODULE_VERSION_ID(DUNE_FEM) )
221 std :: cerr <<
"Warning: Reading discrete function from newer version: "
222 << versionId << std :: endl;
225 if( versionId >= DUNE_VERSION_ID(1,5,0) )
229 const auto spaceId = space().type();
234 if( spaceId != mySpaceId )
235 DUNE_THROW( IOError,
"Trying to read discrete function from different space: DFSpace (" <<
spaceName( spaceId ) <<
") != DataSpace (" <<
spaceName( mySpaceId ) <<
")" );
246 if(
static_cast< int >( mysize ) != BaseType::size() )
247 DUNE_THROW( IOError,
"Trying to read discrete function of different size." );
248 if( BaseType::size() !=
static_cast< int >( this->space().size() ) )
249 DUNE_THROW( InvalidStateException,
"Trying to read discrete function in uncompressed state." );
252 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
253 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
254 typedef typename BlockMapperType::SizeType
SizeType;
256 const BlockMapperType &blockMapper = this->space().blockMapper();
257 const SizeType nBlocks = blockMapper.size();
258 for(
SizeType i = 0; i < nBlocks; ++i )
260 auto &&block = this->dofVector()[ i ];
266 asImp().enableDofCompression();
270 template<
class Impl >
271 template<
class StreamTraits >
275 unsigned int versionId = DUNE_MODULE_VERSION_ID(DUNE_FEM);
279 auto spaceId = space().type();
286 if( BaseType::size() !=
static_cast< int >( this->space().size() ) )
287 DUNE_THROW( InvalidStateException,
"Trying to write DiscreteFunction in uncompressed state." );
290 const int32_t mysize = BaseType::size();
294 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
295 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices LocalBlockIndices;
296 typedef typename BlockMapperType::SizeType
SizeType;
298 const BlockMapperType &blockMapper = this->space().blockMapper();
299 const SizeType nBlocks = blockMapper.size();
300 for(
SizeType i = 0; i < nBlocks; ++i )
302 const auto block = this->dofVector()[ i ];
308 template<
class Impl >
312 typedef typename DiscreteFunctionSpaceType::IndexSetType IndexSetType;
313 IndexSetType& indexSet = (IndexSetType&)space().indexSet();
319 if( persistentIndexSet )
320 persistentIndexSet->addBackupRestore();
324 template<
class Impl >
328 typedef typename DiscreteFunctionSpaceType::IndexSetType IndexSetType;
329 IndexSetType& indexSet = (IndexSetType&)space().indexSet();
335 if( persistentIndexSet )
336 persistentIndexSet->removeBackupRestore();
341 template<
class Impl >
342 template<
class DFType >
346 if( BaseType :: size() != g.
size() )
349 const auto end = BaseType :: dend();
351 auto fit = BaseType :: dbegin();
353 for( ; fit != end; ++fit, ++git )
355 if(
std::abs( *fit - *git ) > 1e-15 )
374 template<
class Impl >
375 inline std :: ostream &
394 template<
class StreamTraits,
class Impl >
414 template<
class StreamTraits,
class Impl >
415 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:396
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:416
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
Definition: common/discretefunction.hh:584
DiscreteFunctionDefault(const std::string &name, const DiscreteFunctionSpaceType &dfSpace)
Constructor storing discrete function space and local function factory.
Definition: discretefunction_inline.hh:26
BaseType::GridPartType GridPartType
type of the underlying grid part
Definition: common/discretefunction.hh:609
BaseType::DofType DofType
Definition: common/discretefunction.hh:649
DofVectorType::SizeType SizeType
size type of the block vector
Definition: common/discretefunction.hh:652
Traits::LocalDofVectorType LocalDofVectorType
type of LocalDofVector
Definition: common/discretefunction.hh:634
std::type_index assembleOperation_
Definition: common/discretefunction.hh:1048
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: common/discretefunction.hh:606
DiscreteFunctionSpaceType::DomainType DomainType
type of domain vector
Definition: common/discretefunction.hh:612
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
type of range field (usually a float type)
Definition: common/discretefunction.hh:623
std::size_t assembleCount_
Definition: common/discretefunction.hh:1049
Definition: common/discretefunction.hh:86
void write(OutStreamInterface< StreamTraits > &out) const
write the discrete function into a stream
Definition: common/discretefunction.hh:543
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:533
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