Flow123d  DF_patch_fe_darcy_complete-579fe1e
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"
29 #include "fem/element_cache_map.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, class TEqData>
40 class AssemblyOutputBase : public AssemblyBase<dim>
41 {
42 public:
43  typedef TEqData EqFields;
44  typedef TEqData EqData;
45 
46  /// Constructor.
47  AssemblyOutputBase(unsigned int quad_order, EqData *eq_data, AssemblyInternals *asm_internals)
48  : AssemblyBase<dim>(quad_order, asm_internals), eq_fields_(eq_data), eq_data_(eq_data) {
50  }
51 
52  /// Constructor.
53  AssemblyOutputBase(EqData *eq_data, AssemblyInternals *asm_internals)
54  : AssemblyBase<dim>(), eq_fields_(eq_data), eq_data_(eq_data) {
55  this->asm_internals_ = asm_internals;
57  }
58 
59  /// Initialize auxiliary vectors and other data members
60  void initialize() {}
61 
62  /// Sets output data members.
63  void set_output_data(const FieldSet &used, std::shared_ptr<OutputTime> stream) {
65  used_fields_ += used;
66  stream_ = stream;
67  }
68 
69  /// Implements @p AssemblyBase::end.
70  void end() override
71  {
73  stream_->update_time(f_acc->time());
74  }
75  }
76 
77 
78 protected:
79  void reset_offsets() {
80  std::fill(offsets_.begin(), offsets_.end(), -1);
81  }
82 
83  /// Data objects shared with EquationOutput
86 
87  FieldSet used_fields_; ///< Sub field set contains fields performed to output
88  std::shared_ptr<OutputTime> stream_; ///< Output stream.
89  std::vector<int> offsets_; ///< Holds indices (offsets) of cached data to output data vector
90 };
91 
92 
93 /**
94  * Auxiliary container class for Finite element and related objects of given dimension.
95  */
96 template <unsigned int dim, class TEqData>
97 class AssemblyOutputElemData : public AssemblyOutputBase<dim, TEqData>
98 {
99 public:
100  typedef TEqData EqFields;
101  typedef TEqData EqData;
102 
103  static constexpr const char * name() { return "Output_ElemData_Assembly"; }
104 
105  /// Constructor.
107  : AssemblyOutputBase<dim, TEqData>(0, eq_data, asm_internals),
108  bulk_integral_( this->create_bulk_integral(this->quad_) ) {}
109 
110  /// Destructor.
112 
113  /// Assembles the cell integrals for the given dimension.
114  inline void assemble_cell_integrals() {
115  unsigned int element_patch_idx, field_value_cache_position, val_idx;
116  this->reset_offsets();
117  for (unsigned int i=0; i<this->integral_data_.bulk_[0].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(this->integral_data_.bulk_[0][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(this->integral_data_.bulk_[0][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  for (unsigned int i=0; i<this->integral_data_.bulk_[0].permanent_size(); ++i) { // holds only one BulkIntegral and uses zero index fixedly
176  element_patch_idx = this->asm_internals_->element_cache_map_.position_in_cache(this->integral_data_.bulk_[0][i].cell.elm_idx());
177  val_idx = (*offset_vec_)[ this->stream_->get_output_mesh_ptr()->get_loc_elem_idx(this->integral_data_.bulk_[0][i].cell.elm_idx()) ];
178  auto p = *( bulk_integral_->points(element_patch_idx).begin() );
179  field_value_cache_position = this->asm_internals_->element_cache_map_.element_eval_point(element_patch_idx, p.eval_point_idx());
180  for (uint j=0; j<this->integral_data_.bulk_[0][i].cell.dim()+1; ++j) {
181  this->offsets_[field_value_cache_position+j] = val_idx+j;
182  }
183  }
184  for (FieldListAccessor f_acc : this->used_fields_.fields_range()) {
185  f_acc->fill_data_value(this->offsets_);
186  }
187  }
188 
189 private:
190  std::shared_ptr< std::vector<unsigned int> > offset_vec_; ///< Holds offsets of individual local elements
191 
192  std::shared_ptr<BulkIntegralAcc<dim>> bulk_integral_;
193 
194  template < template<IntDim...> class DimAssembly>
195  friend class GenericAssembly;
196 
197 };
198 
199 #endif /* ASSEMBLY_OUTPUT_HH_ */
IntegralData integral_data_
Holds patch data for computing different types of integrals.
Quadrature * quad_
Quadrature used in assembling methods.
AssemblyInternals * asm_internals_
Holds shared internals data with GeneriAssembly.
std::shared_ptr< BulkIntegralAcc< dim > > create_bulk_integral(Quadrature *quad)
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: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:634
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,...
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.
RevertableListVector< BulkIntegralData > bulk_
Holds data for computing bulk integrals.