DOpE
spacetimehandler.h
Go to the documentation of this file.
1 
24 #ifndef SPACE_TIME_HANDLER_H_
25 #define SPACE_TIME_HANDLER_H_
26 
27 #include "spacetimehandler_base.h"
29 #include "mapping_wrapper.h"
30 #include "dataout_wrapper.h"
31 
32 #include <deal.II/lac/vector.h>
33 #include <deal.II/lac/block_vector_base.h>
34 #include <deal.II/lac/block_vector.h>
35 #include <deal.II/lac/constraint_matrix.h>
36 #include <deal.II/dofs/dof_handler.h>
37 
38 
39 // Multi-level routines
40 #include <deal.II/multigrid/mg_constrained_dofs.h>
41 #include <deal.II/multigrid/multigrid.h>
42 #include <deal.II/multigrid/mg_transfer.h>
43 #include <deal.II/multigrid/mg_tools.h>
44 #include <deal.II/multigrid/mg_coarse.h>
45 #include <deal.II/multigrid/mg_smoother.h>
46 #include <deal.II/multigrid/mg_matrix.h>
47 
48 
49 
50 #include <vector>
51 #include <iostream>
52 #include <sstream>
53 
54 namespace DOpE
55 {
69  template<template<int, int> class FE, template<int, int> class DH, typename SPARSITYPATTERN,
70  typename VECTOR, int dopedim, int dealdim>
71  class SpaceTimeHandler : public SpaceTimeHandlerBase<VECTOR>
72  {
73  public:
75  SpaceTimeHandlerBase<VECTOR>(type), control_index_(
76  dealii::numbers::invalid_unsigned_int), state_index_(
77  dealii::numbers::invalid_unsigned_int)
78  {
79  }
80  SpaceTimeHandler(dealii::Triangulation<1> & times,
82  SpaceTimeHandlerBase<VECTOR>(times, type), control_index_(
83  dealii::numbers::invalid_unsigned_int), state_index_(
84  dealii::numbers::invalid_unsigned_int)
85  {
86  }
89  SpaceTimeHandlerBase<VECTOR>(type), control_index_(
90  dealii::numbers::invalid_unsigned_int), state_index_(
91  dealii::numbers::invalid_unsigned_int), fe_index_setter_(
92  &index_setter)
93  {
94  }
95  SpaceTimeHandler(dealii::Triangulation<1> & times,
98  SpaceTimeHandlerBase<VECTOR>(times, type), control_index_(
99  dealii::numbers::invalid_unsigned_int), state_index_(
100  dealii::numbers::invalid_unsigned_int), fe_index_setter_(
101  &index_setter)
102  {
103  }
104  virtual
106  {
107 
108  }
109 
118  virtual void
119  ReInit(unsigned int control_n_blocks,
120  const std::vector<unsigned int>& control_block_component,
121  unsigned int state_n_blocks,
122  const std::vector<unsigned int>& state_block_component) =0;
123 
124  /******************************************************/
125 
130  GetControlDoFHandler() const =0;
131 
132  /******************************************************/
133 
138  GetStateDoFHandler() const = 0;
139 
140  /******************************************************/
141 
145  virtual const DOpEWrapper::Mapping<dealdim, DH>&
146  GetMapping() const = 0;
147 
148  /******************************************************/
149 
154  const std::vector<const DOpEWrapper::DoFHandler<dealdim, DH>*>&
156  {
157  assert(state_index_ != dealii::numbers::invalid_unsigned_int);
158 #if dope_dimension > 0
159  assert(control_index_ != dealii::numbers::invalid_unsigned_int);
162 #else
164 #endif
166  }
167 
168  /******************************************************/
169 
174  std::vector<
177  {
178  std::vector<
180  this->GetDoFHandler().size());
181  for (unsigned int dh = 0; dh < this->GetDoFHandler().size(); dh++)
182  {
183  ret[dh] = this->GetDoFHandler()[dh]->begin_active();
184  }
185  return ret;
186  }
187 
188  /******************************************************/
189 
195  std::vector<
198  {
199  std::vector<
201  this->GetDoFHandler().size());
202  for (unsigned int dh = 0; dh < this->GetDoFHandler().size(); dh++)
203  {
204  ret[dh] = this->GetDoFHandler()[dh]->end();
205  }
206  return ret;
207  }
208 
209 
210  /******************************************************/
211 
219  std::vector<
222  {
223  std::vector<
225  this->GetDoFHandler().size());
226  for (unsigned int dh = 0; dh < this->GetDoFHandler().size(); dh++)
227  {
228  ret[dh] = this->GetDoFHandler()[dh]->begin_active();
229  }
230  return ret;
231  }
232 
233  /******************************************************/
234 
243  std::vector<
246  {
247  std::vector<
249  this->GetDoFHandler().size());
250  for (unsigned int dh = 0; dh < this->GetDoFHandler().size(); dh++)
251  {
252  ret[dh] = this->GetDoFHandler()[dh]->end();
253  }
254  return ret;
255  }
256 
257 
258 
259  /******************************************************/
260 
269  void
270  SetDoFHandlerOrdering(unsigned int control_index,
271  unsigned int state_index)
272  {
273  control_index_ = control_index;
274  state_index_ = state_index;
275 #if dope_dimension > 0
276  {
277  assert(( control_index_ ==0 && state_index_ ==1 )||( control_index_ ==1 && state_index_ ==0 ));
279  if(domain_dofhandler_vector_.size() != 2)
280  {
281  domain_dofhandler_vector_.resize(2,NULL);
282  }
283  }
284 #else
285  {
286  assert(state_index_ == 0);
288  if (domain_dofhandler_vector_.size() != 1)
289  {
290  domain_dofhandler_vector_.resize(1, NULL);
291  }
292  }
293 #endif
294  }
295  /******************************************************/
296 
301  unsigned int
303  {
304  return state_index_;
305  }
306 
307  /******************************************************/
314  {
315  //makes only sense in the hp case.
316  return *fe_index_setter_;
317  }
318 
319  /******************************************************/
320  /*
321  * This function sets for every element the right fe index for the state variable.
322  * This is only useful in the hp case!
323  *
324  * @param dof_handler The dof_handler for which the fe indices have to be set.
325  */
326  void
329  {
330  if (dof_handler.NeedIndexSetter()) //with this we distinguish between hp and classic
331  {
332  for (typename DH<dealdim, dealdim>::active_cell_iterator element =
333  dof_handler.begin_active(); element != dof_handler.end(); ++element)
334  {
335  this->GetFEIndexSetter().SetActiveFEIndexState(element);
336  }
337  }
338  }
339 
340  /******************************************************/
341  /*
342  * This function sets for every element the right fe index for the state variable.
343  * This is only useful in the hp case!
344  *
345  * @param dof_handler The dof_handler for which the fe indices have to be set.
346  */
347  void
350  {
351  if (dof_handler.NeedIndexSetter())
352  {
353  for (typename DH<dopedim, dopedim>::active_cell_iterator element =
354  dof_handler.begin_active(); element != dof_handler.end(); ++element)
355  {
356  this->GetFEIndexSetter().SetActiveFEIndexState(element);
357  }
358  }
359  }
360 
361  /******************************************************/
362 
366  virtual unsigned int
367  GetControlDoFsPerBlock(unsigned int b, int time_point = -1) const=0;
368 
369  /******************************************************/
370 
374  virtual unsigned int
375  GetStateDoFsPerBlock(unsigned int b, int time_point = -1) const =0;
376 
377  /******************************************************/
378 
382  virtual unsigned int
383  GetConstraintDoFsPerBlock(std::string name, unsigned int b) const=0;
384 
385  /******************************************************/
386 
390  virtual const std::vector<unsigned int>&
391  GetControlDoFsPerBlock(int time_point = -1) const =0;
392 
393  /******************************************************/
394 
400  virtual const std::vector<unsigned int>&
401  GetStateDoFsPerBlock(int time_point = -1) const =0;
402 
403  /******************************************************/
408  virtual const std::vector<unsigned int>&
409  GetConstraintDoFsPerBlock(std::string name) const = 0;
410 
411  /******************************************************/
412 
416  virtual const dealii::ConstraintMatrix
417  &
418  GetControlDoFConstraints() const=0;
419 
420  /******************************************************/
421 
425  virtual const dealii::ConstraintMatrix
426  &
427  GetStateDoFConstraints() const=0;
428 
429  /*******************************************************/
430 
435  virtual const std::vector<dealii::Point<dealdim> >
436  &
438 
439  /******************************************************/
440 
444  virtual void
445  ComputeControlSparsityPattern(SPARSITYPATTERN & sparsity) const=0;
446 
447  /******************************************************/
448 
452  virtual void
453  ComputeStateSparsityPattern(SPARSITYPATTERN & sparsity) const=0;
454 
455  /******************************************************/
456 
461  virtual void
462  ComputeMGStateSparsityPattern(dealii::MGLevelObject<dealii::BlockSparsityPattern> & /*mg_sparsity_patterns*/,
463  unsigned int /*n_levels*/) const
464  {
465  throw DOpEException(
466  "Not used for normal DofHandler",
467  "StateSpaceTimeHandler.h");
468  }
469 
470  /******************************************************/
471 
476  virtual void
477  ComputeMGStateSparsityPattern(dealii::MGLevelObject<dealii::SparsityPattern> & /*mg_sparsity_patterns*/,
478  unsigned int /*n_levels*/) const
479  {
480  throw DOpEException(
481  "Not used for normal DofHandler",
482  "StateSpaceTimeHandler.h");
483  }
484 
485  /******************************************************/
490  virtual const FE<dealdim, dealdim>&
491  GetFESystem(std::string name) const=0;
492 
493  /******************************************************/
494 
497  {
498  data_out_.clear();
499  return data_out_;
500  }
501 
502  /******************************************************/
503 
504  protected:
505  //we need this here, because we know the type of the DoFHandler in use.
506  //This saves us a template argument for statpdeproblem etc.
510  mutable std::vector<const DOpEWrapper::DoFHandler<dealdim, DH>*> domain_dofhandler_vector_;
511  //TODO What if control and state have different dofhandlertypes??
512 
513  };
514 }
515 
516 #endif
void SetActiveFEIndicesState(DOpEWrapper::DoFHandler< dealdim, DH > &dof_handler)
Definition: spacetimehandler.h:327
static bool NeedIndexSetter()
virtual void ComputeStateSparsityPattern(SPARSITYPATTERN &sparsity) const =0
std::vector< typename DOpEWrapper::DoFHandler< dealdim, DH >::active_cell_iterator > GetDoFHandlerBeginActive() const
Definition: spacetimehandler.h:176
virtual const std::vector< dealii::Point< dealdim > > & GetMapDoFToSupportPoints()=0
void SetActiveFEIndicesControl(DOpEWrapper::DoFHandler< dopedim, DH > &dof_handler)
Definition: spacetimehandler.h:348
std::vector< typename DOpEWrapper::DoFHandler< dealdim, DH >::active_cell_iterator > GetDoFHandlerEnd() const
Definition: spacetimehandler.h:197
virtual unsigned int GetStateDoFsPerBlock(unsigned int b, int time_point=-1) const =0
SpaceTimeHandler(DOpEtypes::ControlType type)
Definition: spacetimehandler.h:74
DOpEWrapper::DataOut< dealdim, DH > data_out_
Definition: spacetimehandler.h:507
virtual const DOpEWrapper::DoFHandler< dopedim, DH > & GetControlDoFHandler() const =0
virtual void ReInit(unsigned int control_n_blocks, const std::vector< unsigned int > &control_block_component, unsigned int state_n_blocks, const std::vector< unsigned int > &state_block_component)=0
ControlType
Definition: dopetypes.h:103
std::vector< const DOpEWrapper::DoFHandler< dealdim, DH > * > domain_dofhandler_vector_
Definition: spacetimehandler.h:510
void SetDoFHandlerOrdering(unsigned int control_index, unsigned int state_index)
Definition: spacetimehandler.h:270
virtual ~SpaceTimeHandler()
Definition: spacetimehandler.h:105
virtual const DOpEWrapper::DoFHandler< dealdim, DH > & GetStateDoFHandler() const =0
Definition: spacetimehandler_base.h:48
virtual const dealii::ConstraintMatrix & GetStateDoFConstraints() const =0
virtual const DOpEWrapper::Mapping< dealdim, DH > & GetMapping() const =0
SpaceTimeHandler(DOpEtypes::ControlType type, const ActiveFEIndexSetterInterface< dopedim, dealdim > &index_setter)
Definition: spacetimehandler.h:87
DOpEWrapper::DataOut< dealdim, DH > & GetDataOut()
Definition: spacetimehandler.h:496
unsigned int GetStateIndex()
Definition: spacetimehandler.h:302
Definition: active_fe_index_setter_interface.h:39
std::vector< typename DOpEWrapper::DoFHandler< dealdim, DH >::cell_iterator > GetDoFHandlerBeginActiveAllLevels() const
Definition: spacetimehandler.h:221
virtual void ComputeMGStateSparsityPattern(dealii::MGLevelObject< dealii::BlockSparsityPattern > &, unsigned int) const
Definition: spacetimehandler.h:462
virtual const FE< dealdim, dealdim > & GetFESystem(std::string name) const =0
const ActiveFEIndexSetterInterface< dopedim, dealdim > & GetFEIndexSetter() const
Definition: spacetimehandler.h:313
std::vector< typename DOpEWrapper::DoFHandler< dealdim, DH >::cell_iterator > GetDoFHandlerEndAllLevels() const
Definition: spacetimehandler.h:245
virtual const dealii::ConstraintMatrix & GetControlDoFConstraints() const =0
const ActiveFEIndexSetterInterface< dopedim, dealdim > * fe_index_setter_
Definition: spacetimehandler.h:509
Definition: spacetimehandler.h:71
const std::vector< const DOpEWrapper::DoFHandler< dealdim, DH > * > & GetDoFHandler() const
Definition: spacetimehandler.h:155
unsigned int state_index_
Definition: spacetimehandler.h:508
SpaceTimeHandler(dealii::Triangulation< 1 > &times, DOpEtypes::ControlType type)
Definition: spacetimehandler.h:80
virtual void ComputeControlSparsityPattern(SPARSITYPATTERN &sparsity) const =0
SpaceTimeHandler(dealii::Triangulation< 1 > &times, DOpEtypes::ControlType type, const ActiveFEIndexSetterInterface< dopedim, dealdim > &index_setter)
Definition: spacetimehandler.h:95
Definition: dopeexception.h:35
virtual void ComputeMGStateSparsityPattern(dealii::MGLevelObject< dealii::SparsityPattern > &, unsigned int) const
Definition: spacetimehandler.h:477
virtual unsigned int GetConstraintDoFsPerBlock(std::string name, unsigned int b) const =0
virtual unsigned int GetControlDoFsPerBlock(unsigned int b, int time_point=-1) const =0
unsigned int control_index_
Definition: spacetimehandler.h:508