DOpE
spacetimehandler_base.h
Go to the documentation of this file.
1 
24 #ifndef SPACE_TIME_HANDLER_BASE_H_
25 #define SPACE_TIME_HANDLER_BASE_H_
26 
27 #include <deal.II/lac/vector.h>
28 #include <deal.II/lac/block_vector_base.h>
29 #include <deal.II/lac/block_vector.h>
30 
31 #include <vector>
32 #include <iostream>
33 #include <sstream>
34 #include <limits>
35 
36 #include "timedofhandler.h"
37 #include "timeiterator.h"
38 #include "refinementcontainer.h"
39 #include "dopetypes.h"
40 
41 namespace DOpE
42 {
47 template<typename VECTOR>//has to be a class template because you can not have virtual member function templates.
49 {
50  public:
51 
52  SpaceTimeHandlerBase(DOpEtypes::ControlType control_type = DOpEtypes::stationary) : control_type_(control_type)
53  {
54  time_triangulation_ = NULL;
55  state_ticket_ = 1;
56  control_ticket_ = 1;
57  }
58 
59  SpaceTimeHandlerBase(dealii::Triangulation<1> & times, DOpEtypes::ControlType type = DOpEtypes::stationary) :
60  tdfh_(times), interval_(tdfh_.first_interval()), control_type_(type)
61  {
62  time_triangulation_ = &times;
63  state_ticket_ = 1;
64  control_ticket_ = 1;
65  }
66 
67  SpaceTimeHandlerBase(dealii::Triangulation<1> & times,
68  const dealii::FiniteElement<1>& fe,
70  tdfh_(times, fe), interval_(tdfh_.first_interval()), control_type_(type)
71  {
72  time_triangulation_ = &times;
73  state_ticket_ = 1;
74  control_ticket_ = 1;
75  }
76 
77 
79  {
80  tdfh_.clear();
81  }
82 
86  void ReInitTime()
87  {
89  tdfh_.distribute_dofs();
90  //FIXME When we have temporal discretization also for control and constraint,
91  //one has to increment here the control_ticket_!
92  }
93 
101  unsigned int GetMaxTimePoint() const
102  {
103  return (tdfh_.GetNbrOfDoFs()-1);//because we start counting at 0.
104  }
105 
109  unsigned int GetNbrOfIntervals() const
110  {
111  return tdfh_.GetNbrOfIntervals();
112  }
113 
114 
120  void SetInterval(const TimeIterator& it)
121  {
122  interval_ = it;
123  }
124 
125 
131  const TimeIterator& GetInterval() const
132  {
133  return interval_;
134  }
135 
136 
143  double GetTime(unsigned int time_point) const
144  {
145 
146  return tdfh_.GetTime(time_point);
147  }
148 
149 
154  {
155  return tdfh_;
156  }
157 
158 
162  const std::vector<double>& GetTimes() const
163  {
164  return tdfh_.GetTimes();
165  }
166 
178  void
179  GetTimes(const TimeIterator& interval, std::vector<double>& local_times) const
180  {
181  return tdfh_.GetTimes(interval, local_times);
182  }
183 
184 
195  bool IsValidStateTicket(unsigned int& ticket) const
196  {
197  bool ret = (ticket == state_ticket_);
198  ticket = state_ticket_;
199  return ret;
200  }
201 
212  bool IsValidControlTicket(unsigned int& ticket) const
213  {
214  bool ret = (ticket == control_ticket_);
215  ticket = control_ticket_;
216  return ret;
217  }
218 
219 
225  {
226  return control_type_;
227  }
228 
229 
241  virtual void
242  InterpolateControl(VECTOR& /*result*/, const std::vector<VECTOR*> &/*local_vectors*/,
243  double /*t*/, const TimeIterator&/*interval*/) const { abort(); }
255  virtual void
256  InterpolateState(VECTOR& /*result*/, const std::vector<VECTOR*> &/*local_vectors*/,
257  double /*t*/, const TimeIterator&/*interval*/) const = 0;
269  virtual void InterpolateConstraint(VECTOR& /*result*/, const std::vector<VECTOR*> &/*local_vectors*/,
270  double /*t*/, const TimeIterator&/*interval*/) const { abort(); }
271 
279  virtual unsigned int GetControlNDoFs(int /*time_point*/ = -1) const { abort(); }
287  virtual unsigned int GetStateNDoFs(int time_point = -1) const = 0;
292  virtual unsigned int GetConstraintNDoFs(std::string /*name*/) const { abort(); return 0; }
300  virtual const std::vector<unsigned int>& GetControlDoFsPerBlock(int /*time_point*/ = -1) const { abort(); }
308  virtual const std::vector<unsigned int>& GetStateDoFsPerBlock(int time_point = -1) const = 0;
313  virtual const std::vector<unsigned int>& GetConstraintDoFsPerBlock(std::string /*name*/) const { abort(); }
317  virtual unsigned int GetNGlobalConstraints() const { abort(); }
321  virtual unsigned int GetNLocalConstraints() const { abort(); }
322 
326  double GetStepSize() const
327  {
328  return interval_.get_k();
329  }
333  double GetNextStepSize() const
334  {
335  assert(interval_!= tdfh_.last_interval());
336  double k = (++interval_).get_k();
337  --interval_;
338  return k;
339  }
343  double GetPreviousStepSize() const
344  {
345  assert(interval_!= tdfh_.first_interval());
346  double k = (--interval_).get_k();
347  ++interval_;
348  return k;
349  }
350 
351 
364  virtual unsigned int NewTimePointToOldTimePoint(unsigned int t) const = 0;
365 
366 
376  virtual void SpatialMeshTransferControl(const VECTOR& /*old_values*/, VECTOR& /*new_values*/) const { abort(); }
377 
378  virtual void SpatialMeshTransferState(const VECTOR& /*old_values*/, VECTOR& /*new_values*/) const { abort(); }
379 
380  /******************************************************/
389  void
392  {
393  //assert(ref_type == DOpEtypes::RefinementType::global);
394  RefinementContainer ref_con_dummy;
395  RefineTime(ref_con_dummy);
396  }
397 
398  /******************************************************/
408  void
409  RefineTime(const RefinementContainer& ref_container)
410  {
411  DOpEtypes::RefinementType ref_type = ref_container.GetRefType();
412 
413  //make sure that we do not use any coarsening
414  assert(!ref_container.UsesCoarsening());
415  assert(time_triangulation_ != NULL);
416 
417  if (DOpEtypes::RefinementType::global == ref_type)
418  {
419  time_triangulation_->set_all_refine_flags();
420  }
421  else
422  {
423  throw DOpEException("Not implemented for name =" + DOpEtypesToString(ref_type),
424  "MethodOfLines_SpaceTimeHandler::RefineTime");
425  }
426  time_triangulation_->prepare_coarsening_and_refinement();
427 
428  time_triangulation_->execute_coarsening_and_refinement();
429  ReInitTime();
430  }
431  /******************************************************/
432 
433  protected:
438  {
439  assert( state_ticket_ < std::numeric_limits<unsigned int>::max());
440  state_ticket_++;
441  }
442 
447  {
448  assert( control_ticket_ < std::numeric_limits<unsigned int>::max());
449  control_ticket_++;
450  }
451 
452  private:
453  mutable TimeDoFHandler tdfh_;//FIXME Is it really necessary for tdfh_ and interval_ to be mutable? this is really ugly
454  mutable TimeIterator interval_;
455  dealii::Triangulation<1>* time_triangulation_;
456  unsigned int control_ticket_;
457  unsigned int state_ticket_;
458  mutable DOpEtypes::ControlType control_type_;
459 };
460 
461 }
462 
463 #endif
void ReInitTime()
Definition: spacetimehandler_base.h:86
virtual unsigned int NewTimePointToOldTimePoint(unsigned int t) const =0
double GetTime(unsigned int time_point) const
Definition: spacetimehandler_base.h:143
Definition: timedofhandler.h:64
void RefineTime(DOpEtypes::RefinementType=DOpEtypes::RefinementType::global)
Definition: spacetimehandler_base.h:390
bool IsValidControlTicket(unsigned int &ticket) const
Definition: spacetimehandler_base.h:212
virtual unsigned int GetNLocalConstraints() const
Definition: spacetimehandler_base.h:321
double GetStepSize() const
Definition: spacetimehandler_base.h:326
virtual const std::vector< unsigned int > & GetConstraintDoFsPerBlock(std::string) const
Definition: spacetimehandler_base.h:313
virtual void SpatialMeshTransferState(const VECTOR &, VECTOR &) const
Definition: spacetimehandler_base.h:378
virtual void InterpolateConstraint(VECTOR &, const std::vector< VECTOR * > &, double, const TimeIterator &) const
Definition: spacetimehandler_base.h:269
virtual const std::vector< unsigned int > & GetControlDoFsPerBlock(int=-1) const
Definition: spacetimehandler_base.h:300
ControlType
Definition: dopetypes.h:103
bool IsValidStateTicket(unsigned int &ticket) const
Definition: spacetimehandler_base.h:195
virtual unsigned int GetNGlobalConstraints() const
Definition: spacetimehandler_base.h:317
const std::vector< double > & GetTimes() const
Definition: timedofhandler.h:164
Definition: dopetypes.h:52
TimeIterator first_interval() const
Definition: timedofhandler.h:203
Definition: spacetimehandler_base.h:48
double GetNextStepSize() const
Definition: spacetimehandler_base.h:333
Definition: timeiterator.h:62
Definition: dopetypes.h:105
SpaceTimeHandlerBase(dealii::Triangulation< 1 > &times, const dealii::FiniteElement< 1 > &fe, DOpEtypes::ControlType type=DOpEtypes::stationary)
Definition: spacetimehandler_base.h:67
double get_k() const
Definition: timeiterator.h:194
unsigned int GetNbrOfDoFs() const
Definition: timedofhandler.h:152
DOpEtypes::RefinementType GetRefType() const
Definition: refinementcontainer.cc:86
RefinementType
Definition: dopetypes.h:50
Definition: refinementcontainer.h:42
SpaceTimeHandlerBase(DOpEtypes::ControlType control_type=DOpEtypes::stationary)
Definition: spacetimehandler_base.h:52
TimeIterator last_interval() const
Definition: timedofhandler.h:224
unsigned int GetNbrOfIntervals() const
Definition: timedofhandler.h:140
virtual void InterpolateControl(VECTOR &, const std::vector< VECTOR * > &, double, const TimeIterator &) const
Definition: spacetimehandler_base.h:242
virtual void SpatialMeshTransferControl(const VECTOR &, VECTOR &) const
Definition: spacetimehandler_base.h:376
DOpEtypes::ControlType GetControlType() const
Definition: spacetimehandler_base.h:224
const TimeDoFHandler & GetTimeDoFHandler() const
Definition: spacetimehandler_base.h:153
virtual unsigned int GetControlNDoFs(int=-1) const
Definition: spacetimehandler_base.h:279
virtual ~SpaceTimeHandlerBase()
Definition: spacetimehandler_base.h:78
const TimeIterator & GetInterval() const
Definition: spacetimehandler_base.h:131
void SetInterval(const TimeIterator &it)
Definition: spacetimehandler_base.h:120
void distribute_dofs()
Definition: timedofhandler.h:115
virtual const std::vector< unsigned int > & GetStateDoFsPerBlock(int time_point=-1) const =0
double GetTime(unsigned int timestep)
Definition: timedofhandler.h:193
void GetTimes(const TimeIterator &interval, std::vector< double > &local_times) const
Definition: spacetimehandler_base.h:179
bool UsesCoarsening() const
Definition: refinementcontainer.cc:94
unsigned int GetMaxTimePoint() const
Definition: spacetimehandler_base.h:101
const std::vector< double > & GetTimes() const
Definition: spacetimehandler_base.h:162
SpaceTimeHandlerBase(dealii::Triangulation< 1 > &times, DOpEtypes::ControlType type=DOpEtypes::stationary)
Definition: spacetimehandler_base.h:59
void IncrementControlTicket()
Definition: spacetimehandler_base.h:446
virtual unsigned int GetStateNDoFs(int time_point=-1) const =0
Definition: dopeexception.h:35
double GetPreviousStepSize() const
Definition: spacetimehandler_base.h:343
virtual void InterpolateState(VECTOR &, const std::vector< VECTOR * > &, double, const TimeIterator &) const =0
unsigned int GetNbrOfIntervals() const
Definition: spacetimehandler_base.h:109
virtual unsigned int GetConstraintNDoFs(std::string) const
Definition: spacetimehandler_base.h:292
std::string DOpEtypesToString(const C &)
Definition: dopetypes.h:134
void IncrementStateTicket()
Definition: spacetimehandler_base.h:437
void RefineTime(const RefinementContainer &ref_container)
Definition: spacetimehandler_base.h:409