Flow123d  3.9.0-97067769b
assembly_output.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_dg.hh
15  * @brief
16  */
17 
18 #ifndef ASSEMBLY_OUTPUT_HH_
19 #define ASSEMBLY_OUTPUT_HH_
20 
21 #include <unordered_map>
22 
25 #include "fem/fe_p.hh"
26 #include "fem/fe_values.hh"
28 #include "coupling/balance.hh"
30 #include "io/output_time.hh"
31 #include "io/element_data_cache.hh"
32 #include "mesh/ref_element.hh"
33 
34 
35 
36 /**
37  * Common ancestor of AssemblyOutputElemData and AssemblyOutputNodeData class.
38  */
39 template <unsigned int dim>
40 class AssemblyOutputBase : public AssemblyBase<dim>
41 {
42 public:
45 
46  /// Constructor.
47  AssemblyOutputBase(unsigned int quad_order, EqFields *eq_fields, EqData *eq_data)
48  : AssemblyBase<dim>(quad_order), eq_fields_(eq_fields), eq_data_(eq_data) {
50  offsets_.resize(1.1 * CacheMapElementNumber::get());
51  }
52 
53  /// Constructor.
54  AssemblyOutputBase(EqFields *eq_fields, EqData *eq_data)
55  : AssemblyBase<dim>(), eq_fields_(eq_fields), eq_data_(eq_data) {
57  offsets_.resize(1.1 * CacheMapElementNumber::get());
58  }
59 
60  /// Initialize auxiliary vectors and other data members
61  void initialize(ElementCacheMap *element_cache_map) {
62  this->element_cache_map_ = element_cache_map;
63  }
64 
65  /// Sets output data members.
66  void set_output_data(const FieldSet &used, std::shared_ptr<OutputTime> stream) {
68  used_fields_ += used;
69  stream_ = stream;
70  }
71 
72  /// Implements @p AssemblyBase::end.
73  void end() override
74  {
76  stream_->update_time(f_acc->time());
77  }
78  }
79 
80 
81 protected:
82  void reset_offsets() {
83  std::fill(offsets_.begin(), offsets_.end(), -1);
84  }
85 
86  /// Data objects shared with EquationOutput
89 
90  FieldSet used_fields_; ///< Sub field set contains fields performed to output
91  std::shared_ptr<OutputTime> stream_; ///< Output stream.
92  std::vector<int> offsets_; ///< Holds indices (offsets) of cached data to output data vector
93 };
94 
95 
96 /**
97  * Auxiliary container class for Finite element and related objects of given dimension.
98  */
99 template <unsigned int dim>
101 {
102 public:
106 
107  static constexpr const char * name() { return "AssemblyOutputElemData"; }
108 
109  /// Constructor.
110  AssemblyOutputElemData(EqFields *eq_fields, EqData *eq_data)
111  : AssemblyOutputBase<dim>(0, eq_fields, eq_data) {}
112 
113  /// Destructor.
115 
116  /// Assembles the cell integrals for the given dimension.
117  inline void assemble_cell_integrals(const RevertableList<BulkIntegralData> &bulk_integral_data) {
118  if (dim!=1) return; // Perform full output in one loop
119  unsigned int element_patch_idx, field_value_cache_position, val_idx;
120  this->reset_offsets();
121  for (unsigned int i=0; i<bulk_integral_data.permanent_size(); ++i) {
122  element_patch_idx = this->element_cache_map_->position_in_cache(bulk_integral_data[i].cell.elm_idx());
123  auto p = *( this->bulk_points(element_patch_idx).begin() ); // evaluation point (in element center)
124  field_value_cache_position = this->element_cache_map_->element_eval_point(element_patch_idx, p.eval_point_idx());
125  val_idx = this->stream_->get_output_mesh_ptr()->get_loc_elem_idx(bulk_integral_data[i].cell.elm_idx());
126  this->offsets_[field_value_cache_position] = val_idx;
127  }
128  for (FieldListAccessor f_acc : this->used_fields_.fields_range()) {
129  f_acc->fill_data_value(this->offsets_);
130  }
131  }
132 
133  template < template<IntDim...> class DimAssembly>
134  friend class GenericAssembly;
135 };
136 
137 
138 /**
139  * Auxiliary container class for Finite element and related objects of given dimension.
140  */
141 template <unsigned int dim>
143 {
144 public:
148 
149  static constexpr const char * name() { return "AssemblyOutputNodeData"; }
150 
151  /// Constructor.
152  AssemblyOutputNodeData(EqFields *eq_fields, EqData *eq_data)
153  : AssemblyOutputBase<dim>(eq_fields, eq_data) {
154  this->quad_ = new Quadrature(dim, RefElement<dim>::n_nodes);
155  for(unsigned int i = 0; i<RefElement<dim>::n_nodes; i++)
156  {
157  this->quad_->weight(i) = 1.0;
158  this->quad_->set(i) = RefElement<dim>::node_coords(i);
159  }
160  }
161 
162  /// Destructor.
164 
165  /// Sets output data members.
166  void set_output_data(const FieldSet &used, std::shared_ptr<OutputTime> stream) {
168  offset_vec_ = this->stream_->get_output_mesh_ptr()->offsets()->get_data();
169  }
170 
171 
172  /// Assembles the cell integrals for the given dimension.
173  inline void assemble_cell_integrals(const RevertableList<BulkIntegralData> &bulk_integral_data) {
174  if (dim!=1) return; // Perform full output in one loop
175  unsigned int element_patch_idx, field_value_cache_position, val_idx;
176  this->reset_offsets();
177  for (unsigned int i=0; i<bulk_integral_data.permanent_size(); ++i) {
178  element_patch_idx = this->element_cache_map_->position_in_cache(bulk_integral_data[i].cell.elm_idx());
179  val_idx = (*offset_vec_)[ this->stream_->get_output_mesh_ptr()->get_loc_elem_idx(bulk_integral_data[i].cell.elm_idx()) ];
180  auto p = *( this->bulk_points(element_patch_idx).begin() );
181  field_value_cache_position = this->element_cache_map_->element_eval_point(element_patch_idx, p.eval_point_idx());
182  for (uint j=0; j<bulk_integral_data[i].cell.dim()+1; ++j) {
183  this->offsets_[field_value_cache_position+j] = val_idx+j;
184  }
185  }
186  for (FieldListAccessor f_acc : this->used_fields_.fields_range()) {
187  f_acc->fill_data_value(this->offsets_);
188  }
189  }
190 
191 private:
192  std::shared_ptr< std::vector<unsigned int> > offset_vec_; ///< Holds offsets of individual local elements
193 
194  template < template<IntDim...> class DimAssembly>
195  friend class GenericAssembly;
196 
197 };
198 
199 #endif /* ASSEMBLY_OUTPUT_HH_ */
CacheMapElementNumber::get
static unsigned int get()
Return number of stored elements.
Definition: field_value_cache.hh:93
AssemblyOutputBase::initialize
void initialize(ElementCacheMap *element_cache_map)
Initialize auxiliary vectors and other data members.
Definition: assembly_output.hh:61
ref_element.hh
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
element_data_cache.hh
AssemblyOutputNodeData::name
static constexpr const char * name()
Definition: assembly_output.hh:149
AssemblyOutputNodeData
Definition: assembly_output.hh:142
FieldListAccessor
Definition: field_set.hh:61
RefElement
Definition: ref_element.hh:339
AssemblyOutputNodeData::assemble_cell_integrals
void assemble_cell_integrals(const RevertableList< BulkIntegralData > &bulk_integral_data)
Assembles the cell integrals for the given dimension.
Definition: assembly_output.hh:173
ElementCacheMap::position_in_cache
unsigned int position_in_cache(unsigned mesh_elm_idx, bool bdr=false) const
Return position of element stored in ElementCacheMap.
Definition: field_value_cache.hh:215
AssemblyOutputBase
Definition: assembly_output.hh:40
ElementCacheMap
Directing class of FieldValueCache.
Definition: field_value_cache.hh:151
fe_values.hh
Class FEValues calculates finite element data on the actual cells such as shape function values,...
RevertableList::permanent_size
std::size_t permanent_size() const
Return permanent size of list.
Definition: revertable_list.hh:71
AssemblyOutputBase::offsets_
std::vector< int > offsets_
Holds indices (offsets) of cached data to output data vector.
Definition: assembly_output.hh:92
AssemblyOutputBase::EqData
EquationOutput EqData
Definition: assembly_output.hh:44
FieldSet::fields_range
Range< FieldListAccessor > fields_range() const
Returns range of Fields held in field_list.
Definition: field_set.cc:329
AssemblyOutputNodeData::~AssemblyOutputNodeData
~AssemblyOutputNodeData()
Destructor.
Definition: assembly_output.hh:163
std::vector< int >
AssemblyOutputBase::AssemblyOutputBase
AssemblyOutputBase(EqFields *eq_fields, EqData *eq_data)
Constructor.
Definition: assembly_output.hh:54
uint
unsigned int uint
Definition: mh_dofhandler.hh:101
assembly_base.hh
GenericAssemblyBase::BulkIntegralData
Definition: generic_assembly.hh:60
AssemblyOutputNodeData::BulkIntegralData
GenericAssemblyBase::BulkIntegralData BulkIntegralData
Definition: assembly_output.hh:147
fe_p.hh
Definitions of basic Lagrangean finite elements with polynomial shape functions.
AssemblyOutputBase::stream_
std::shared_ptr< OutputTime > stream_
Output stream.
Definition: assembly_output.hh:91
AssemblyOutputNodeData::EqFields
EquationOutput EqFields
Definition: assembly_output.hh:145
AssemblyOutputElemData::name
static constexpr const char * name()
Definition: assembly_output.hh:107
generic_assembly.hh
quadrature_lib.hh
Definitions of particular quadrature rules on simplices.
AssemblyOutputNodeData::AssemblyOutputNodeData
AssemblyOutputNodeData(EqFields *eq_fields, EqData *eq_data)
Constructor.
Definition: assembly_output.hh:152
Quadrature::set
Armor::Array< double >::ArrayMatSet set(uint i)
Definition: quadrature.hh:97
EquationOutput
Definition: equation_output.hh:44
AssemblyOutputNodeData::offset_vec_
std::shared_ptr< std::vector< unsigned int > > offset_vec_
Holds offsets of individual local elements.
Definition: assembly_output.hh:192
output_time.hh
Quadrature::weight
double weight(unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:107
ElementCacheMap::element_eval_point
int element_eval_point(unsigned int i_elem_in_cache, unsigned int i_eval_point) const
Definition: field_value_cache.hh:204
AssemblyOutputElemData::~AssemblyOutputElemData
~AssemblyOutputElemData()
Destructor.
Definition: assembly_output.hh:114
AssemblyOutputBase::used_fields_
FieldSet used_fields_
Sub field set contains fields performed to output.
Definition: assembly_output.hh:90
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
RevertableList< BulkIntegralData >
AssemblyOutputBase::end
void end() override
Implements AssemblyBase::end.
Definition: assembly_output.hh:73
AssemblyOutputBase::reset_offsets
void reset_offsets()
Definition: assembly_output.hh:82
AssemblyOutputBase::EqFields
EquationOutput EqFields
Definition: assembly_output.hh:43
AssemblyOutputBase::set_output_data
void set_output_data(const FieldSet &used, std::shared_ptr< OutputTime > stream)
Sets output data members.
Definition: assembly_output.hh:66
AssemblyBase::bulk_points
Range< BulkPoint > bulk_points(unsigned int element_patch_idx) const
Return BulkPoint range of appropriate dimension.
Definition: assembly_base.hh:104
RefElement::node_coords
static LocalPoint node_coords(unsigned int nid)
Definition: ref_element.hh:619
AssemblyOutputElemData::EqFields
EquationOutput EqFields
Definition: assembly_output.hh:103
bulk
@ bulk
Definition: generic_assembly.hh:33
AssemblyOutputNodeData::set_output_data
void set_output_data(const FieldSet &used, std::shared_ptr< OutputTime > stream)
Sets output data members.
Definition: assembly_output.hh:166
AssemblyOutputElemData::assemble_cell_integrals
void assemble_cell_integrals(const RevertableList< BulkIntegralData > &bulk_integral_data)
Assembles the cell integrals for the given dimension.
Definition: assembly_output.hh:117
field_value_cache.hh
AssemblyBase::active_integrals_
int active_integrals_
Holds mask of active integrals.
Definition: assembly_base.hh:191
AssemblyOutputBase::eq_data_
EqData * eq_data_
Definition: assembly_output.hh:88
AssemblyOutputElemData::AssemblyOutputElemData
AssemblyOutputElemData(EqFields *eq_fields, EqData *eq_data)
Constructor.
Definition: assembly_output.hh:110
AssemblyOutputNodeData::EqData
EquationOutput EqData
Definition: assembly_output.hh:146
AssemblyOutputBase::eq_fields_
EqFields * eq_fields_
Data objects shared with EquationOutput.
Definition: assembly_output.hh:87
AssemblyBase
Definition: assembly_base.hh:34
AssemblyOutputElemData
Definition: assembly_output.hh:100
balance.hh
AssemblyOutputBase::AssemblyOutputBase
AssemblyOutputBase(unsigned int quad_order, EqFields *eq_fields, EqData *eq_data)
Constructor.
Definition: assembly_output.hh:47
Quadrature
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
GenericAssembly
Generic class of assemblation.
Definition: generic_assembly.hh:160
AssemblyOutputElemData::EqData
EquationOutput EqData
Definition: assembly_output.hh:104
AssemblyBase::element_cache_map_
ElementCacheMap * element_cache_map_
ElementCacheMap shared with GenericAssembly object.
Definition: assembly_base.hh:193
AssemblyOutputElemData::BulkIntegralData
GenericAssemblyBase::BulkIntegralData BulkIntegralData
Definition: assembly_output.hh:105
AssemblyBase::quad_
Quadrature * quad_
Quadrature used in assembling methods.
Definition: assembly_base.hh:189
IntDim
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19