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)
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:
255  void
256  find_ends()
257  {
258  DoFHandler<1>::active_cell_iterator element = this->begin_active();
259  while (element->face(0)->boundary_indicator() != 0)
260  {
261  element = element->neighbor(0);
262  }
263  _first_interval.Initialize(element, 0);
264  _before_first_interval.Initialize(element, -2);
265 
266  element = this->begin_active();
267  while (element->face(1)->boundary_indicator() != 1)
268  {
269  element = element->neighbor(1);
270  }
271  assert(static_cast<int>(this->get_tria().n_active_cells() - 1) >= 0);
272  _last_interval.Initialize(element,
273  static_cast<int>(this->get_tria().n_active_cells() - 1));_after_last_interval
274  .Initialize(element, -1);
275  }
276 
281  void
282  compute_times()
283  {
284  assert(this->get_fe().has_support_points());
285  //get the right length
286  _times.resize(this->n_dofs());
287 
288  //geht the support points and build a quadrature rule from it
289  dealii::Quadrature<1> quadrature_formula(
290  this->get_fe().get_unit_support_points());
291 
292  //after that, build a fevalues object. We need only the quadrature points!
293  //typename dealii::FEValues<1> fe_values(this->get_fe(),
294  dealii::FEValues<1> fe_values(this->get_fe(), quadrature_formula,
295  dealii::UpdateFlags(update_q_points));
296 
297  const unsigned int n_q_points = quadrature_formula.size();
298  std::vector<unsigned int> global_dof_indices(
299  this->get_fe().dofs_per_cell);
300 
301  //the usual loops. Go over all elements, in every element go through the quad
302  //points and store thei position in _times
303  //typename DoFHandler<1>::active_cell_iterator element =
304  DoFHandler<1>::active_cell_iterator element = this->begin_active(), endc =
305  this->end();
306  for (; element != endc; ++element)
307  {
308  fe_values.reinit(element);
309  element->get_dof_indices(global_dof_indices);
310  for (unsigned int i = 0; i < n_q_points; ++i)
311  {
312  _times[global_dof_indices[i]] =
313  fe_values.get_quadrature_points()[i](0);
314  }
315  }
316  }
317  //member variables
318 
319  TimeIterator _first_interval, _last_interval, _before_first_interval,
320  _after_last_interval;
321 
322  //FIXME
323  //Dummy FE which is used, if no fe is specified from the user.
324  //At the moment, this is necessary, because we use an DoFCellAccessor
325  //-iterator to go through our timegrid. Is this ok?
326  const dealii::FiniteElement<1>* _fe;
327 
331  std::vector<double> _times;
332  unsigned int _dofs_per_element;
333  bool _need_delete, _initialized;
334  };
335 
336 } //end of namespace
337 
338 #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:63
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:208
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