Flow123d  DF_patch_fe_values-dbc06cd
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"
27 #include "coupling/balance.hh"
28 #include "fem/element_cache_map.hh"
29 #include "io/output_time.hh"
30 #include "io/element_data_cache.hh"
31 #include "mesh/ref_element.hh"
32 
33 
34 
35 /**
36  * Common ancestor of AssemblyOutputElemData and AssemblyOutputNodeData class.
37  */
38 template <unsigned int dim, class TEqData>
40 {
41 public:
42  typedef TEqData EqFields;
43  typedef TEqData EqData;
44 
45  /// Constructor.
46  AssemblyOutputBase(unsigned int quad_order, EqData *eq_data, AssemblyInternals *asm_internals)
47  : AssemblyBasePatch<dim>(quad_order, asm_internals), eq_fields_(eq_data), eq_data_(eq_data) {
49  }
50 
51  /// Constructor.
52  AssemblyOutputBase(EqData *eq_data, AssemblyInternals *asm_internals)
53  : AssemblyBasePatch<dim>(), eq_fields_(eq_data), eq_data_(eq_data) {
54  this->asm_internals_ = asm_internals;
56  }
57 
58  /// Initialize auxiliary vectors and other data members
59  void initialize() {}
60 
61  /// Sets output data members.
62  void set_output_data(const FieldSet &used, std::shared_ptr<OutputTime> stream) {
64  used_fields_ += used;
65  stream_ = stream;
66  }
67 
68  /// Implements @p AssemblyBase::end.
69  void end() override
70  {
72  stream_->update_time(f_acc->time());
73  }
74  }
75 
76 
77 protected:
78  void reset_offsets() {
79  std::fill(offsets_.begin(), offsets_.end(), -1);
80  }
81 
82  /// Data objects shared with EquationOutput
85 
86  FieldSet used_fields_; ///< Sub field set contains fields performed to output
87  std::shared_ptr<OutputTime> stream_; ///< Output stream.
88  std::vector<int> offsets_; ///< Holds indices (offsets) of cached data to output data vector
89 };
90 
91 
92 /**
93  * Auxiliary container class for Finite element and related objects of given dimension.
94  */
95 template <unsigned int dim, class TEqData>
96 class AssemblyOutputElemData : public AssemblyOutputBase<dim, TEqData>
97 {
98 public:
99  typedef TEqData EqFields;
100  typedef TEqData EqData;
101 
102  static constexpr const char * name() { return "Output_ElemData_Assembly"; }
103 
104  /// Constructor.
106  : AssemblyOutputBase<dim, TEqData>(0, eq_data, asm_internals),
107  bulk_integral_( this->create_bulk_integral(this->quad_) ) {}
108 
109  /// Destructor.
111 
112  /// Assembles the cell integrals for the given dimension.
113  inline void assemble_cell_integrals() {
114  unsigned int element_patch_idx, field_value_cache_position, val_idx;
115  this->reset_offsets();
116  auto &patch_data = bulk_integral_->patch_data();
117  for (unsigned int i=0; i<patch_data.permanent_size(); ++i) { // holds only one BulkIntegral and uses zero index fixedly
118  element_patch_idx = this->asm_internals_->element_cache_map_.position_in_cache(patch_data[i].cell.elm_idx());
119  auto p = *( bulk_integral_->points(element_patch_idx).begin() ); // evaluation point (in element center)
120  field_value_cache_position = this->asm_internals_->element_cache_map_.element_eval_point(element_patch_idx, p.eval_point_idx());
121  val_idx = this->stream_->get_output_mesh_ptr()->get_loc_elem_idx(patch_data[i].cell.elm_idx());
122  this->offsets_[field_value_cache_position] = val_idx;
123  }
124  for (FieldListAccessor f_acc : this->used_fields_.fields_range()) {
125  f_acc->fill_data_value(this->offsets_);
126  }
127  }
128 
129 private:
130  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_;
131 
132  template < template<IntDim...> class DimAssembly>
133  friend class GenericAssembly;
134 };
135 
136 
137 /**
138  * Auxiliary container class for Finite element and related objects of given dimension.
139  */
140 template <unsigned int dim, class TEqData>
141 class AssemblyOutputNodeData : public AssemblyOutputBase<dim, TEqData>
142 {
143 public:
144  typedef TEqData EqFields;
145  typedef TEqData EqData;
146 
147  static constexpr const char * name() { return "Output_NodeData_Assembly"; }
148 
149  /// Constructor.
151  : AssemblyOutputBase<dim, TEqData>(eq_data, asm_internals) {
152  this->quad_ = new Quadrature(dim, RefElement<dim>::n_nodes);
153  for(unsigned int i = 0; i<RefElement<dim>::n_nodes; i++)
154  {
155  this->quad_->weight(i) = 1.0;
156  this->quad_->set(i) = RefElement<dim>::node_coords(i);
157  }
159  }
160 
161  /// Destructor.
163 
164  /// Sets output data members.
165  void set_output_data(const FieldSet &used, std::shared_ptr<OutputTime> stream) {
167  offset_vec_ = this->stream_->get_output_mesh_ptr()->offsets()->get_data();
168  }
169 
170 
171  /// Assembles the cell integrals for the given dimension.
172  inline void assemble_cell_integrals() {
173  unsigned int element_patch_idx, field_value_cache_position, val_idx;
174  this->reset_offsets();
175  auto &patch_data = bulk_integral_->patch_data();
176  for (unsigned int i=0; i<patch_data.permanent_size(); ++i) { // holds only one BulkIntegral and uses zero index fixedly
177  element_patch_idx = this->asm_internals_->element_cache_map_.position_in_cache(patch_data[i].cell.elm_idx());
178  val_idx = (*offset_vec_)[ this->stream_->get_output_mesh_ptr()->get_loc_elem_idx(patch_data[i].cell.elm_idx()) ];
179  auto p = *( bulk_integral_->points(element_patch_idx).begin() );
180  field_value_cache_position = this->asm_internals_->element_cache_map_.element_eval_point(element_patch_idx, p.eval_point_idx());
181  for (uint j=0; j<patch_data[i].cell.dim()+1; ++j) {
182  this->offsets_[field_value_cache_position+j] = val_idx+j;
183  }
184  }
185  for (FieldListAccessor f_acc : this->used_fields_.fields_range()) {
186  f_acc->fill_data_value(this->offsets_);
187  }
188  }
189 
190 private:
191  std::shared_ptr< std::vector<unsigned int> > offset_vec_; ///< Holds offsets of individual local elements
192 
193  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_;
194 
195  template < template<IntDim...> class DimAssembly>
196  friend class GenericAssembly;
197 
198 };
199 
200 #endif /* ASSEMBLY_OUTPUT_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.
AssemblyOutputBase(unsigned int quad_order, EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
EqFields * eq_fields_
Data objects shared with EquationOutput.
std::shared_ptr< OutputTime > stream_
Output stream.
AssemblyOutputBase(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
FieldSet used_fields_
Sub field set contains fields performed to output.
void end() override
Implements AssemblyBase::end.
void set_output_data(const FieldSet &used, std::shared_ptr< OutputTime > stream)
Sets output data members.
std::vector< int > offsets_
Holds indices (offsets) of cached data to output data vector.
void initialize()
Initialize auxiliary vectors and other data members.
void assemble_cell_integrals()
Assembles the cell integrals for the given dimension.
AssemblyOutputElemData(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
~AssemblyOutputElemData()
Destructor.
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
static constexpr const char * name()
~AssemblyOutputNodeData()
Destructor.
static constexpr const char * name()
std::shared_ptr< std::vector< unsigned int > > offset_vec_
Holds offsets of individual local elements.
std::shared_ptr< BulkIntegralAcc< dim > > bulk_integral_
void set_output_data(const FieldSet &used, std::shared_ptr< OutputTime > stream)
Sets output data members.
void assemble_cell_integrals()
Assembles the cell integrals for the given dimension.
AssemblyOutputNodeData(EqData *eq_data, AssemblyInternals *asm_internals)
Constructor.
static unsigned int get()
Return number of stored elements.
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
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:634
Definitions of basic Lagrangean finite elements with polynomial shape functions.
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.
Holds common data shared between GenericAssemblz and Assembly<dim> classes.
ElementCacheMap element_cache_map_
ElementCacheMap according to EvalPoints.