Flow123d  DF_patch_fe_darcy_complete-579fe1e
generic_assembly.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file generic_assembly.hh
15  * @brief
16  */
17 
18 #ifndef GENERIC_ASSEMBLY_HH_
19 #define GENERIC_ASSEMBLY_HH_
20 
22 #include "fem/integral_acc.hh"
23 #include "fem/eval_points.hh"
24 #include "fem/element_cache_map.hh"
25 #include "fem/fe_values.hh"
26 #include "fem/patch_fe_values.hh"
27 #include "tools/revertable_list.hh"
28 #include "system/sys_profiler.hh"
29 
30 
31 
32 /// Allow set mask of active integrals.
33 //enum ActiveIntegrals {
34 // no_intg = 0,
35 // bulk = 0x0001,
36 // edge = 0x0002,
37 // coupling = 0x0004,
38 // boundary = 0x0008
39 //};
40 
41 
42 /// Set of all used integral necessary in assemblation
44  std::array<std::shared_ptr<BulkIntegral>, 3> bulk_; ///< Bulk integrals of elements of dimensions 1, 2, 3
45  std::array<std::shared_ptr<EdgeIntegral>, 3> edge_; ///< Edge integrals between elements of dimensions 1, 2, 3
46  std::array<std::shared_ptr<CouplingIntegral>, 3> coupling_; ///< Coupling integrals between elements of dimensions 1-2, 2-3
47  std::array<std::shared_ptr<BoundaryIntegral>, 3> boundary_; ///< Boundary integrals betwwen elements of dimensions 1, 2, 3 and boundaries
48 };
49 
50 
51 /// Holds common data shared between GenericAssemblz and Assembly<dim> classes.
53 public:
55  : eval_points_(std::make_shared<EvalPoints>()) {}
56 
58  : eval_points_(std::make_shared<EvalPoints>()), fe_values_(fe) {}
59 
60  std::shared_ptr<EvalPoints> eval_points_; ///< EvalPoints object shared by all integrals
61  ElementCacheMap element_cache_map_; ///< ElementCacheMap according to EvalPoints
62  PatchFEValues<3> fe_values_; ///< Common FEValues object over all dimensions
63 };
64 
65 
66 /**
67  * Common interface class for all Assembly classes.
68  */
70 {
71 public:
73  {}
74 
76  : asm_internals_(fe)
77  {}
78 
80 
81  virtual void assemble(std::shared_ptr<DOFHandlerMultiDim> dh) = 0;
82 
83  /// Getter to EvalPoints object
84  inline std::shared_ptr<EvalPoints> eval_points() const {
86  }
87 
88 protected:
89  AssemblyInternals asm_internals_; ///< Holds shared internals data
90 };
91 
92 
93 /**
94  * @brief Generic class of assemblation.
95  *
96  * Class
97  * - holds assemblation structures (EvalPoints, Integral objects, Integral data table).
98  * - associates assemblation objects specified by dimension
99  * - provides general assemble method
100  * - provides methods that allow construction of element patches
101  */
102 template < template<IntDim...> class DimAssembly>
104 {
105 public:
106  /**
107  * Constructor.
108  *
109  * Used in equations working with 'old' FeValues objects in evaluation.
110  * @param eq_fields Descendant of FieldSet declared in equation
111  * @param eq_data Object defined in equation containing shared data of eqation and assembly class.
112  */
113  GenericAssembly( typename DimAssembly<1>::EqData *eq_data)
115  use_patch_fe_values_(false),
116  multidim_assembly_(eq_data, &this->asm_internals_)
117  {
118  initialize();
119  }
120 
121  /**
122  * Constructor.
123  *
124  * Used in equations working with 'new' PatchFeValues objects in evaluation.
125  * @param eq_fields Descendant of FieldSet declared in equation
126  * @param eq_data Object defined in equation containing shared data of eqation and assembly class.
127  * @param dh DOF handler object
128  */
129  GenericAssembly( typename DimAssembly<1>::EqData *eq_data, DOFHandlerMultiDim* dh)
130  : GenericAssemblyBase(dh->ds()->fe()),
131  use_patch_fe_values_(true),
132  multidim_assembly_(eq_data, &this->asm_internals_)
133  {
134  initialize();
135  }
136 
137  /// Getter to set of assembly objects
139  return multidim_assembly_;
140  }
141 
142  /// Allows rewrite number of minimal edge sides.
143  void set_min_edge_sides(unsigned int val) {
144  multidim_assembly_[1_d]->set_min_edge_sides(val);
145  multidim_assembly_[2_d]->set_min_edge_sides(val);
146  multidim_assembly_[3_d]->set_min_edge_sides(val);
147  }
148 
149  /**
150  * @brief General assemble methods.
151  *
152  * Loops through local cells and calls assemble methods of assembly
153  * object of each cells over space dimension.
154  *
155  * TODO:
156  * - make estimate of the cache fill for combination of (integral_type x element dimension)
157  * - add next cell to patch if current_patch_size + next_element_size <= fixed_cache_size
158  * - avoid reverting the integral data lists.
159  */
160  void assemble(std::shared_ptr<DOFHandlerMultiDim> dh) override {
161  START_TIMER( DimAssembly<1>::name() );
162  this->reallocate_cache();
163  multidim_assembly_[1_d]->begin();
164 
165  bool add_into_patch = false; // control variable
166  for(auto cell_it = dh->local_range().begin(); cell_it != dh->local_range().end(); )
167  {
168  unsigned int cell_dim = cell_it->dim();
169  if (!add_into_patch) {
171  add_into_patch = true;
172  }
173 
174  START_TIMER("add_integrals_to_patch");
175  bool is_patch_full = false;
176  switch ( cell_dim ) {
177  case 1:
178  is_patch_full = multidim_assembly_[1_d]->add_integrals_of_computing_step(*cell_it);
179  break;
180  case 2:
181  is_patch_full = multidim_assembly_[2_d]->add_integrals_of_computing_step(*cell_it);
182  break;
183  case 3:
184  is_patch_full = multidim_assembly_[3_d]->add_integrals_of_computing_step(*cell_it);
185  break;
186  default:
187  ASSERT(false).error("Should not happen!");
188  }
189  END_TIMER("add_integrals_to_patch");
190 
191  if (is_patch_full) {
193  this->assemble_integrals();
194  add_into_patch = false;
195  } else {
197  if (use_patch_fe_values_) {
199  }
201  this->assemble_integrals();
202  add_into_patch = false;
203  }
204  ++cell_it;
205  }
206  }
207  if (add_into_patch) {
208  this->assemble_integrals();
209  }
210 
211  multidim_assembly_[1_d]->end();
212  END_TIMER( DimAssembly<1>::name() );
213  }
214 
215  /// Return ElementCacheMap
216  inline const ElementCacheMap &cache_map() const {
218  }
219 
220 private:
221  /// Common part of GenericAssemblz constructors.
222  void initialize() {
224  multidim_assembly_[1_d]->initialize();
225  multidim_assembly_[2_d]->initialize();
226  multidim_assembly_[3_d]->initialize();
227  if (use_patch_fe_values_) {
229  }
230  }
231 
232  /// Call assemblations when patch is filled
234  START_TIMER("create_patch");
236  END_TIMER("create_patch");
237  if (use_patch_fe_values_) {
238  START_TIMER("patch_reinit");
239  patch_reinit();
240  END_TIMER("patch_reinit");
241  }
242  START_TIMER("cache_update");
243  multidim_assembly_[1_d]->eq_fields_->cache_update(asm_internals_.element_cache_map_); // TODO replace with sub FieldSet
244  END_TIMER("cache_update");
246 
247  {
248  START_TIMER("assemble_volume_integrals");
249  multidim_assembly_[1_d]->assemble_cell_integrals();
250  multidim_assembly_[2_d]->assemble_cell_integrals();
251  multidim_assembly_[3_d]->assemble_cell_integrals();
252  END_TIMER("assemble_volume_integrals");
253  }
254 
255  {
256  START_TIMER("assemble_fluxes_boundary");
257  multidim_assembly_[1_d]->assemble_boundary_side_integrals();
258  multidim_assembly_[2_d]->assemble_boundary_side_integrals();
259  multidim_assembly_[3_d]->assemble_boundary_side_integrals();
260  END_TIMER("assemble_fluxes_boundary");
261  }
262 
263  {
264  START_TIMER("assemble_fluxes_elem_elem");
265  multidim_assembly_[1_d]->assemble_edge_integrals();
266  multidim_assembly_[2_d]->assemble_edge_integrals();
267  multidim_assembly_[3_d]->assemble_edge_integrals();
268  END_TIMER("assemble_fluxes_elem_elem");
269  }
270 
271  {
272  START_TIMER("assemble_fluxes_elem_side");
273  multidim_assembly_[1_d]->assemble_neighbour_integrals();
274  multidim_assembly_[2_d]->assemble_neighbour_integrals();
275  END_TIMER("assemble_fluxes_elem_side");
276  }
277  // clean integral data
278  multidim_assembly_[1_d]->clean_integral_data();
279  multidim_assembly_[2_d]->clean_integral_data();
280  multidim_assembly_[3_d]->clean_integral_data();
282  if (use_patch_fe_values_) {
284  }
285  }
286 
287  /// Reinit PatchFeValues object during construction of patch
288  void patch_reinit() {
293 
295  }
296 
297  /// Calls cache_reallocate method on
298  inline void reallocate_cache() {
299  multidim_assembly_[1_d]->eq_fields_->cache_reallocate(asm_internals_.element_cache_map_, multidim_assembly_[1_d]->used_fields_);
300  // DebugOut() << "Order of evaluated fields (" << DimAssembly<1>::name() << "):" << multidim_assembly_[1_d]->eq_fields_->print_dependency();
301  }
302 
303 
304  bool use_patch_fe_values_; ///< Flag holds if common @p fe_values_ object is used in @p multidim_assembly_
306 };
307 
308 
309 #endif /* GENERIC_ASSEMBLY_HH_ */
#define ASSERT(expr)
Definition: asserts.hh:351
static unsigned int get()
Return number of stored elements.
Provides the numbering of the finite element degrees of freedom on the computational mesh.
Definition: dofhandler.hh:151
Directing class of FieldValueCache.
unsigned int get_simd_rounded_size()
Returns number of eval. points with addition of max simd duplicates due to regions.
void start_elements_update()
Start update of cache.
void finish_elements_update()
Finish update after reading data to cache.
void clear_element_eval_points_map()
Reset all items of elements_eval_points_map.
void create_patch()
Create patch of cached elements before reading data to cache.
RevertableList< EvalPointData > eval_point_data_
void init(std::shared_ptr< EvalPoints > eval_points)
Init cache.
void make_paermanent_eval_points()
Mark eval_point_data_ as permanent.
Class holds local coordinations of evaluating points (bulk and sides) specified by element dimension.
Definition: eval_points.hh:54
AssemblyInternals asm_internals_
Holds shared internals data.
virtual ~GenericAssemblyBase()
GenericAssemblyBase(MixedPtr< FiniteElement > fe)
std::shared_ptr< EvalPoints > eval_points() const
Getter to EvalPoints object.
virtual void assemble(std::shared_ptr< DOFHandlerMultiDim > dh)=0
Generic class of assemblation.
GenericAssembly(typename DimAssembly< 1 >::EqData *eq_data)
MixedPtr< DimAssembly, 1 > multidim_assembly_
Assembly object.
void assemble_integrals()
Call assemblations when patch is filled.
void assemble(std::shared_ptr< DOFHandlerMultiDim > dh) override
General assemble methods.
void patch_reinit()
Reinit PatchFeValues object during construction of patch.
const ElementCacheMap & cache_map() const
Return ElementCacheMap.
GenericAssembly(typename DimAssembly< 1 >::EqData *eq_data, DOFHandlerMultiDim *dh)
void initialize()
Common part of GenericAssemblz constructors.
void set_min_edge_sides(unsigned int val)
Allows rewrite number of minimal edge sides.
void reallocate_cache()
Calls cache_reallocate method on.
bool use_patch_fe_values_
Flag holds if common fe_values_ object is used in multidim_assembly_.
MixedPtr< DimAssembly, 1 > multidim_assembly() const
Getter to set of assembly objects.
void add_patch_points(const DimIntegrals< dim > &integrals, const IntegralData &integral_data, ElementCacheMap *element_cache_map, std::shared_ptr< EvalPoints > eval_points)
Add elements, sides and quadrature points registered on patch.
void init_finalize()
Finalize initialization, creates child (patch) arena and passes it to PatchPointValue objects.
void make_permanent_ppv_data()
Marks data of last successfully added element to patch as permanent.
void clean_elements_map()
Clear elements_map, set values to (-1)
void reinit_patch()
Reinit data.
void reset()
Reset PatchpointValues structures.
Class FEValues calculates finite element data on the actual cells such as shape function values,...
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19
Class FEValues calculates finite element data on the actual cells such as shape function values,...
Definitions of particular quadrature rules on simplices.
Allow set mask of active integrals.
std::array< std::shared_ptr< BulkIntegral >, 3 > bulk_
Bulk integrals of elements of dimensions 1, 2, 3.
std::array< std::shared_ptr< BoundaryIntegral >, 3 > boundary_
Boundary integrals betwwen elements of dimensions 1, 2, 3 and boundaries.
std::array< std::shared_ptr< EdgeIntegral >, 3 > edge_
Edge integrals between elements of dimensions 1, 2, 3.
std::array< std::shared_ptr< CouplingIntegral >, 3 > coupling_
Coupling integrals between elements of dimensions 1-2, 2-3.
Holds common data shared between GenericAssemblz and Assembly<dim> classes.
PatchFEValues< 3 > fe_values_
Common FEValues object over all dimensions.
ElementCacheMap element_cache_map_
ElementCacheMap according to EvalPoints.
AssemblyInternals(MixedPtr< FiniteElement > fe)
std::shared_ptr< EvalPoints > eval_points_
EvalPoints object shared by all integrals.
std::size_t revert_temporary()
Erase temporary part of data.
#define END_TIMER(tag)
Ends a timer with specified tag.
#define START_TIMER(tag)
Starts a timer with specified tag.