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. ) );
91 const MappingType &m =
dynamic_cast<const MappingType&
>( mapping );
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 );
112 void operator() (
const DomainType &arg, RangeType &dest )
const 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_) { }
161 term(
const MappingType &mapping, RangeFieldType scalar ) : v_(&mapping), scalar_(scalar), scaleIt_(
true ) {
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. )
198 const MappingType *v_;
199 RangeFieldType scalar_;
208 std::vector<term> lincomb_;
211 mutable bool loopDetected_ ;
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;
253 copyMapping(a, 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;
278 copyMapping(a, 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;
301 copyMapping(a, 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;
318 return multiplyMapping(a,factor);
330 template<
class DFieldType,
class RFieldType,
class DType,
class 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>
386 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
389 const RFieldType& factor)
400 template<
class DFieldType,
class RFieldType,
class DType,
class RType>
411 #endif // #ifndef DUNE_FEM_MAPPING_HH DType DomainType
domain vector space (for usage in derived classes) This can either be for example a discrete function...
Definition: mapping.hh:57
static Mapping< DFieldType, RFieldType, DType, RType > operator/(const Mapping< DFieldType, RFieldType, DType, RType > &mapping, const RFieldType &factor)
operator / for mappings
Definition: mapping.hh:388
Mapping< DFieldType, RFieldType, DType, RType > MappingType
type of mapping
Definition: mapping.hh:50
RType RangeType
range vector space (for usage in derived classes) This can either be for example a discrete function ...
Definition: mapping.hh:63
A mapping from one vector space into another This class describes a general mapping from the domain v...
Definition: mapping.hh:46
Mapping()
create Mappiung with empty linear combination
Definition: mapping.hh:72
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 > operator-(const Mapping< DFieldType, RFieldType, DType, RType > &a, const Mapping< DFieldType, RFieldType, DType, RType > &b)
substract two mappings
Definition: mapping.hh:346
Implementation of Mapping +, -, *, / operations.
Definition: mapping.hh:219
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
DFieldType DomainFieldType
type of field the domain vector space, i.e. double
Definition: mapping.hh:66
static Mapping< DFieldType, RFieldType, DType, RType > divideMapping(const Mapping< DFieldType, RFieldType, DType, RType > &a, const RFieldType &scalar)
divide mapping
Definition: mapping.hh:314
Definition: coordinate.hh:4
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
virtual ~Mapping()
delete linear combination if necessary
Definition: mapping.hh:81
RFieldType RangeFieldType
type of field the range vector space, i.e. double
Definition: mapping.hh:69
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 > operator+(const Mapping< DFieldType, RFieldType, DType, RType > &a, const Mapping< DFieldType, RFieldType, DType, RType > &b)
add two mappings
Definition: mapping.hh:332
void operator()(const DomainType &arg, RangeType &dest) const
Application operator that applies all operators in the linear combination stack.
Definition: mapping.hh:112
static Mapping< DFieldType, RFieldType, DType, RType > operator*(const Mapping< DFieldType, RFieldType, DType, RType > &mapping, const RFieldType &factor)
scale mapping with factor
Definition: mapping.hh:360
MappingType & operator=(const MappingType &mapping)
assignment of mapping mapping
Definition: mapping.hh:89