Flow123d  release_2.1.0-84-g6a13a75
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 #include "fields/field.hh"
22 #include <fields/field_set.hh>
23 
24 namespace IT=Input::Type;
25 
27  return IT::Record("OutputMesh", "Parameters of the refined output mesh.")
28  .declare_key("max_level", IT::Integer(1,20),IT::Default("3"),
29  "Maximal level of refinement of the output mesh.")
30  .declare_key("refine_by_error", IT::Bool(), IT::Default("false"),
31  "Set true for using error_control_field. Set false for global uniform refinement to max_level.")
32  .declare_key("error_control_field",IT::String(), IT::Default::optional(),
33  "Name of an output field, according to which the output mesh will be refined. The field must be a SCALAR one.")
34  .close();
35 }
36 
38 :
39  nodes_ (std::make_shared<MeshData<double>>("", OutputDataBase::N_VECTOR)),
40  connectivity_(std::make_shared<MeshData<unsigned int>>("connectivity")),
41  offsets_(std::make_shared<MeshData<unsigned int>>("offsets")),
42  orig_mesh_(&mesh),
43  max_level_(0)
44 {
45 }
46 
47 
49 :
50  nodes_ (std::make_shared<MeshData<double>>("", OutputDataBase::N_VECTOR)),
51  connectivity_(std::make_shared<MeshData<unsigned int>>("connectivity")),
52  offsets_(std::make_shared<MeshData<unsigned int>>("offsets")),
53  input_record_(in_rec),
54  orig_mesh_(&mesh),
55  max_level_(input_record_.val<int>("max_level"))
56 {
57 }
58 
60 {
61 }
62 
64 {
66  return OutputElementIterator(OutputElement(0, shared_from_this()));
67 }
68 
70 {
72  return OutputElementIterator(OutputElement(offsets_->n_values, shared_from_this()));
73 }
74 
76 {
77  bool use_field = input_record_.val<bool>("refine_by_error");
78 
79  if(use_field)
80  {
81  std::string error_control_field_name = "";
82  // Read optional error control field name
83  auto it = input_record_.find<std::string>("error_control_field");
84  if(it) error_control_field_name = *it;
85 
86  FieldCommon* field = output_fields.field(error_control_field_name);
87  // throw input exception if the field is unknown
88  if(field == nullptr){
89  THROW(FieldSet::ExcUnknownField()
90  << FieldCommon::EI_Field(error_control_field_name)
92  return;
93  }
94 
95  // throw input exception if the field is not scalar
96  if( typeid(*field) == typeid(Field<3,FieldValue<3>::Scalar>) ) {
97 
99  DebugOut() << "Output mesh will be refined according to field " << error_control_field_name << ".";
100  }
101  else{
102  THROW(ExcFieldNotScalar()
103  << FieldCommon::EI_Field(error_control_field_name)
105  }
106  }
107  else
108  {
109  error_control_field_ = nullptr;
110  }
111 }
112 
114 {
116  return offsets_->n_values;
117 }
118 
120 {
122  return nodes_->n_values;
123 }
124 
125 
126 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
127 
128 
130 : OutputMeshBase(mesh)
131 {
132 }
133 
135 : OutputMeshBase(mesh, in_rec)
136 {
137 }
138 
139 
141 {
142 }
143 
144 
146 {
147  DebugOut() << "Create outputmesh identical to computational one.";
148 
149  const unsigned int n_elements = orig_mesh_->n_elements(),
151 
152  nodes_->data_.resize(spacedim*n_nodes); // suppose 3D coordinates
153  nodes_->n_values = n_nodes;
154  unsigned int coord_id = 0, // coordinate id in vector
155  node_id = 0; // node id
156  FOR_NODES(orig_mesh_, node) {
157  node->aux = node_id; // store node index in the auxiliary variable
158 
159  nodes_->data_[coord_id] = node->getX(); coord_id++;
160  nodes_->data_[coord_id] = node->getY(); coord_id++;
161  nodes_->data_[coord_id] = node->getZ(); coord_id++;
162  node_id++;
163  }
164 
165  orig_element_indices_ = std::make_shared<std::vector<unsigned int>>(n_elements);
166  connectivity_->data_.reserve(4*n_elements); //reserve - suppose all elements being tetrahedra (4 nodes)
167  offsets_->data_.resize(n_elements);
168  offsets_->n_values = n_elements;
169  Node* node;
170  unsigned int ele_id = 0,
171  connect_id = 0,
172  offset = 0, // offset of node indices of element in node vector
173  li; // local node index
174  FOR_ELEMENTS(orig_mesh_, ele) {
175  FOR_ELEMENT_NODES(ele, li) {
176  node = ele->node[li];
177  connectivity_->data_.push_back(node->aux);
178  connect_id++;
179  }
180 
181  // increase offset by number of nodes of the simplicial element
182  offset += ele->dim() + 1;
183  offsets_->data_[ele_id] = offset;
184  (*orig_element_indices_)[ele_id] = ele_id;
185  ele_id++;
186  }
187  connectivity_->data_.shrink_to_fit();
188  connectivity_->n_values = connect_id;
189 }
190 
192 {
193  ASSERT(0).error("Not implemented yet.");
194 }
195 
196 
198 {
199  ASSERT(0).error("Not implemented yet.");
200  return false;
201 }
202 
203 
204 
205 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
206 
208 : OutputMeshBase(mesh)
209 {
210 }
211 
213 : OutputMeshBase(mesh, in_rec)
214 {
215 }
216 
217 
219 {
220 }
221 
222 
223 void OutputMeshDiscontinuous::create_mesh(shared_ptr< OutputMesh > output_mesh)
224 {
225  ASSERT_DBG(output_mesh->nodes_->n_values > 0); //continuous data already computed
226 
227  if(nodes_->data_.size() > 0) return; //already computed
228 
229  DebugOut() << "Create discontinuous outputmesh.";
230 
231  // connectivity = for every element list the nodes => its length corresponds to discontinuous data
232  const unsigned int n_corners = output_mesh->connectivity_->n_values;
233 
234  // these are the same as in continuous case, so we copy the pointer.
235  offsets_ = output_mesh->offsets_;
236  orig_element_indices_ = output_mesh->orig_element_indices_;
237 
238  nodes_->data_.resize(spacedim*n_corners);
239  nodes_->n_values = n_corners;
240 
241  connectivity_->data_.resize(n_corners);
242  connectivity_->n_values = n_corners;
243 
244  unsigned int coord_id = 0, // coordinate id in vector
245  corner_id = 0, // corner index (discontinous node)
246  li; // local node index
247 
248  for(const auto & ele : *output_mesh)
249  {
250  unsigned int n = ele.n_nodes(),
251  ele_idx = ele.idx(),
252  con_off = (* offsets_)[ele_idx];
253 
254  for(li = 0; li < n; li++)
255  {
256  // offset of the first coordinate of the first node of the element in nodes_ vector
257  unsigned int off = spacedim * (* output_mesh->connectivity_)[con_off - n + li];
258  auto &d = output_mesh->nodes_->data_;
259 
260  nodes_->data_[coord_id] = d[off]; ++coord_id;
261  nodes_->data_[coord_id] = d[off+1]; ++coord_id;
262  nodes_->data_[coord_id] = d[off+2]; ++coord_id;
263 
264  connectivity_->data_[corner_id] = corner_id;
265  corner_id++;
266  }
267  }
268 }
269 
270 
272 {
273  ASSERT(0).error("Not implemented yet.");
274 }
275 
277 {
278  ASSERT(0).error("Not implemented yet.");
279  return false;
280 }
281 
Classes for auxiliary output mesh.
static const unsigned int spacedim
Shortcut instead of spacedim template. We suppose only spacedim=3 at the moment.
Definition: output_mesh.hh:56
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:60
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:61
Common parent class for templated OutputData.
#define FOR_ELEMENT_NODES(i, j)
Definition: elements.h:188
Base class for Output mesh.
Definition: output_mesh.hh:49
GeneralIterator< OutputElement > OutputElementIterator
Definition: output_mesh.hh:37
Definition: nodes.hh:32
unsigned int n_elements()
Returns number of element.
Definition: output_mesh.cc:113
Mesh * orig_mesh_
Pointer to the computational mesh.
Definition: output_mesh.hh:98
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:56
#define FOR_ELEMENTS(_mesh_, __i)
Definition: mesh.h:405
Class for declaration of the input of type Bool.
Definition: type_base.hh:452
void select_error_control_field(FieldSet &output_fields)
Selects the error control field out of output field set according to input record.
Definition: output_mesh.cc:75
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:62
std::shared_ptr< MeshData< unsigned int > > connectivity_
Vector maps the nodes to their coordinates in vector nodes_.
Definition: output_mesh.hh:84
static const Input::Type::Record & get_input_type()
The specification of output mesh.
Definition: output_mesh.cc:26
const unsigned int max_level_
Maximal level of refinement.
Definition: output_mesh.hh:101
Definition: mesh.h:95
Iterator< Ret > find(const string &key) const
std::shared_ptr< MeshData< double > > nodes_
Vector of node coordinates. [spacedim x n_nodes].
Definition: output_mesh.hh:82
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
Class for declaration of the integral input data.
Definition: type_base.hh:483
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:301
unsigned int n_nodes()
Returns number of nodes.
Definition: output_mesh.cc:119
void create_refined_mesh()
Creates refined mesh.
Definition: output_mesh.cc:191
OutputMesh(Mesh &mesh)
Definition: output_mesh.cc:129
EI_Address ei_address() const
Definition: accessors.cc:178
static Default optional()
The factory function to make an empty default value which is optional.
Definition: type_record.hh:119
FieldCommon * field(const std::string &field_name) const
Definition: field_set.cc:132
unsigned int n_elements() const
Definition: mesh.h:133
Accessor to the data with type Type::Record.
Definition: accessors.hh:286
const Ret val(const string &key) const
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:488
bool refinement_criterion()
Definition: output_mesh.cc:197
int aux
Definition: nodes.hh:93
virtual ~OutputMeshBase()
Definition: output_mesh.cc:59
#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:223
OutputMeshDiscontinuous(Mesh &mesh)
Definition: output_mesh.cc:207
Input::Record input_record_
Input record for output mesh.
Definition: output_mesh.hh:95
std::shared_ptr< MeshData< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
Definition: output_mesh.hh:86
OutputElementIterator end()
Gives iterator to the LAST element of the output mesh.
Definition: output_mesh.cc:69
friend class OutputElement
Friend provides access to vectors for element accessor class.
Definition: output_mesh.hh:107
void create_refined_mesh()
Creates discontinuous refined mesh.
Definition: output_mesh.cc:271
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:336
Class OutputElement and its iterator OutputElementIterator on the output mesh.
#define ASSERT_DBG(expr)
Definition: asserts.hh:350
void create_identical_mesh()
Creates the output mesh identical to the computational one.
Definition: output_mesh.cc:145
unsigned int n_nodes() const
Definition: mesh.h:129
Record type proxy class.
Definition: type_record.hh:177
General iterator template. Provides iterator over objects in some container.
#define DebugOut()
Macro defining &#39;debug&#39; record of log.
Definition: logger.hh:240
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:45
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:79
OutputElementIterator begin()
Gives iterator to the FIRST element of the output mesh.
Definition: output_mesh.cc:63
Field< 3, FieldValue< 3 >::Scalar > * error_control_field_
Refinement error control field.
Definition: output_mesh.hh:104
OutputMeshBase(Mesh &mesh)
Constructor. Takes computational mesh as a parameter.
Definition: output_mesh.cc:37