dune-fem  2.4.1-rc
local.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_PASS_LOCAL_HH
2 #define DUNE_FEM_PASS_LOCAL_HH
3 
4 #include <sstream>
5 #include <string>
6 
8 
9 namespace Dune
10 {
11 
12  namespace Fem
13  {
14 
15  // External forward declaration
16  // ----------------------------
17 
18  template <class DiscreteModelImp, class PreviousPassImp , int passIdImp >
19  class Pass;
20 
21  // LocalPass
22  // ---------
23 
31  template< class DiscreteModelImp, class PreviousPassImp , int passIdImp >
32  class LocalPass
33  : public Pass< DiscreteModelImp , PreviousPassImp , passIdImp>
34  {
35  public:
37  typedef PreviousPassImp PreviousPassType;
38 
41 
46 
48  typedef typename DiscreteModelImp::Traits::DestinationType DestinationType;
50  typedef typename DiscreteModelImp::Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
52  typedef typename DiscreteFunctionSpaceType::IteratorType IteratorType;
54  typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
55 
56  // deprecated type
57  typedef EntityType Entity;
58 
59  public:
65  LocalPass (PreviousPassImp &pass,
66  const DiscreteFunctionSpaceType &spc,
67  std::string passName = "LocalPass")
68  : BaseType(pass),
69  spc_(spc),
70  passName_(passName),
71  computeTime_(0.0),
72  numberOfElements_( 0 ),
73  passIsActive_( true )
74  {}
75 
77  virtual ~LocalPass () {}
78 
80  virtual void allocateLocalMemory ()
81  {
82  if (!this->destination_)
83  {
84  std::ostringstream funcName;
85  funcName << passName_ << "_" << this->passNumber();
86  this->destination_ = new DestinationType(funcName.str(), spc_);
87 
88  // set mem handle for deleting destination_
90  }
91  }
92 
94  const DiscreteFunctionSpaceType &space () const { return spc_; }
95 
99  virtual double computeTime () const
100  {
101  double ct = computeTime_;
102  computeTime_ = 0.0;
103  return ct;
104  }
105 
107  virtual size_t numberOfElements() const { return numberOfElements_; }
108 
110  bool active () const { return passIsActive_; }
111 
113  void enable () const { passIsActive_ = true ; }
114 
116  void disable() const { passIsActive_ = false ; }
117 
118  protected:
121  virtual void prepare (const ArgumentType &arg, DestinationType &dest) const = 0;
124  virtual void finalize (const ArgumentType &arg, DestinationType &dest) const = 0;
127  virtual void applyLocal (const EntityType &en ) const = 0;
128 
129  public:
133  void compute (const ArgumentType &arg, DestinationType &dest) const
134  {
135  // if pass was disable, don't do computation
136  if( ! active() ) return ;
137 
138  // get stopwatch
139  Dune::Timer timer;
140 
141  prepare(arg, dest);
142 
143  numberOfElements_ = 0 ;
144  const IteratorType endit = spc_.end();
145  for (IteratorType it = spc_.begin(); it != endit; ++it, ++ numberOfElements_ )
146  {
147  applyLocal(*it);
148  }
149 
150  finalize(arg, dest);
151 
152  // accumulate time
153  computeTime_ += timer.elapsed();
154  }
155 
156  protected:
157  const DiscreteFunctionSpaceType &spc_;
158  const std::string passName_;
159  mutable double computeTime_;
160  mutable size_t numberOfElements_;
161  mutable bool passIsActive_;
162  };
163 
164  } // namespace Fem
165 
166 } // namespace Dune
167 
168 #endif // #ifndef DUNE_FEM_PASS_LOCAL_HH
virtual void prepare(const ArgumentType &arg, DestinationType &dest) const =0
DeleteHandlerType * deleteHandler_
object to delete destination_
Definition: common/pass.hh:380
DiscreteFunctionSpaceType::IteratorType IteratorType
iterator over the space
Definition: local.hh:52
const DiscreteFunctionSpaceType & spc_
Definition: local.hh:157
size_t numberOfElements_
Definition: local.hh:160
virtual double computeTime() const
return accumulated time needed by pass&#39;s operator () this method also resets the compute time to zero...
Definition: local.hh:99
DiscreteModelImp::Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
the discrete function space belonging to destinationtype
Definition: local.hh:50
bool active() const
return true if pass is active
Definition: local.hh:110
void disable() const
set pass status to inactive
Definition: local.hh:116
DiscreteModelImp::Traits::DestinationType DestinationType
the discrete function representing the return value of this pass
Definition: local.hh:48
virtual void allocateLocalMemory()
build up local memory
Definition: local.hh:80
static DeleteHandler< ObjectToDelete > & instance()
return reference to default object deleter
Definition: common/pass.hh:142
virtual void applyLocal(const EntityType &en) const =0
const std::string passName_
Definition: local.hh:158
EntityType Entity
Definition: local.hh:57
virtual ~LocalPass()
destructor
Definition: local.hh:77
PreviousPassImp PreviousPassType
type of the preceding pass
Definition: local.hh:37
int passNumber() const
Definition: common/pass.hh:183
void pass(const GlobalArgumentType &arg) const
Definition: common/pass.hh:267
DiscreteFunctionSpaceType::EntityType EntityType
the codim 0 entity
Definition: local.hh:54
Definition: coordinate.hh:4
BaseType::TotalArgumentType ArgumentType
The type of the argument (and destination) type of the overall operator.
Definition: local.hh:45
virtual void finalize(const ArgumentType &arg, DestinationType &dest) const =0
const DiscreteFunctionSpaceType & space() const
return reference to space
Definition: local.hh:94
void compute(const ArgumentType &arg, DestinationType &dest) const
Definition: local.hh:133
LocalPass(PreviousPassImp &pass, const DiscreteFunctionSpaceType &spc, std::string passName="LocalPass")
constructor
Definition: local.hh:65
Base class for specific pass implementations.
Definition: local.hh:19
double computeTime_
Definition: local.hh:159
void enable() const
set pass status to active
Definition: local.hh:113
Pass< DiscreteModelImp, PreviousPassImp, passIdImp > BaseType
base class
Definition: local.hh:40
PushFrontTuple< LocalArgumentType, const GlobalArgumentType * >::type TotalArgumentType
Definition: common/pass.hh:177
virtual size_t numberOfElements() const
return number of elements visited during operator computation
Definition: local.hh:107
Specialisation of Pass which provides a grid walk-through, but leaves open what needs to be done on e...
Definition: local.hh:32
bool passIsActive_
Definition: local.hh:161
DestinationType * destination_
destination (might be set from outside)
Definition: common/pass.hh:377