ug4
grid_function.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION__
34 #define __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION__
35 
39 #include "approximation_space.h"
41 
42 #ifdef UG_PARALLEL
44 #endif
45 
46 namespace ug{
47 
49 
56 {
57  public:
58  virtual ~IGridFunction() {}
59 
61 
70  virtual void permute_values(const std::vector<size_t>& vIndNew) = 0;
71 
73 
90  virtual void copy_values(const std::vector<std::pair<size_t, size_t> >& vIndexMap,
91  bool bDisjunct = false) = 0;
92 
94 
100  virtual void resize_values(size_t s, number defaultValue = 0.0) = 0;
101 };
102 
103 template <typename TDomain> class AdaptionSurfaceGridFunction;
104 
106 
116 template <typename TDomain, typename TAlgebra>
118  : public TAlgebra::vector_type,
119  public IGridFunction,
121 {
122  public:
125 
128 
130  typedef TDomain domain_type;
131 
133  static const int dim = domain_type::dim;
134 
136  typedef TAlgebra algebra_type;
137 
139  typedef typename algebra_type::vector_type vector_type;
140 
141  public:
143  template <typename TElem>
144  struct traits
145  {
149  };
150 
151  template <int dim>
152  struct dim_traits
153  {
157  };
158 
162 
163  typedef typename dim_traits<dim-1>::grid_base_object side_type;
164  typedef typename dim_traits<dim-1>::iterator side_iterator;
165  typedef typename dim_traits<dim-1>::const_iterator const_side_iterator;
166 
167  protected:
169  virtual this_type* virtual_clone() const {return new this_type(*this);}
170 
172  virtual this_type* virtual_clone_without_values() const;
173 
174  public:
177  SmartPtr<DoFDistribution> spDoFDistr, bool bManage = true);
178 
180  GridFunction(SmartPtr<ApproximationSpace<TDomain> > spApproxSpace, bool bManage = true);
181 
183  GridFunction(SmartPtr<ApproximationSpace<TDomain> > spApproxSpace, int level, bool bManage = true);
184 
186  GridFunction(SmartPtr<ApproximationSpace<TDomain> > spApproxSpace, const GridLevel& gl, bool bManage = true);
187 
188  protected:
190  void check_algebra();
191 
193  void init(SmartPtr<ApproximationSpace<TDomain> > spApproxSpace,
194  SmartPtr<DoFDistribution> spDoFDistr, bool bManage);
195 
196  public:
199 
202  {
203  if (this!= &v) assign(v);
204  return *this;
205  }
206 
209  {
210  vector_type::operator=(d);
211  return *this;
212  }
213 
216 
217 
220 
222  virtual void clone_pattern(const this_type& v);
223 
225  void assign(const this_type& v);
226 
228  void assign(const vector_type& v);
229 
231  virtual ~GridFunction() {m_spDD->unmanage_grid_function(*this);}
232 
233  public:
239 
245 
247  const GridLevel& grid_level() const {return m_spDD->grid_level();}
248 
251  template <typename TElem>
253  {return m_spDD->template begin<TElem>();}
254 
255  template <typename TElem>
258  {return m_spDD->template begin<TElem>(validStates);}
259 
260  template <typename TElem>
262  {return m_spDD->template end<TElem>();}
263 
264  template <typename TElem>
267  {return m_spDD->template end<TElem>(validStates);}
268 
269  template <typename TElem>
270  typename traits<TElem>::const_iterator begin(int si) const
271  {return m_spDD->template begin<TElem>(si);}
272 
273  template <typename TElem>
275  begin(int si, SurfaceView::SurfaceConstants validStates) const
276  {return m_spDD->template begin<TElem>(si, validStates);}
277 
278  template <typename TElem>
279  typename traits<TElem>::const_iterator end(int si) const
280  {return m_spDD->template end<TElem>(si);}
281 
282  template <typename TElem>
284  end(int si, SurfaceView::SurfaceConstants validStates) const
285  {return m_spDD->template end<TElem>(si, validStates);}
287 
289  template <typename TElem, typename TBaseElem>
290  void collect_associated(std::vector<TBaseElem*>& vAssElem,
291  TElem* elem, bool clearContainer = true) const{
292  m_spDD->collect_associated(vAssElem, elem, clearContainer);
293  }
294 
296  template <class TGeomObj>
297  bool is_contained(TGeomObj* obj) const{
298  return m_spDD->is_contained(obj);
299  }
300 
301  public:
303  size_t num_indices() const {return m_spDD->num_indices();}
304 
306  size_t num_indices(int si) const {return m_spDD->num_indices(si);}
307 
310  size_t num_dofs() const {return num_dofs(DoFCount::ALL_FCT);}
311  size_t num_dofs(int fct) const {return num_dofs(fct, DoFCount::ALL_SUBSET);}
312  size_t num_dofs(int fct, int si) const;
314 
316  template <typename TElem>
317  void indices(TElem* elem, LocalIndices& ind, bool bHang = false) const
318  {m_spDD->indices(elem, ind, bHang);}
319 
321  template <typename TElem>
322  size_t dof_indices(TElem* elem, size_t fct, std::vector<DoFIndex>& ind, bool bHang = false, bool bClear = true) const
323  {return m_spDD->dof_indices(elem, fct, ind, bHang, bClear);}
324 
326  template <typename TElem>
327  size_t inner_dof_indices(TElem* elem, size_t fct, std::vector<DoFIndex>& ind, bool bClear = true) const
328  {return m_spDD->inner_dof_indices(elem, fct, ind, bClear);}
329 
331  template <typename TElem>
332  size_t algebra_indices(TElem* elem, std::vector<size_t>& ind, bool bClear = true) const
333  {return m_spDD->algebra_indices(elem, ind, bClear);}
334 
336  template <typename TElem>
337  size_t inner_algebra_indices(TElem* elem, std::vector<size_t>& ind, bool bClear = true) const
338  {return m_spDD->inner_algebra_indices(elem, ind, bClear);}
339 
340  public:
343 
345  ConstSmartPtr<TDomain> domain() const {return m_spApproxSpace->domain();}
346 
349 
352 
353  public:
355  bool managed() const {return m_bManaged;}
356 
358 
362 
364 
367  void enable_redistribution(bool enable) {m_bRedistribute = enable;}
368 
369  // for debugging purposes. To be removed.
371  {
372 #ifdef UG_PARALLEL
373  this->set_storage_type(PST_CONSISTENT);
374 #endif
375  }
376 
378  virtual void resize_values(size_t s, number defaultValue = 0.0);
379 
381  virtual void permute_values(const std::vector<size_t>& vIndNew);
382 
384  virtual void copy_values(const std::vector<std::pair<size_t, size_t> >& vIndexMap,
385  bool bDisjunct = false);
386 
387 
388  protected:
392 
395 
400 
403 
406 
407  protected:
410 
413 
416 
418 
420 
423 };
424 
425 template <typename TDomain, typename TAlgebra>
426 const typename TAlgebra::vector_type &getVector(const GridFunction<TDomain, TAlgebra> &t)
427 {
428  return *dynamic_cast<const GridFunction<TDomain, TAlgebra>*>(&t);
429 }
430 
431 
432 template <typename TDomain, typename TAlgebra>
433 inline std::ostream& operator<< (std::ostream& outStream, const GridFunction<TDomain, TAlgebra>& v)
434 {
435  outStream << *dynamic_cast<const GridFunction<TDomain, TAlgebra>*>(&v);
436  return outStream;
437 }
438 
439 } // end namespace ug
440 
441 // include implementation
442 #include "grid_function_impl.h"
443 
444 #endif /* __H__UG__LIB_DISC__FUNCTION_SPACE__GRID_FUNCTION__ */
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
Definition: adaption_surface_grid_function.h:43
base class for approximation spaces without type of algebra or dof distribution
Definition: approximation_space.h:279
static const int ALL_FCT
Definition: dof_count.h:48
static const int ALL_SUBSET
Definition: dof_count.h:49
Definition: dof_distribution_info.h:152
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
TDomain domain_type
Domain.
Definition: grid_function.h:130
size_t num_dofs() const
Definition: grid_function.h:310
traits< TElem >::const_iterator begin(SurfaceView::SurfaceConstants validStates) const
Definition: grid_function.h:257
ConstSmartPtr< ApproximationSpace< TDomain > > approx_space() const
returns const domain
Definition: grid_function.h:351
ConstSmartPtr< DoFDistribution > dof_distribution() const
Definition: grid_function.h:242
size_t num_indices() const
return the number of indices distributed (proc local)
Definition: grid_function.h:303
traits< TElem >::const_iterator begin(int si) const
Definition: grid_function.h:270
void check_algebra()
checks the algebra
Definition: grid_function_impl.h:127
size_t num_dofs(int fct) const
Definition: grid_function.h:311
bool m_bRedistribute
specifies whether the gridfunction should be redistributed together with the grid.
Definition: grid_function.h:419
GridFunction< TDomain, TAlgebra > this_type
This type.
Definition: grid_function.h:124
bool redistribution_enabled() const
retruns true if the grid-function is redistributed together with the grid in parallel applications
Definition: grid_function.h:361
algebra_type::vector_type vector_type
Vector type used to store dof values.
Definition: grid_function.h:139
traits< TElem >::const_iterator end(int si, SurfaceView::SurfaceConstants validStates) const
Definition: grid_function.h:284
this_type & operator=(const this_type &v)
assigns another grid function
Definition: grid_function.h:201
SmartPtr< TDomain > domain()
returns domain
Definition: grid_function.h:342
TAlgebra algebra_type
Algebra type.
Definition: grid_function.h:136
size_t inner_dof_indices(TElem *elem, size_t fct, std::vector< DoFIndex > &ind, bool bClear=true) const
get multi indices on an geometric object in canonical order
Definition: grid_function.h:327
void indices(TElem *elem, LocalIndices &ind, bool bHang=false) const
get all indices of the element
Definition: grid_function.h:317
SmartPtr< DoFDistribution > dof_distribution()
Definition: grid_function.h:236
uint m_preDistStorageType
stores the storage-type from before redistribution
Definition: grid_function.h:422
SmartPtr< ApproximationSpace< TDomain > > m_spApproxSpace
Approximation Space.
Definition: grid_function.h:412
traits< TElem >::const_iterator end(int si) const
Definition: grid_function.h:279
ApproximationSpace< TDomain > approximation_space_type
Type of Approximation space.
Definition: grid_function.h:127
virtual void copy_values(const std::vector< std::pair< size_t, size_t > > &vIndexMap, bool bDisjunct=false)
copy values
Definition: grid_function_impl.h:270
virtual void clone_pattern(const this_type &v)
copies the GridFunction v, except that the values are copied.
Definition: grid_function_impl.h:169
SmartPtr< ApproximationSpace< TDomain > > approx_space()
returns approx space
Definition: grid_function.h:348
bool managed() const
return m_bManaged
Definition: grid_function.h:355
traits< TElem >::const_iterator begin(int si, SurfaceView::SurfaceConstants validStates) const
Definition: grid_function.h:275
size_t dof_indices(TElem *elem, size_t fct, std::vector< DoFIndex > &ind, bool bHang=false, bool bClear=true) const
get multi indices on an finite element in canonical order
Definition: grid_function.h:322
dim_traits< dim-1 >::iterator side_iterator
Definition: grid_function.h:164
GridFunction(SmartPtr< ApproximationSpace< TDomain > > spApproxSpace, SmartPtr< DoFDistribution > spDoFDistr, bool bManage=true)
Initializing Constructor.
Definition: grid_function_impl.h:57
void grid_changed_callback(const GridMessage_Adaption &msg)
Definition: grid_function_impl.h:315
SmartPtr< this_type > clone_without_values() const
clone excluding values
Definition: grid_function.h:219
dim_traits< dim >::const_iterator const_element_iterator
Definition: grid_function.h:161
virtual void resize_values(size_t s, number defaultValue=0.0)
resize
Definition: grid_function_impl.h:227
size_t algebra_indices(TElem *elem, std::vector< size_t > &ind, bool bClear=true) const
get algebra indices on an geometric object in canonical order
Definition: grid_function.h:332
void grid_distribution_callback(const GridMessage_Distribution &msg)
called during parallel redistribution
Definition: grid_function_impl.h:390
virtual this_type * virtual_clone() const
virtual clone using covariant return type
Definition: grid_function.h:169
MessageHub::SPCallbackId m_spGridDistributionCallbackID
Definition: grid_function.h:391
virtual void permute_values(const std::vector< size_t > &vIndNew)
permutes all values
Definition: grid_function_impl.h:243
static const int dim
World Dimension.
Definition: grid_function.h:133
traits< TElem >::const_iterator begin() const
Definition: grid_function.h:252
void SetConsistentStorageType()
Definition: grid_function.h:370
void collect_associated(std::vector< TBaseElem * > &vAssElem, TElem *elem, bool clearContainer=true) const
returns the adjacend elements
Definition: grid_function.h:290
void register_at_adaption_msg_hub()
registers at message hub for grid adaption
Definition: grid_function_impl.h:299
SmartPtr< AdaptionSurfaceGridFunction< TDomain > > m_spAdaptGridFct
adaption grid function for temporary storage of values in grid
Definition: grid_function.h:405
SmartPtr< DoFDistribution > m_spDD
DoF Distribution this GridFunction relies on.
Definition: grid_function.h:409
const GridLevel & grid_level() const
returns the grid level
Definition: grid_function.h:247
size_t num_indices(int si) const
return the number of indices distributed on subset si (proc local)
Definition: grid_function.h:306
ConstSmartPtr< TDomain > domain() const
returns const domain
Definition: grid_function.h:345
void enable_redistribution(bool enable)
enables or disables redistribution for this grid function
Definition: grid_function.h:367
void assign(const this_type &v)
assigns another GridFunction
Definition: grid_function_impl.h:195
dim_traits< dim-1 >::const_iterator const_side_iterator
Definition: grid_function.h:165
ConstSmartPtr< DoFDistribution > dd() const
Definition: grid_function.h:243
GridFunction(const this_type &v)
Copy constructor.
Definition: grid_function.h:198
SmartPtr< this_type > clone() const
clone including values
Definition: grid_function.h:215
bool m_bManaged
boolean for DoF Distribution management of grid function
Definition: grid_function.h:415
MessageHub::SPCallbackId m_spGridAdaptionCallbackID
message hub id
Definition: grid_function.h:390
dim_traits< dim >::grid_base_object element_type
Definition: grid_function.h:159
virtual this_type * virtual_clone_without_values() const
virtual clone using covariant return type excluding values
Definition: grid_function_impl.h:206
traits< TElem >::const_iterator end() const
Definition: grid_function.h:261
SmartPtr< DoFDistribution > dd()
Definition: grid_function.h:237
virtual ~GridFunction()
Destructor.
Definition: grid_function.h:231
void init(SmartPtr< ApproximationSpace< TDomain > > spApproxSpace, SmartPtr< DoFDistribution > spDoFDistr, bool bManage)
inits the grid function
Definition: grid_function_impl.h:87
dim_traits< dim >::iterator element_iterator
Definition: grid_function.h:160
size_t inner_algebra_indices(TElem *elem, std::vector< size_t > &ind, bool bClear=true) const
get algebra indices on an geometric object in canonical order
Definition: grid_function.h:337
traits< TElem >::const_iterator end(SurfaceView::SurfaceConstants validStates) const
Definition: grid_function.h:266
bool is_contained(TGeomObj *obj) const
returns if the grid object is part of this grid function
Definition: grid_function.h:297
dim_traits< dim-1 >::grid_base_object side_type
Definition: grid_function.h:163
this_type & operator=(number d)
assigns constant value
Definition: grid_function.h:208
Definition: grid_level.h:42
A message sent along with "GridRefinement" messages.
Definition: lib_grid_messages.h:91
Definition: lib_grid_messages.h:166
Base class for all Grid Functions.
Definition: grid_function.h:56
virtual void resize_values(size_t s, number defaultValue=0.0)=0
resize
virtual void permute_values(const std::vector< size_t > &vIndNew)=0
permutes all values
virtual void copy_values(const std::vector< std::pair< size_t, size_t > > &vIndexMap, bool bDisjunct=false)=0
copy values
virtual ~IGridFunction()
Definition: grid_function.h:58
Definition: local_algebra.h:50
Const iterator to traverse the surface of a multi-grid hierarchy.
Definition: surface_view.h:237
Iterator to traverse the surface of a multi-grid hierarchy.
Definition: surface_view.h:178
SurfaceConstants
Definition: surface_view.h:72
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
static const int dim
PrandtlReuss< TDomain > this_type
unsigned int uint
Definition: types.h:114
double number
Definition: types.h:124
CPUAlgebra::vector_type vector_type
the ug namespace
const T & getVector(const T &t)
Definition: template_expressions.h:123
domain_traits< dim >::grid_base_object grid_base_object
Definition: dof_distribution.h:88
TElem grid_object
Definition: dof_distribution.h:80
Definition: grid_function.h:153
DoFDistribution::dim_traits< dim >::const_iterator const_iterator
Definition: grid_function.h:156
DoFDistribution::dim_traits< dim >::grid_base_object grid_base_object
Definition: grid_function.h:154
DoFDistribution::dim_traits< dim >::iterator iterator
Definition: grid_function.h:155
iterator traits
Definition: grid_function.h:145
DoFDistribution::traits< TElem >::iterator iterator
Definition: grid_function.h:147
DoFDistribution::traits< TElem >::const_iterator const_iterator
Definition: grid_function.h:148
DoFDistribution::traits< TElem >::grid_object grid_object
Definition: grid_function.h:146