Flow123d  master-f44eb46
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) {
51  }
52 
53  /// Constructor.
54  AssemblyOutputBase(EqFields *eq_fields, EqData *eq_data)
55  : AssemblyBase<dim>(), eq_fields_(eq_fields), eq_data_(eq_data) {
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_ */
Range< BulkPoint > bulk_points(unsigned int element_patch_idx) const
Return BulkPoint range of appropriate dimension.
Quadrature * quad_
Quadrature used in assembling methods.
int active_integrals_
Holds mask of active integrals.
ElementCacheMap * element_cache_map_
ElementCacheMap shared with GenericAssembly object.
AssemblyOutputBase(unsigned int quad_order, EqFields *eq_fields, EqData *eq_data)
Constructor.
EquationOutput EqFields
EqFields * eq_fields_
Data objects shared with EquationOutput.
std::shared_ptr< OutputTime > stream_
Output stream.
std::vector< int > offsets_
Holds indices (offsets) of cached data to output data vector.
EquationOutput EqData
AssemblyOutputBase(EqFields *eq_fields, EqData *eq_data)
Constructor.
void initialize(ElementCacheMap *element_cache_map)
Initialize auxiliary vectors and other data members.
void end() override
Implements AssemblyBase::end.
void set_output_data(const FieldSet &used, std::shared_ptr< OutputTime > stream)
Sets output data members.
FieldSet used_fields_
Sub field set contains fields performed to output.
GenericAssemblyBase::BulkIntegralData BulkIntegralData
~AssemblyOutputElemData()
Destructor.
void assemble_cell_integrals(const RevertableList< BulkIntegralData > &bulk_integral_data)
Assembles the cell integrals for the given dimension.
AssemblyOutputElemData(EqFields *eq_fields, EqData *eq_data)
Constructor.
static constexpr const char * name()
void assemble_cell_integrals(const RevertableList< BulkIntegralData > &bulk_integral_data)
Assembles the cell integrals for the given dimension.
AssemblyOutputNodeData(EqFields *eq_fields, EqData *eq_data)
Constructor.
static constexpr const char * name()
std::shared_ptr< std::vector< unsigned int > > offset_vec_
Holds offsets of individual local elements.
void set_output_data(const FieldSet &used, std::shared_ptr< OutputTime > stream)
Sets output data members.
~AssemblyOutputNodeData()
Destructor.
GenericAssemblyBase::BulkIntegralData BulkIntegralData
static unsigned int get()
Return number of stored elements.
Directing class of FieldValueCache.
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:159
Range< FieldListAccessor > fields_range() const
Returns range of Fields held in field_list.
Definition: field_set.cc:275
Generic class of assemblation.
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
static LocalPoint node_coords(unsigned int nid)
Definition: ref_element.hh:619
Definitions of basic Lagrangean finite elements with polynomial shape functions.
Class FEValues calculates finite element data on the actual cells such as shape function values,...
@ bulk
unsigned int uint
unsigned int IntDim
A dimension index type.
Definition: mixed.hh:19
Definitions of particular quadrature rules on simplices.
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
std::size_t permanent_size() const
Return permanent size of list.