Flow123d  release_2.2.0-21-g2806cf6
output_mesh.cc
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 output_mesh.cc
15  * @brief Classes for auxiliary output mesh.
16  */
17 
18 #include "output_mesh.hh"
19 #include "output_element.hh"
20 #include "mesh/mesh.h"
21 
22 namespace IT=Input::Type;
23 
25  return IT::Record("OutputMesh", "Parameters of the refined output mesh.")
26  .declare_key("max_level", IT::Integer(1,20),IT::Default("3"),
27  "Maximal level of refinement of the output mesh.")
28  .declare_key("refine_by_error", IT::Bool(), IT::Default("false"),
29  "Set true for using error_control_field. Set false for global uniform refinement to max_level.")
30  .declare_key("error_control_field",IT::String(), IT::Default::optional(),
31  "Name of an output field, according to which the output mesh will be refined. The field must be a SCALAR one.")
32  .close();
33 }
34 
36 :
37  nodes_( std::make_shared<ElementDataCache<double>>("", ElementDataCacheBase::N_VECTOR, 1, 0) ),
38  connectivity_( std::make_shared<ElementDataCache<unsigned int>>("connectivity", ElementDataCacheBase::N_SCALAR, 1, 0) ),
39  offsets_( std::make_shared<ElementDataCache<unsigned int>>("offsets", ElementDataCacheBase::N_SCALAR, 1, 0) ),
40  orig_mesh_(&mesh),
41  max_level_(0),
43 {
44 }
45 
46 
48 :
49  nodes_( std::make_shared<ElementDataCache<double>>("", ElementDataCacheBase::N_VECTOR, 1, 0) ),
50  connectivity_( std::make_shared<ElementDataCache<unsigned int>>("connectivity", ElementDataCacheBase::N_SCALAR, 1, 0) ),
51  offsets_( std::make_shared<ElementDataCache<unsigned int>>("offsets", ElementDataCacheBase::N_SCALAR, 1, 0) ),
52  input_record_(in_rec),
53  orig_mesh_(&mesh),
54  max_level_(input_record_.val<int>("max_level"))
55 {
56  // Read optional error control field name
57  bool use_field = input_record_.val<bool>("refine_by_error");
59  if(use_field) {
60  auto it = input_record_.find<std::string>("error_control_field");
61  if(it) error_control_field_name_ = *it;
62  }
63 }
64 
66 {
67 }
68 
70 {
72  return OutputElementIterator(OutputElement(0, shared_from_this()));
73 }
74 
76 {
78  return OutputElementIterator(OutputElement(offsets_->n_values(), shared_from_this()));
79 }
80 
82 {
84  return offsets_->n_values();
85 }
86 
88 {
90  return nodes_->n_values();
91 }
92 
93 
94 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
95 
96 
98 : OutputMeshBase(mesh)
99 {
100 }
101 
103 : OutputMeshBase(mesh, in_rec)
104 {
105 }
106 
107 
109 {
110 }
111 
112 
114 {
115  nodes_.reset();
116  connectivity_.reset();
117  offsets_.reset();
118 
119  DebugOut() << "Create outputmesh identical to computational one.";
120 
121  const unsigned int n_elements = orig_mesh_->n_elements(),
123 
124  nodes_ = std::make_shared<ElementDataCache<double>>("", ElementDataCacheBase::N_VECTOR, 1, n_nodes);
125  unsigned int coord_id = 0, // coordinate id in vector
126  node_id = 0; // node id
127  auto &node_vec = *( nodes_->get_component_data(0).get() );
128  FOR_NODES(orig_mesh_, node) {
129  node->aux = node_id; // store node index in the auxiliary variable
130 
131  // use store value
132  node_vec[coord_id] = node->getX(); coord_id++;
133  node_vec[coord_id] = node->getY(); coord_id++;
134  node_vec[coord_id] = node->getZ(); coord_id++;
135  node_id++;
136  }
137 
138  orig_element_indices_ = std::make_shared<std::vector<unsigned int>>(n_elements);
139 
140  offsets_ = std::make_shared<ElementDataCache<unsigned int>>("offsets", ElementDataCacheBase::N_SCALAR, 1, n_elements);
141  Node* node;
142  unsigned int ele_id = 0,
143  connect_id = 0,
144  offset = 0, // offset of node indices of element in node vector
145  li; // local node index
146  auto &offset_vec = *( offsets_->get_component_data(0).get() );
147  FOR_ELEMENTS(orig_mesh_, ele) {
148  // increase offset by number of nodes of the simplicial element
149  offset += ele->dim() + 1;
150  offset_vec[ele_id] = offset;
151  (*orig_element_indices_)[ele_id] = ele_id;
152  ele_id++;
153  }
154 
155  const unsigned int n_connectivities = offset_vec[offset_vec.size()-1];
156  connectivity_ = std::make_shared<ElementDataCache<unsigned int>>("connectivity", ElementDataCacheBase::N_SCALAR, 1, n_connectivities);
157  auto &connect_vec = *( connectivity_->get_component_data(0).get() );
158  FOR_ELEMENTS(orig_mesh_, ele) {
159  FOR_ELEMENT_NODES(ele, li) {
160  node = ele->node[li];
161  connect_vec[connect_id] = node->aux;
162  connect_id++;
163  }
164 
165  }
166  connectivity_->get_component_data(0)->shrink_to_fit();
167 }
168 
170 {
171  ASSERT(0).error("Not implemented yet.");
172 }
173 
174 
176 {
177  ASSERT(0).error("Not implemented yet.");
178  return false;
179 }
180 
181 
182 
183 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
184 
186 : OutputMeshBase(mesh)
187 {
188 }
189 
191 : OutputMeshBase(mesh, in_rec)
192 {
193 }
194 
195 
197 {
198 }
199 
200 
201 void OutputMeshDiscontinuous::create_mesh(shared_ptr< OutputMesh > output_mesh)
202 {
203  nodes_.reset();
204  connectivity_.reset();
205  offsets_.reset();
206 
207  ASSERT_DBG(output_mesh->nodes_->n_values() > 0); //continuous data already computed
208 
209  if (nodes_) return; //already computed
210 
211  DebugOut() << "Create discontinuous outputmesh.";
212 
213  // connectivity = for every element list the nodes => its length corresponds to discontinuous data
214  const unsigned int n_corners = output_mesh->connectivity_->n_values();
215 
216  // these are the same as in continuous case, so we copy the pointer.
217  offsets_ = output_mesh->offsets_;
218  orig_element_indices_ = output_mesh->orig_element_indices_;
219 
220  nodes_ = std::make_shared<ElementDataCache<double>>("", ElementDataCacheBase::N_VECTOR, 1, n_corners);
221  connectivity_ = std::make_shared<ElementDataCache<unsigned int>>("connectivity", ElementDataCacheBase::N_SCALAR, 1, n_corners);
222 
223  unsigned int coord_id = 0, // coordinate id in vector
224  corner_id = 0, // corner index (discontinous node)
225  li; // local node index
226 
227  auto &node_vec = *( nodes_->get_component_data(0).get() );
228  auto &conn_vec = *( connectivity_->get_component_data(0).get() );
229  for(const auto & ele : *output_mesh)
230  {
231  unsigned int n = ele.n_nodes(),
232  ele_idx = ele.idx(),
233  con_off = (* offsets_)[ele_idx];
234 
235  for(li = 0; li < n; li++)
236  {
237  // offset of the first coordinate of the first node of the element in nodes_ vector
238  unsigned int off = spacedim * (* output_mesh->connectivity_)[con_off - n + li];
239  auto &d = *( output_mesh->nodes_->get_component_data(0).get() );
240 
241  node_vec[coord_id] = d[off]; ++coord_id;
242  node_vec[coord_id] = d[off+1]; ++coord_id;
243  node_vec[coord_id] = d[off+2]; ++coord_id;
244 
245  conn_vec[corner_id] = corner_id;
246  corner_id++;
247  }
248  }
249 }
250 
251 
253 {
254  ASSERT(0).error("Not implemented yet.");
255 }
256 
258 {
259  ASSERT(0).error("Not implemented yet.");
260  return false;
261 }
262 
Classes for auxiliary output mesh.
void create_refined_mesh() override
Creates refined mesh.
Definition: output_mesh.cc:169
static const unsigned int spacedim
Shortcut instead of spacedim template. We suppose only spacedim=3 at the moment.
Definition: output_mesh.hh:66
#define FOR_ELEMENT_NODES(i, j)
Definition: elements.h:187
Base class for Output mesh.
Definition: output_mesh.hh:62
GeneralIterator< OutputElement > OutputElementIterator
Definition: output_mesh.hh:31
Definition: nodes.hh:32
unsigned int n_elements()
Returns number of element.
Definition: output_mesh.cc:81
Mesh * orig_mesh_
Pointer to the computational mesh.
Definition: output_mesh.hh:113
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
#define FOR_ELEMENTS(_mesh_, __i)
Definition: mesh.h:426
Class for declaration of the input of type Bool.
Definition: type_base.hh:458
static const Input::Type::Record & get_input_type()
The specification of output mesh.
Definition: output_mesh.cc:24
const unsigned int max_level_
Maximal level of refinement.
Definition: output_mesh.hh:116
Definition: mesh.h:97
Iterator< Ret > find(const string &key) const
std::shared_ptr< ElementDataCache< unsigned int > > connectivity_
Vector maps the nodes to their coordinates in vector nodes_.
Definition: output_mesh.hh:99
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:346
Class for declaration of the integral input data.
Definition: type_base.hh:489
std::shared_ptr< ElementDataCache< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
Definition: output_mesh.hh:101
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:303
unsigned int n_nodes()
Returns number of nodes.
Definition: output_mesh.cc:87
std::shared_ptr< ElementDataCache< double > > nodes_
Vector of node coordinates. [spacedim x n_nodes].
Definition: output_mesh.hh:97
OutputMesh(Mesh &mesh)
Definition: output_mesh.cc:97
static Default optional()
The factory function to make an empty default value which is optional.
Definition: type_record.hh:124
unsigned int n_elements() const
Definition: mesh.h:141
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
const Ret val(const string &key) const
std::string error_control_field_name_
Refinement error control field name.
Definition: output_mesh.hh:119
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:490
bool refinement_criterion()
Definition: output_mesh.cc:175
virtual ~OutputMeshBase()
Definition: output_mesh.cc:65
#define FOR_NODES(_mesh_, i)
Definition: mesh.h:58
void create_mesh(std::shared_ptr< OutputMesh > output_mesh)
Creates output mesh from the given continuous one.
Definition: output_mesh.cc:201
OutputMeshDiscontinuous(Mesh &mesh)
Definition: output_mesh.cc:185
Input::Record input_record_
Input record for output mesh.
Definition: output_mesh.hh:110
OutputElementIterator end()
Gives iterator to the LAST element of the output mesh.
Definition: output_mesh.cc:75
friend class OutputElement
Friend provides access to vectors for element accessor class.
Definition: output_mesh.hh:122
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:335
Class OutputElement and its iterator OutputElementIterator on the output mesh.
#define ASSERT_DBG(expr)
Definition: asserts.hh:349
void create_identical_mesh()
Creates the output mesh identical to the computational one.
Definition: output_mesh.cc:113
unsigned int n_nodes() const
Definition: mesh.h:137
Record type proxy class.
Definition: type_record.hh:182
General iterator template. Provides iterator over objects in some container.
#define DebugOut()
Macro defining &#39;debug&#39; record of log.
Definition: logger.hh:242
void create_refined_mesh() override
Creates discontinuous refined mesh.
Definition: output_mesh.cc:252
Class for declaration of the input data that are in string format.
Definition: type_base.hh:588
std::shared_ptr< std::vector< unsigned int > > orig_element_indices_
Vector of element indices in the computational mesh. (Important when refining.)
Definition: output_mesh.hh:94
OutputElementIterator begin()
Gives iterator to the FIRST element of the output mesh.
Definition: output_mesh.cc:69
OutputMeshBase(Mesh &mesh)
Constructor. Takes computational mesh as a parameter.
Definition: output_mesh.cc:35