dune-fem  2.4.1-rc
insertfunction.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_PASS_INSERTFUNCTION_HH
2 #define DUNE_FEM_PASS_INSERTFUNCTION_HH
3 
7 
8 namespace Dune
9 {
10 
11  namespace Fem
12  {
13 
14  // Internal Forward Declarations
15  // -----------------------------
16 
17  template< class DiscreteFunction >
19 
20  template< class DiscreteFunction, class PreviousPass, int passId = -1 >
22 
23 
24 
25  // InsertFunctionPassDiscreteModelTraits
26  // -------------------------------------
27 
29  template< class DiscreteFunction >
31  {
32  typedef DiscreteFunction DiscreteFunctionType;
33 
34  typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
35 
36  typedef DiscreteFunctionType DestinationType;
38  };
39 
40 
41 
42  // InsertFunctionPassDiscreteModel
43  // -------------------------------
44 
45  template< class DiscreteFunction >
47  {
49  };
50 
51 
52 
53  // InsertFunctionPass
54  // ------------------
55 
63  template< class DiscreteFunction, class PreviousPass, int passId >
64  class InsertFunctionPass
65  : public Pass< InsertFunctionPassDiscreteModel< DiscreteFunction >, PreviousPass, passId >
66  {
68  typedef Pass< InsertFunctionPassDiscreteModel< DiscreteFunction >, PreviousPass, passId > BaseType;
69 
70  static const bool hasLocalFunction = Conversion< DiscreteFunction, HasLocalFunction >::exists;
71  static_assert( hasLocalFunction, "InsertFunctionPass can only insert grid functions." );
72 
73  protected:
74  template <class DFType>
76  {
77  template <class ArgType>
78  static void init( const ArgType&, const double time, DiscreteFunction& ) {}
79  };
80 
81  template <class LFType>
83  {
84  template <class ArgType>
85  static void init( const ArgType& arg, const double time, DiscreteFunction& dest )
86  {
87  // call initialize on LocalFunctionAdapter
88  dest.initialize( arg, time );
89  }
90  };
91 
92  public:
95 
98 
100  typedef PreviousPass PreviousPassType;
101 
104 
109 
110  public:
116  InsertFunctionPass ( const DestinationType &destination, PreviousPassType &previousPass )
117  : BaseType( previousPass )
118  {
119  destination_ = const_cast< DestinationType * >( &destination );
120  }
121 
131  InsertFunctionPass ( const DestinationType &destination,
132  PreviousPassType &previousPass,
133  const DiscreteFunctionSpaceType &space )
134  : BaseType( previousPass )
135  {
136  destination_ = const_cast< DestinationType * >( &destination );
137  }
138 
143  explicit InsertFunctionPass ( PreviousPassType &previousPass )
144  : BaseType( previousPass )
145  {
146  assert( destination_ == 0 );
147  }
148 
152  InsertFunctionPass ( const DestinationType* destination, const std::shared_ptr< PreviousPassType >& previousPass )
153  : BaseType( *previousPass ),
154  prevPassPtr_( previousPass )
155  {
156  destination_ = const_cast< DestinationType * >( destination );
157  }
158 
161  {
162  destination_ = 0;
163  }
164 
165  // empty method here
167  {}
168 
170  const DiscreteFunctionSpaceType &space () const
171  {
172  assert( destination_ != 0 );
173  return destination_->space();
174  }
175 
177  void setDestination ( const DestinationType &destination )
178  {
179  destination_ = const_cast< DestinationType * >( &destination );
180  }
181 
182  using BaseType::time;
183 
184  protected:
185  // empty method here
186  void compute ( const ArgumentType &arg, DestinationType &dest ) const
187  {
188  // in case DestinationType is a LocalFunctionAdapter
189  // call initialize
191  }
192 
193  std::shared_ptr< PreviousPassType > prevPassPtr_;
194  using BaseType::destination_;
195  }; // end class InsertFunctionPass
196 
197  } // namespace Fem
198 
199 } // namespace Dune
200 
201 #endif // #ifndef DUNE_FEM_PASS_INSERTFUNCTION_HH
BaseType::GlobalArgumentType GlobalArgumentType
Definition: insertfunction.hh:103
InsertFunctionPass(const DestinationType &destination, PreviousPassType &previousPass, const DiscreteFunctionSpaceType &space)
Definition: insertfunction.hh:131
static void init(const ArgType &arg, const double time, DiscreteFunction &dest)
Definition: insertfunction.hh:85
std::shared_ptr< PreviousPassType > prevPassPtr_
Definition: insertfunction.hh:193
~InsertFunctionPass()
destructor
Definition: insertfunction.hh:160
PreviousPassType::GlobalArgumentType GlobalArgumentType
Definition: common/pass.hh:171
Traits::DestinationType DestinationType
discrete function representing the return value of this pass
Definition: insertfunction.hh:106
LocalFunctionAdapter wrapped a class with a local evaluate method into a grid function.
Definition: localfunctionadapter.hh:25
PreviousPass PreviousPassType
Repetition of template arguments.
Definition: insertfunction.hh:100
Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
discrete function space belonging to DestinationType
Definition: insertfunction.hh:108
void allocateLocalMemory()
Definition: insertfunction.hh:166
InsertFunctionPass(const DestinationType &destination, PreviousPassType &previousPass)
Definition: insertfunction.hh:116
InsertFunctionPassDiscreteModel< DiscreteFunction > DiscreteModelType
Definition: insertfunction.hh:37
Traits for InsertFunctionPass to create dummy discrete model.
Definition: insertfunction.hh:30
InsertFunctionPass(PreviousPassType &previousPass)
Definition: insertfunction.hh:143
Definition: coordinate.hh:4
DiscreteFunction DiscreteFunctionType
Definition: insertfunction.hh:32
InsertFunctionPassDiscreteModel< DiscreteFunction > DiscreteModelType
type of discrete model for this class
Definition: insertfunction.hh:94
BaseType::TotalArgumentType ArgumentType
Definition: insertfunction.hh:102
Definition: insertfunction.hh:18
InsertFunctionPass(const DestinationType *destination, const std::shared_ptr< PreviousPassType > &previousPass)
Definition: insertfunction.hh:152
void setDestination(const DestinationType &destination)
set internal destination pointer to dest
Definition: insertfunction.hh:177
InsertFunctionPassDiscreteModelTraits< DiscreteFunction > Traits
Definition: insertfunction.hh:48
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: insertfunction.hh:34
Base class for specific pass implementations.
Definition: local.hh:19
static void init(const ArgType &, const double time, DiscreteFunction &)
Definition: insertfunction.hh:78
const DiscreteFunctionSpaceType & space() const
return reference to space
Definition: insertfunction.hh:170
DiscreteModelType::Traits Traits
type of traits for this class
Definition: insertfunction.hh:97
PushFrontTuple< LocalArgumentType, const GlobalArgumentType * >::type TotalArgumentType
Definition: common/pass.hh:177
void compute(const ArgumentType &arg, DestinationType &dest) const
Definition: insertfunction.hh:186
DiscreteFunctionType DestinationType
Definition: insertfunction.hh:36
Base class for specific pass implementations. InsertFunctionPass simply inserts a discrete function f...
Definition: insertfunction.hh:21