1#ifndef DUNE_FEM_MAPPING_HH
2#define DUNE_FEM_MAPPING_HH
45 template<
typename DFieldType,
typename RFieldType,
class DType,
class RType>
74 loopDetected_( false )
77 lincomb_.push_back( term( *
this, 1. ) );
93 lincomb_.erase( lincomb_.begin(), lincomb_.end() );
94 typedef typename std::vector<term>::const_iterator iterator;
97 lincomb_.reserve( m.lincomb_.size() );
99 iterator end = m.lincomb_.end();
100 for (iterator it = m.lincomb_.begin(); it != end; it++ )
102 lincomb_.push_back( *it );
115 typedef typename std::vector<term>::const_iterator const_iterator;
116 const_iterator end = lincomb_.end();
117 for ( const_iterator it = lincomb_.begin(); it != end; ++it )
119 const term& current = (*it);
123 current.apply( arg, dest );
128 current.applyAdd( arg, dest );
133 loopDetected_ = false ;
138 virtual void apply (
const DomainType &arg, RangeType &dest)
const
144 std::cerr <<
"WARNING: Mapping::apply: Loop detected! Check overloading of operator() and apply! " << std::endl;
150 loopDetected_ = true ;
157 term() : v_(NULL), scalar_(1.0), scaleIt_(false) { }
158 term(
const term& other)
159 : v_(other.v_), scalar_(other.scalar_), scaleIt_(other.scaleIt_) { }
162 if ( scalar_ == 1. ) {
167 void apply(
const DomainType &arg, RangeType &dest)
const
169 v_->apply( arg, dest );
176 void applyAdd(
const DomainType &arg, RangeType &dest)
const
179 RangeType tmp( dest );
181 v_->apply( arg, tmp );
186 else if ( scalar_ == -1. )
203 friend struct MappingOperators;
208 std::vector<term> lincomb_;
211 mutable bool loopDetected_ ;
214 friend struct MappingOperators;
222 template<
typename DFieldType,
typename RFieldType,
class DType,
class RType>
228 typedef typename std::vector< typename MappingType :: term > :: const_iterator iterator;
231 copy.lincomb_.clear();
234 iterator end = org.lincomb_.end();
235 for ( iterator it = org.lincomb_.begin(); it != end; ++it )
237 copy.lincomb_.push_back( *it );
243 template<
typename DFieldType,
typename RFieldType,
class DType,
class RType>
250 MappingType newMapping;
255 typedef typename std::vector< typename MappingType :: term > :: const_iterator iterator;
257 iterator end = b.lincomb_.end();
258 for ( iterator it = b.lincomb_.begin(); it != end; ++it )
260 newMapping.lincomb_.push_back( *it );
266 template<
typename DFieldType,
typename RFieldType,
class DType,
class RType>
272 typedef typename MappingType :: term term;
273 typedef typename std::vector< term > :: const_iterator iterator;
275 MappingType newMapping;
280 iterator end = b.lincomb_.end();
281 for ( iterator it = b.lincomb_.begin(); it != end; ++it )
283 newMapping.lincomb_.push_back( term( *it->v_, -it->scalar_ ) );
289 template<
typename DFieldType,
typename RFieldType,
class DType,
class RType>
292 const RFieldType& scalar)
295 typedef typename MappingType :: term term;
296 typedef typename std::vector< term > :: iterator iterator;
298 MappingType newMapping;
303 iterator end = newMapping.lincomb_.end();
304 for ( iterator it = newMapping.lincomb_.begin(); it != end; ++it )
306 it->scalar_ *= scalar;
312 template<
typename DFieldType,
typename RFieldType,
class DType,
class RType>
315 const RFieldType& scalar)
317 RFieldType factor = RFieldType(1)/scalar;
330 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
331 static inline Mapping<DFieldType,RFieldType,DType,RType>
344 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
358 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
361 const RFieldType& factor)
372 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
374 operator *(
const RFieldType& factor,
386 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
389 const RFieldType& factor)
400 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
402 operator /(
const RFieldType& factor,
A mapping from one vector space into another This class describes a general mapping from the domain v...
Definition: mapping.hh:47
DFieldType DomainFieldType
type of field the domain vector space, i.e. double
Definition: mapping.hh:66
RFieldType RangeFieldType
type of field the range vector space, i.e. double
Definition: mapping.hh:69
DType DomainType
domain vector space (for usage in derived classes) This can either be for example a discrete function...
Definition: mapping.hh:57
RType RangeType
range vector space (for usage in derived classes) This can either be for example a discrete function ...
Definition: mapping.hh:63
virtual ~Mapping()
delete linear combination if necessary
Definition: mapping.hh:81
Mapping< DFieldType, RFieldType, DType, RType > MappingType
type of mapping
Definition: mapping.hh:50
Mapping()
create Mappiung with empty linear combination
Definition: mapping.hh:72
void operator()(const DomainType &arg, RangeType &dest) const
Application operator that applies all operators in the linear combination stack.
Definition: mapping.hh:112
MappingType & operator=(const MappingType &mapping)
assignment of mapping mapping
Definition: mapping.hh:89
Dune namespace.
Definition: alignedallocator.hh:13
Implementation of Mapping +, -, *, / operations.
Definition: mapping.hh:220
static Mapping< DFieldType, RFieldType, DType, RType > multiplyMapping(const Mapping< DFieldType, RFieldType, DType, RType > &a, const RFieldType &scalar)
multiply mapping
Definition: mapping.hh:291
static Mapping< DFieldType, RFieldType, DType, RType > divideMapping(const Mapping< DFieldType, RFieldType, DType, RType > &a, const RFieldType &scalar)
divide mapping
Definition: mapping.hh:314
static Mapping< DFieldType, RFieldType, DType, RType > addMappings(const Mapping< DFieldType, RFieldType, DType, RType > &a, const Mapping< DFieldType, RFieldType, DType, RType > &b)
add mappings
Definition: mapping.hh:245
static void copyMapping(const Mapping< DFieldType, RFieldType, DType, RType > &org, Mapping< DFieldType, RFieldType, DType, RType > ©)
copy mapping
Definition: mapping.hh:224
static Mapping< DFieldType, RFieldType, DType, RType > substractMappings(const Mapping< DFieldType, RFieldType, DType, RType > &a, const Mapping< DFieldType, RFieldType, DType, RType > &b)
substract mappings
Definition: mapping.hh:268