Flow123d  DF_patch_fe_values-dbc06cd
assembly_observe.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 assembly_observe.hh
15  * @brief
16  */
17 
18 #ifndef ASSEMBLY_OBSERVE_HH_
19 #define ASSEMBLY_OBSERVE_HH_
20 
21 #include <unordered_map>
22 
25 #include "fem/dofhandler.hh"
26 #include "fem/element_cache_map.hh"
27 #include "io/observe.hh"
28 
29 
30 /**
31  * Helper structure holds patch data of observe output
32  *
33  * Data is specified by cell and subset index in EvalPoint object
34  */
36  /// Default constructor
38 
39  /// Constructor with data mebers initialization
40  ObserveIntegralData(DHCellAccessor dhcell, unsigned int subset_idx)
41  : cell(dhcell), subset_index(subset_idx) {}
42 
43  /// Copy constructor
45  : cell(other.cell), subset_index(other.subset_index) {}
46 
47  DHCellAccessor cell; ///< Specified cell (element)
48  unsigned int subset_index; ///< Index (order) of subset in EvalPoints object
49 };
50 
51 
52 /**
53  * @brief Generic class of observe output assemblation.
54  *
55  * Class
56  * - holds assemblation structures (EvalPoints, Integral objects, Integral data table).
57  * - associates assemblation objects specified by dimension
58  * - provides general assemble method
59  * - provides methods that allow construction of element patches
60  */
61 template < template<IntDim...> class DimAssembly>
63 {
64 public:
65  /// Constructor
66  GenericAssemblyObserve( typename DimAssembly<1>::EqFields *eq_fields, const std::unordered_set<string> &observe_fields_list,
67  std::shared_ptr<Observe> observe)
69  multidim_assembly_(eq_fields, observe_fields_list, observe.get(), &this->asm_internals_), observe_(observe), patch_data_(20, 10)
70  {
71  multidim_assembly_[1_d]->create_observe_integrals(bulk_integrals_);
72  multidim_assembly_[2_d]->create_observe_integrals(bulk_integrals_);
73  multidim_assembly_[3_d]->create_observe_integrals(bulk_integrals_);
75  multidim_assembly_[1_d]->initialize();
76  multidim_assembly_[2_d]->initialize();
77  multidim_assembly_[3_d]->initialize();
78  }
79 
80  /// Getter to set of assembly objects
82  return multidim_assembly_;
83  }
84 
85  /**
86  * @brief General assemble methods.
87  *
88  * Loops through local cells and calls assemble methods of assembly
89  * object of each cells over space dimension.
90  */
91  void assemble(std::shared_ptr<DOFHandlerMultiDim> dh) override {
92  START_TIMER( DimAssembly<1>::name() );
93 
94  unsigned int i_ep, subset_begin, subset_idx;
95  auto &patch_point_data = observe_->patch_point_data();
96  for(auto & p_data : patch_point_data) {
97  subset_idx = bulk_integrals_[p_data.i_quad]->get_subset_idx();
98  subset_begin = this->asm_internals_.eval_points_->subset_begin(p_data.i_quad+1, subset_idx);
99  i_ep = subset_begin + p_data.i_quad_point;
100  DHCellAccessor dh_cell = dh->cell_accessor_from_element(p_data.elem_idx);
101  patch_data_.emplace_back(dh_cell, p_data.i_quad_point);
102  this->asm_internals_.element_cache_map_.eval_point_data_.emplace_back(p_data.i_reg, p_data.elem_idx, i_ep, 0);
103  }
106 
107  this->reallocate_cache();
109  multidim_assembly_[1_d]->eq_fields_->cache_update(this->asm_internals_.element_cache_map_);
110 
111  multidim_assembly_[1_d]->assemble_cell_integrals(patch_data_);
112  multidim_assembly_[2_d]->assemble_cell_integrals(patch_data_);
113  multidim_assembly_[3_d]->assemble_cell_integrals(patch_data_);
114  patch_data_.reset();
116  END_TIMER( DimAssembly<1>::name() );
117  }
118 
119 
120 private:
121  /// Calls cache_reallocate method on set of used fields
122  inline void reallocate_cache() {
123  multidim_assembly_[1_d]->eq_fields_->cache_reallocate(this->asm_internals_.element_cache_map_, multidim_assembly_[1_d]->used_fields_);
124  // DebugOut() << "Order of evaluated fields (" << DimAssembly<1>::name() << "):" << multidim_assembly_[1_d]->eq_fields_->print_dependency();
125  }
126 
127  std::array<std::shared_ptr<BulkIntegral>, 3> bulk_integrals_; ///< Bulk integrals of elements of dimensions 1, 2, 3
129  std::shared_ptr<Observe> observe_; ///< Shared Observe object.
130  RevertableList<ObserveIntegralData> patch_data_; ///< Holds data for computing bulk integrals.
131 };
132 
133 
134 template <unsigned int dim>
136 {
137 public:
139 
140  static constexpr const char * name() { return "Output_Observe_Assembly"; }
141 
142  /// Constructor.
143  AssemblyObserveOutput(EqFields *eq_fields, const std::unordered_set<string> &observe_fields_list, Observe *observe, AssemblyInternals *asm_internals)
144  : AssemblyBasePatch<dim>(), eq_fields_(eq_fields), observe_(observe) {
145  this->asm_internals_ = asm_internals;
146  offsets_.resize(1.1 * CacheMapElementNumber::get());
147 
148  for (auto observe_field : observe_fields_list) {
149  auto found_field = eq_fields_->field(observe_field);
150  used_fields_ += *found_field;
151  }
152  }
153 
154  /// Destructor.
156 
157  /// Initialize auxiliary vectors and other data members
158  void initialize() {}
159 
160  /// Assembles the cell integrals for the given dimension.
162  unsigned int element_patch_idx, field_value_cache_position, val_idx;
163  this->reset_offsets();
164  for (unsigned int i=0; i<patch_data.permanent_size(); ++i) {
165  if (patch_data[i].cell.dim() != dim) continue;
166  element_patch_idx = this->asm_internals_->element_cache_map_.position_in_cache(patch_data[i].cell.elm_idx());
167  auto p = *( bulk_integral_->points(element_patch_idx).begin()); // evaluation point
168  field_value_cache_position = this->asm_internals_->element_cache_map_.element_eval_point(element_patch_idx, p.eval_point_idx() + patch_data[i].subset_index);
170  this->offsets_[field_value_cache_position] = val_idx;
171  }
172  for (FieldListAccessor f_acc : this->used_fields_.fields_range()) {
173  f_acc->fill_observe_value(observe_->get_output_cache(f_acc->name()), this->offsets_);
174  }
175  }
176 
177 
178  /// Create bulk integral according to dim
179  void create_observe_integrals(std::array<std::shared_ptr<BulkIntegral>, 3> &integrals) {
180  std::vector<arma::vec> reg_points;
181 
182  auto &patch_point_data = observe_->patch_point_data();
183  for(auto & p_data : patch_point_data) {
184  auto el_acc = eq_fields_->mesh()->element_accessor(p_data.elem_idx);
185  if (el_acc.dim()!=dim) continue;
186  p_data.i_reg = el_acc.region_idx().idx();
187  p_data.i_quad = el_acc.dim() - 1;
188  p_data.i_quad_point = reg_points.size();
189  reg_points.push_back(p_data.local_coords);
190  }
191 
192  if (reg_points.size() > 0) {
193  this->quad_ = new Quadrature(dim, reg_points.size());
194  for (uint j=0; j<reg_points.size(); j++) {
195  arma::vec::fixed<dim> fix_p = reg_points[j].subvec(0, dim-1);
196  this->quad_->weight(j) = 1.0;
197  this->quad_->set(j) = fix_p;
198  }
200  //this->integrals_.bulk_ = bulk_integral_;
201  integrals[dim-1] = bulk_integral_;
202  }
203  }
204 
205 private:
206  void reset_offsets() {
207  std::fill(offsets_.begin(), offsets_.end(), -1);
208  }
209 
210  /// Data objects shared with EquationOutput
213 
214  FieldSet used_fields_; ///< Sub field set contains fields performed to output
215  std::vector<int> offsets_; ///< Holds indices (offsets) of cached data to output data vector
216 
217  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_; ///< Accessor of integral
218 
219  template < template<IntDim...> class DimAssembly>
221 };
222 
223 
224 
225 
226 #endif /* ASSEMBLY_OBSERVE_HH_ */
std::shared_ptr< BulkIntegralAcc< dim > > create_bulk_integral(Quadrature *quad)
Quadrature * quad_
Quadrature used in assembling methods.
AssemblyInternals * asm_internals_
Holds shared internals data with GeneriAssembly.
const DimIntegrals< dim > & integrals() const
Getter of integrals_.
EqFields * eq_fields_
Data objects shared with EquationOutput.
FieldSet used_fields_
Sub field set contains fields performed to output.
AssemblyObserveOutput(EqFields *eq_fields, const std::unordered_set< string > &observe_fields_list, Observe *observe, AssemblyInternals *asm_internals)
Constructor.
void initialize()
Initialize auxiliary vectors and other data members.
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
Accessor of integral.
void create_observe_integrals(std::array< std::shared_ptr< BulkIntegral >, 3 > &integrals)
Create bulk integral according to dim.
void assemble_cell_integrals(RevertableList< ObserveIntegralData > &patch_data)
Assembles the cell integrals for the given dimension.
~AssemblyObserveOutput()
Destructor.
std::vector< int > offsets_
Holds indices (offsets) of cached data to output data vector.
static constexpr const char * name()
static unsigned int get()
Return number of stored elements.
Cell accessor allow iterate over DOF handler cells.
RegionIdx region_idx() const
Definition: accessors.hh:201
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.
int element_eval_point(unsigned int i_elem_in_cache, unsigned int i_eval_point) const
unsigned int position_in_cache(unsigned mesh_elm_idx, bool bdr=false) const
Return position of element stored in ElementCacheMap.
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:160
Range< FieldListAccessor > fields_range() const
Returns range of Fields held in field_list.
Definition: field_set.cc:282
const Mesh * mesh() const
Returns pointer to mesh.
Definition: field_set.hh:394
FieldCommon * field(const std::string &field_name) const
Definition: field_set.cc:173
AssemblyInternals asm_internals_
Holds shared internals data.
Generic class of observe output assemblation.
std::shared_ptr< Observe > observe_
Shared Observe object.
void reallocate_cache()
Calls cache_reallocate method on set of used fields.
RevertableList< ObserveIntegralData > patch_data_
Holds data for computing bulk integrals.
GenericAssemblyObserve(typename DimAssembly< 1 >::EqFields *eq_fields, const std::unordered_set< string > &observe_fields_list, std::shared_ptr< Observe > observe)
Constructor.
std::array< std::shared_ptr< BulkIntegral >, 3 > bulk_integrals_
Bulk integrals of elements of dimensions 1, 2, 3.
MixedPtr< DimAssembly, 1 > multidim_assembly_
Assembly object.
MixedPtr< DimAssembly, 1 > multidim_assembly() const
Getter to set of assembly objects.
void assemble(std::shared_ptr< DOFHandlerMultiDim > dh) override
General assemble methods.
ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:880
Point accessor allow iterate over local Observe points.
Definition: observe.hh:372
unsigned int loc_point_time_index() const
Return local index in data cache (combination of local point index and index of stored time)
Definition: observe.hh:402
OutputDataPtr get_output_cache(std::string field_name)
Definition: observe.hh:300
PatchPointVec & patch_point_data()
Getter of patch_point_data.
Definition: observe.hh:307
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
Armor::Array< double >::ArrayMatSet set(uint i)
Definition: quadrature.hh:93
double weight(unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:103
unsigned int idx() const
Returns a global index of the region.
Definition: region.hh:81
Declaration of class which handles the ordering of degrees of freedom (dof) and mappings between loca...
unsigned int uint
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19
Array< double > array
Definition: armor.hh:938
Holds common data shared between GenericAssemblz and Assembly<dim> classes.
ElementCacheMap element_cache_map_
ElementCacheMap according to EvalPoints.
std::shared_ptr< EvalPoints > eval_points_
EvalPoints object shared by all integrals.
ObserveIntegralData()
Default constructor.
ObserveIntegralData(const ObserveIntegralData &other)
Copy constructor.
unsigned int subset_index
Index (order) of subset in EvalPoints object.
ObserveIntegralData(DHCellAccessor dhcell, unsigned int subset_idx)
Constructor with data mebers initialization.
DHCellAccessor cell
Specified cell (element)
std::size_t make_permanent()
Finalize temporary part of data.
void reset()
Clear the list.
std::size_t emplace_back(Args &&... args)
std::size_t permanent_size() const
Return permanent size of list.
#define END_TIMER(tag)
Ends a timer with specified tag.
#define START_TIMER(tag)
Starts a timer with specified tag.