DOpE
timedofhandler.h
Go to the documentation of this file.
1 
24 #ifndef TIMEDOFHANDLER_H_
25 #define TIMEDOFHANDLER_H_
26 
27 //DOpE
28 #include <timeiterator.h>
29 #include <dopeexception.h>
30 #include <versionscheck.h>
31 
32 //deal.ii
33 #include <deal.II/fe/fe_q.h>
34 #include <deal.II/fe/fe_dgq.h>
35 #include <deal.II/fe/fe_nothing.h>
36 #include <deal.II/fe/fe_update_flags.h>
37 #include <deal.II/fe/fe_values.h>
38 #include <deal.II/dofs/dof_handler.h>
39 #include <deal.II/dofs/dof_renumbering.h>
40 #include <deal.II/base/point.h>
41 
42 //c++
43 #include <vector>
44 
45 
46 using namespace dealii;
47 
48 namespace DOpE
49 {
50 
64  class TimeDoFHandler : public dealii::DoFHandler<1>
65  {
66  public:
67  //Constructors
69  {
70  fe_ = NULL;
71  times_.resize(1, 0.);
72  dofs_per_element_ = 1;
73  need_delete_ = false;
74  initialized_ = false;
75  }
76 
81  TimeDoFHandler(const Triangulation<1> & tria,
82  const dealii::FiniteElement<1>& fe)
83  : dealii::DoFHandler<1>(tria)
84  {
85  fe_ = &fe;
86  this->distribute_dofs();
87  need_delete_ = false;
88  }
89 
90  TimeDoFHandler(const Triangulation<1>& tria)
91  : dealii::DoFHandler<1>(tria)
92  {
93  fe_ = new dealii::FE_Q<1>(1);
94  this->distribute_dofs();
95  need_delete_ = true;
96  }
97 
98  //Destructor
100  {
101  this->clear();
102 
103  if (need_delete_)
104  {
105  delete fe_;
106  }
107  fe_ = NULL;
108  }
109 
114  void
116  {
117  if (fe_ != NULL)
118  {
119  dealii::DoFHandler<1>::distribute_dofs(*fe_);
120  //make sure that the dofs are numbered 'downstream' (referring to the time variable!)
121 
122 #if DEAL_II_VERSION_GTE(7,3,0)
123  dealii::DoFRenumbering::downstream<dealii::DoFHandler<1> >(*this,
124  dealii::Point<1>(1.), true);
125  #else
126  dealii::DoFRenumbering::downstream<dealii::DoFHandler<1>, 1>(*this,
127  dealii::Point<1>(1.), true);
128  #endif
129  find_ends();
130  compute_times();
131  initialized_ = true;
132  dofs_per_element_ = this->get_fe().dofs_per_cell;
133  }
134  }
135 
139  unsigned int
141  {
142  if (initialized_)
143  return this->get_tria().n_active_cells();
144  else
145  return 0;
146  }
147 
151  unsigned int
152  GetNbrOfDoFs() const
153  {
154  if (initialized_)
155  return this->n_dofs();
156  else
157  return 1;
158  }
159 
163  const std::vector<double>&
164  GetTimes() const
165  {
166  return times_;
167  }
168 
175  void
176  GetTimes(const TimeIterator & interval,
177  std::vector<double>& local_times) const
178  {
179  assert(local_times.size() == GetLocalNbrOfDoFs());
180 
181  std::vector<unsigned int> global_dof_indices(GetLocalNbrOfDoFs());
182  interval.get_time_dof_indices(global_dof_indices);
183  for (unsigned int i = 0; i < GetLocalNbrOfDoFs(); ++i)
184  {
185  local_times[i] = times_[global_dof_indices[i]];
186  }
187  }
188 
192  double
193  GetTime(unsigned int timestep)
194  {
195  assert(timestep < times_.size());
196  return times_[timestep];
197  }
198 
204  {
205  assert(initialized_);
206  return first_interval_;
207  }
208 
215  {
216  assert(initialized_);
217  return before_first_interval_;
218  }
219 
225  {
226  assert(initialized_);
227  return last_interval_;
228  }
229 
236  {
237  assert(initialized_);
238  return after_last_interval_;
239  }
240 
244  unsigned int
246  {
247  return dofs_per_element_;
248  }
249 
250  private:
251  using dealii::DoFHandler<1>::distribute_dofs; //Remove the clang warning that the function below overloads the distribute_dofs
256  void
257  find_ends()
258  {
259  DoFHandler<1>::active_cell_iterator element = this->begin_active();
260 #if DEAL_II_VERSION_GTE(8,3,0)
261  while (element->face(0)->boundary_id() != 0)
262 #else
263  while (element->face(0)->boundary_indicator() != 0)
264 #endif
265  {
266  element = element->neighbor(0);
267  }
268  first_interval_.Initialize(element, 0);
269  before_first_interval_.Initialize(element, -2);
270 
271  element = this->begin_active();
272 #if DEAL_II_VERSION_GTE(8,3,0)
273  while (element->face(1)->boundary_id() != 1)
274 #else
275  while (element->face(1)->boundary_indicator() != 1)
276 #endif
277  {
278  element = element->neighbor(1);
279  }
280  assert(static_cast<int>(this->get_tria().n_active_cells() - 1) >= 0);
281  last_interval_.Initialize(element,
282  static_cast<int>(this->get_tria().n_active_cells() - 1));after_last_interval_
283  .Initialize(element, -1);
284  }
285 
290  void
291  compute_times()
292  {
293  assert(this->get_fe().has_support_points());
294  //get the right length
295  times_.resize(this->n_dofs());
296 
297  //geht the support points and build a quadrature rule from it
298  dealii::Quadrature<1> quadrature_formula(
299  this->get_fe().get_unit_support_points());
300 
301  //after that, build a fevalues object. We need only the quadrature points!
302  //typename dealii::FEValues<1> fe_values(this->get_fe(),
303  dealii::FEValues<1> fe_values(this->get_fe(), quadrature_formula,
304  dealii::UpdateFlags(update_q_points));
305 
306  const unsigned int n_q_points = quadrature_formula.size();
307  std::vector<unsigned int> global_dof_indices(
308  this->get_fe().dofs_per_cell);
309 
310  //the usual loops. Go over all elements, in every element go through the quad
311  //points and store thei position in times_
312  //typename DoFHandler<1>::active_cell_iterator element =
313  DoFHandler<1>::active_cell_iterator element = this->begin_active(), endc =
314  this->end();
315  for (; element != endc; ++element)
316  {
317  fe_values.reinit(element);
318  element->get_dof_indices(global_dof_indices);
319  for (unsigned int i = 0; i < n_q_points; ++i)
320  {
321  times_[global_dof_indices[i]] =
322  fe_values.get_quadrature_points()[i](0);
323  }
324  }
325  }
326  //member variables
327 
328  TimeIterator first_interval_, last_interval_, before_first_interval_,
329  after_last_interval_;
330 
331  //FIXME
332  //Dummy FE which is used, if no fe is specified from the user.
333  //At the moment, this is necessary, because we use an DoFCellAccessor
334  //-iterator to go through our timegrid. Is this ok?
335  const dealii::FiniteElement<1>* fe_;
336 
340  std::vector<double> times_;
341  unsigned int dofs_per_element_;
342  bool need_delete_, initialized_;
343  };
344 
345 } //end of namespace
346 
347 #endif /* TIMEDOFHANDLER_H_ */
Definition: timedofhandler.h:64
TimeDoFHandler()
Definition: timedofhandler.h:68
const std::vector< double > & GetTimes() const
Definition: timedofhandler.h:164
TimeIterator first_interval() const
Definition: timedofhandler.h:203
void GetTimes(const TimeIterator &interval, std::vector< double > &local_times) const
Definition: timedofhandler.h:176
TimeIterator before_first_interval() const
Definition: timedofhandler.h:214
TimeIterator after_last_interval() const
Definition: timedofhandler.h:235
Definition: timeiterator.h:62
unsigned int GetNbrOfDoFs() const
Definition: timedofhandler.h:152
TimeDoFHandler(const Triangulation< 1 > &tria, const dealii::FiniteElement< 1 > &fe)
Definition: timedofhandler.h:81
TimeIterator last_interval() const
Definition: timedofhandler.h:224
unsigned int GetNbrOfIntervals() const
Definition: timedofhandler.h:140
void get_time_dof_indices(std::vector< unsigned int > &local_dof_indices) const
Definition: timeiterator.h:207
unsigned int GetLocalNbrOfDoFs() const
Definition: timedofhandler.h:245
~TimeDoFHandler()
Definition: timedofhandler.h:99
void distribute_dofs()
Definition: timedofhandler.h:115
TimeDoFHandler(const Triangulation< 1 > &tria)
Definition: timedofhandler.h:90
double GetTime(unsigned int timestep)
Definition: timedofhandler.h:193