Flow123d  JS_before_hm-1972-g3b0f4cd6d
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 mesh.cc
15  * @ingroup mesh
16  * @brief Mesh construction
17  */
18 
19 
20 #include <unistd.h>
21 #include <set>
22 #include <unordered_map>
23 
24 #include "system/system.hh"
25 #include "system/exceptions.hh"
26 #include "system/index_types.hh"
28 #include "input/input_type.hh"
29 #include "input/accessors.hh"
30 #include "system/sys_profiler.hh"
31 #include "la/distribution.hh"
32 
33 #include "mesh/mesh.h"
34 #include "mesh/bc_mesh.hh"
35 #include "mesh/ref_element.hh"
36 #include "mesh/region_set.hh"
37 #include "mesh/range_wrapper.hh"
38 
39 // think about following dependencies
40 #include "mesh/accessors.hh"
41 #include "mesh/node_accessor.hh"
42 #include "mesh/partitioning.hh"
43 #include "mesh/neighbours.h"
44 
45 
46 #include "mesh/bih_tree.hh"
47 #include "mesh/duplicate_nodes.h"
48 #include "mesh/mesh_optimizer.hh"
49 
51 
52 
53 
54 //TODO: sources, concentrations, initial condition and similarly boundary conditions should be
55 // instances of a Element valued field
56 // concentrations is in fact reimplemented in transport REMOVE it HERE
57 
58 // After removing non-geometrical things from mesh, this should be part of mash initializing.
59 #include "mesh/region.hh"
60 
61 #define NDEF -1
62 
63 namespace IT = Input::Type;
64 
66  return Input::Type::Selection("Types of search algorithm for finding intersection candidates.")
67  .add_value(Mesh::BIHsearch, "BIHsearch",
68  "Use BIH for finding initial candidates, then continue by prolongation.")
69  .add_value(Mesh::BIHonly, "BIHonly",
70  "Use BIH for finding all candidates.")
71  .add_value(Mesh::BBsearch, "BBsearch",
72  "Use bounding boxes for finding initial candidates, then continue by prolongation.")
73  .close();
74 }
75 
77  return IT::Record("Mesh","Record with mesh related data." )
78  .allow_auto_conversion("mesh_file")
80  "Input file with mesh description.")
82  "List of additional region and region set definitions not contained in the mesh. "
83  "There are three region sets implicitly defined:\n\n"
84  "- ALL (all regions of the mesh)\n"
85  "- .BOUNDARY (all boundary regions)\n"
86  "- BULK (all bulk regions)")
87  .declare_key("partitioning", Partitioning::get_input_type(), IT::Default("\"any_neighboring\""), "Parameters of mesh partitioning algorithms.\n" )
88  .declare_key("print_regions", IT::Bool(), IT::Default("true"), "If true, print table of all used regions.")
89  .declare_key("intersection_search", Mesh::get_input_intersection_variant(),
90  IT::Default("\"BIHsearch\""), "Search algorithm for element intersections.")
91  .declare_key("global_snap_radius", IT::Double(0.0), IT::Default("1E-3"),
92  "Maximal snapping distance from the mesh in various search operations. In particular, it is used "
93  "to find the closest mesh element of an observe point; and in FieldFormula to find closest surface "
94  "element in plan view (Z projection).")
96  "Output file with neighboring data from mesh.")
97  .declare_key("optimize_mesh", IT::Bool(), IT::Default("true"), "If true, permute nodes and elements in order to increase cache locality. "
98  "This will speed up the calculations. GMSH output preserves original ordering but is slower. All variants of VTK output use the permuted.")
99  .close();
100 }
101 
103 : tree(nullptr),
104  comm_(MPI_COMM_WORLD),
105  bulk_size_(0),
106  nodes_(3, 1, 0),
107  row_4_el(nullptr),
108  el_4_loc(nullptr),
109  el_ds(nullptr),
110  node_4_loc_(nullptr),
111  node_ds_(nullptr),
112  bc_mesh_(nullptr)
113 
114 {init();}
115 
116 
117 
119 : tree(nullptr),
120  optimize_memory_locality(true),
121  in_record_(in_record),
122  comm_(com),
123  bulk_size_(0),
124  nodes_(3, 1, 0),
125  row_4_el(nullptr),
126  el_4_loc(nullptr),
127  el_ds(nullptr),
128  node_4_loc_(nullptr),
129  node_ds_(nullptr),
130  bc_mesh_(nullptr)
131 {
132 
133  init();
134 }
135 
136 
138  : tree(nullptr),
139  optimize_memory_locality(other.optimize_memory_locality),
140  in_record_(other.in_record_),
141  comm_(other.comm_),
142  bulk_size_(0),
143  nodes_(3, 1, 0),
144  row_4_el(nullptr),
145  el_4_loc(nullptr),
146  el_ds(nullptr),
147  node_4_loc_(nullptr),
148  node_ds_(nullptr),
149  bc_mesh_(nullptr)
150 {
151  init();
152 }
153 
154 
155 
157 {
158  return in_record_.val<Mesh::IntersectionSearch>("intersection_search");
159 }
160 
161 
163 {
164  // set in_record_, if input accessor is empty
165  if (in_record_.is_empty()) {
166  istringstream is("{mesh_file=\"\", optimize_mesh=false}");
167  Input::ReaderToStorage reader;
168  IT::Record &in_rec = const_cast<IT::Record &>(Mesh::get_input_type());
169  in_rec.finish();
170  reader.read_stream(is, in_rec, Input::FileFormat::format_JSON);
172  }
173 
174  optimize_memory_locality = in_record_.val<bool>("optimize_mesh");
175 
176  n_insides = NDEF;
177  n_exsides = NDEF;
178  n_sides_ = NDEF;
179 
180  for (int d=0; d<3; d++) max_edge_sides_[d] = 0;
181 
182  // Initialize numbering of nodes on sides.
183  // This is temporary solution, until class Element is templated
184  // by dimension. Then we can replace Mesh::side_nodes by
185  // RefElement<dim>::side_nodes.
186 
187  // indices of side nodes in element node array
188  // Currently this is made ad libitum
189  // with some ordering here we can get sides with correct orientation.
190  // This speedup normal calculation.
191 
192  side_nodes.resize(3); // three side dimensions
193  for(int dim=0; dim < 3; dim++) {
194  side_nodes[dim].resize(dim+2); // number of sides
195  for(int i_side=0; i_side < dim+2; i_side++)
196  side_nodes[dim][i_side].resize(dim+1);
197  }
198 
199  for (unsigned int sid=0; sid<RefElement<1>::n_sides; sid++)
200  for (unsigned int nid=0; nid<RefElement<1>::n_nodes_per_side; nid++)
201  side_nodes[0][sid][nid] = RefElement<1>::interact(Interaction<0,0>(sid))[nid];
202 
203  for (unsigned int sid=0; sid<RefElement<2>::n_sides; sid++)
204  for (unsigned int nid=0; nid<RefElement<2>::n_nodes_per_side; nid++)
205  side_nodes[1][sid][nid] = RefElement<2>::interact(Interaction<0,1>(sid))[nid];
206 
207  for (unsigned int sid=0; sid<RefElement<3>::n_sides; sid++)
208  for (unsigned int nid=0; nid<RefElement<3>::n_nodes_per_side; nid++)
209  side_nodes[2][sid][nid] = RefElement<3>::interact(Interaction<0,2>(sid))[nid];
210 }
211 
212 
214  for(EdgeData &edg : this->edges)
215  if (edg.side_) delete[] edg.side_;
216 
217  for (unsigned int idx=0; idx < bulk_size_; idx++) {
218  Element *ele=&(element_vec_[idx]);
219  if (ele->boundary_idx_) delete[] ele->boundary_idx_;
220  if (ele->neigh_vb) delete[] ele->neigh_vb;
221  }
222 
223  for(unsigned int idx=bulk_size_; idx < element_vec_.size(); idx++) {
224  Element *ele=&(element_vec_[idx]);
225  if (ele->boundary_idx_) delete[] ele->boundary_idx_;
226  }
227 
228  if (row_4_el != nullptr) delete[] row_4_el;
229  if (el_4_loc != nullptr) delete[] el_4_loc;
230  if (el_ds != nullptr) delete el_ds;
231  if (node_4_loc_ != nullptr) delete[] node_4_loc_;
232  if (node_ds_ != nullptr) delete node_ds_;
233  if (bc_mesh_ != nullptr) delete bc_mesh_;
234  if (tree != nullptr) delete tree;
235 }
236 
237 
238 unsigned int Mesh::n_sides() const
239 {
240  if (n_sides_ == NDEF) {
241  n_sides_=0;
242  for (auto ele : this->elements_range()) n_sides_ += ele->n_sides();
243  }
244  return n_sides_;
245 }
246 
247 unsigned int Mesh::n_vb_neighbours() const {
248  return vb_neighbours_.size();
249  }
250 
251 
252 unsigned int Mesh::n_corners() {
253  unsigned int li, count = 0;
254  for (auto ele : this->elements_range()) {
255  for (li=0; li<ele->n_nodes(); li++) {
256  count++;
257  }
258  }
259  return count;
260 }
261 
262 Edge Mesh::edge(uint edge_idx) const
263 {
264  ASSERT_LT_DBG(edge_idx, edges.size());
265  return Edge(this, edge_idx);
266 }
267 
269 {
270  ASSERT_LT_DBG(bc_idx, boundary_.size());
271  return Boundary(&boundary_[bc_idx]);
272 }
273 
275  return part_.get();
276 }
277 
279  return (LongIdx*)this->get_part()->get_loc_part();
280 }
281 
282 
283 
284 
286 
287  // get dim of the first element in the map, if it exists
288  uint dim_to_check = RegionDB::undefined_dim;
289  std::string reg_name = "UndefinedRegion";
290  if(map.size() > 0){
291  Element &ele = element_vec_[ elem_index(map.begin()->first) ];
292  dim_to_check = ele.dim();
293  reg_name = region_db_.find_id(map.begin()->second).label();
294  }
295 
296  for (auto elem_to_region : map) {
297  Element &ele = element_vec_[ elem_index(elem_to_region.first) ];
298 
299  if( ele.dim() != dim_to_check){
300  THROW(ExcRegionElmDiffDim() << EI_Region(reg_name) << EI_RegIdx(elem_to_region.second) << EI_Dim(dim_to_check)
301  << EI_DimOther(ele.dim()) << EI_ElemId(elem_to_region.first) );
302  }
303 
304  ele.region_idx_ = region_db_.get_region( elem_to_region.second, ele.dim() );
306  }
307 }
308 
309 
311  std::vector<uint> nodes_new_idx( this->n_nodes(), undef_idx );
312 
313  // check element quality and flag used nodes
314  for (auto ele : this->elements_range()) {
315  // element quality
316  double quality = ele.quality_measure_smooth();
317  if (quality < 0) {
318  ASSERT_LT_DBG(ele.jacobian_S3(), 0);
319  element_vec_[ele.mesh_idx()].inverted = true;
320  quality = -quality;
321  }
322  if (quality < 4*std::numeric_limits<double>::epsilon())
323  THROW( ExcBadElement() << EI_Quality(quality) << EI_ElemId(ele.idx()) );
324  if ( quality< 0.001)
325  WarningOut().fmt("Bad quality element ID={}, ({}<0.001).\n", ele.idx(), quality);
326 
327  // flag used nodes
328  for (uint ele_node=0; ele_node<ele->n_nodes(); ele_node++) {
329  uint inode = ele->node_idx(ele_node);
330  nodes_new_idx[inode] = inode;
331  }
332  }
333 
334  // possibly build new node ids map
335  BidirectionalMap<int> new_node_ids_;
336  new_node_ids_.reserve(node_ids_.size());
337 
338  // remove unused nodes from the mesh
339  uint inode_new = 0;
340  for(uint inode = 0; inode < nodes_new_idx.size(); inode++) {
341  if(nodes_new_idx[inode] == undef_idx){
342  WarningOut().fmt("A node {} does not belong to any element "
343  " and will be removed.",
344  find_node_id(inode));
345  }
346  else{
347  // map new node numbering
348  nodes_new_idx[inode] = inode_new;
349 
350  // possibly move the nodes
351  nodes_.vec<3>(inode_new) = nodes_.vec<3>(inode);
352  new_node_ids_.add_item(node_ids_[inode]);
353 
354  inode_new++;
355  }
356  }
357 
358  uint n_nodes_new = inode_new;
359 
360  // if some node erased, update node ids in elements
361  if(n_nodes_new < nodes_new_idx.size()){
362 
363  DebugOut() << "Updating node-element numbering due to unused nodes: "
364  << print_var(n_nodes_new) << print_var(nodes_new_idx.size()) << "\n";
365 
366  // throw away unused nodes
367  nodes_.resize(n_nodes_new);
368  node_ids_ = new_node_ids_;
369 
370  // update node-element numbering
371  for (auto ele : this->elements_range()) {
372  for (uint ele_node=0; ele_node<ele->n_nodes(); ele_node++) {
373  uint inode_orig = ele->node_idx(ele_node);
374  uint inode = nodes_new_idx[inode_orig];
375  ASSERT_DBG(inode != undef_idx);
376  const_cast<Element*>(ele.element())->nodes_[ele_node] = inode;
377  }
378  }
379  }
380 }
381 
382 
383 //void Mesh::array_sort(std::array<uint, 4> &nodes) {
384 // // TODO: use templated insert sort with recursion over length of array so that compiler can
385 // // optimize for the small array size.
386 //
387 // std::sort(nodes.begin(), nodes.end());
388 //}
389 
390 std::array<std::pair<uint,uint>, 6> _comparisons = { {{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}} };
391 
392 
394  // Fill mappings from canonical element nodes to original
395  // for individual permitations.
396  // Permutations are numbered by the bifield of all six _comparisons.
397  element_nodes_original_[0] = {0,1,2,3};
398  element_nodes_original_[1] = {0,1,3,2};
399  element_nodes_original_[4] = {0,2,1,3};
400  element_nodes_original_[6] = {0,2,3,1};
401  element_nodes_original_[3] = {0,3,1,2};
402  element_nodes_original_[7] = {0,3,2,1};
403  element_nodes_original_[32] = {1,0,2,3};
404  element_nodes_original_[33] = {1,0,3,2};
405  element_nodes_original_[48] = {1,2,0,3};
406  element_nodes_original_[56] = {1,2,3,0};
407  element_nodes_original_[41] = {1,3,0,2};
408  element_nodes_original_[57] = {1,3,2,0};
409  element_nodes_original_[20] = {2,0,1,3};
410  element_nodes_original_[22] = {2,0,3,1};
411  element_nodes_original_[52] = {2,1,0,3};
412  element_nodes_original_[60] = {2,1,3,0};
413  element_nodes_original_[30] = {2,3,0,1};
414  element_nodes_original_[62] = {2,3,1,0};
415  element_nodes_original_[11] = {3,0,1,2};
416  element_nodes_original_[15] = {3,0,2,1};
417  element_nodes_original_[43] = {3,1,0,2};
418  element_nodes_original_[59] = {3,1,2,0};
419  element_nodes_original_[31] = {3,2,0,1};
420  element_nodes_original_[63] = {3,2,1,0};
421 
422 
423  // element_vec_ still contains both bulk and boundary elements
424  for (uint i_el=0; i_el < element_vec_.size(); i_el++) {
425  Element &ele = element_vec_[i_el];
426  uint cmp_bits = 0;
427  for(uint i=0; i<6; i++) {
428  cmp_bits <<=1;
429  cmp_bits += (ele.nodes_[_comparisons[i].first] > ele.nodes_[_comparisons[i].second]);
430  }
431  ele.permutation_ = cmp_bits;
432  std::sort(ele.nodes_.begin(), ele.nodes_.end());
433  }
434 
435 }
436 
439  START_TIMER("MESH - optimizer");
440  this->optimize();
441  END_TIMER("MESH - optimizer");
442  }
443 
444  START_TIMER("MESH - setup topology");
445 
446  canonical_faces();
448 
449 
453 
454  tree = new DuplicateNodes(this);
455 
456  part_ = std::make_shared<Partitioning>(this, in_record_.val<Input::Record>("partitioning") );
457 
458  // create parallel distribution and numbering of elements
459  LongIdx *id_4_old = new LongIdx[n_elements()];
460  int i = 0;
461  for (auto ele : this->elements_range())
462  id_4_old[i++] = ele.idx();
463  part_->id_maps(n_elements(), id_4_old, el_ds, el_4_loc, row_4_el);
464 
465  delete[] id_4_old;
466 
467  this->distribute_nodes();
468 
470 }
471 
472 
474  MeshOptimizer<3> mo(this);
475  mo.calculate_sizes();
478 
479  this->sort_permuted_nodes_elements( mo.sort_nodes(this->node_permutation_), mo.sort_elements(this->elem_permutation_) );
480 }
481 
482 
484  BidirectionalMap<int> node_ids_backup = this->node_ids_;
485  this->node_ids_.clear();
486  this->node_ids_.reserve(this->n_nodes());
487  Armor::Array<double> nodes_backup = this->nodes_;
488  for (uint i = 0; i < this->element_vec_.size(); ++i) {
489  for (uint j = 0; j < this->element_vec_[i].dim() + 1; ++j) {
490  this->element_vec_[i].nodes_[j] = this->node_permutation_[this->element_vec_[i].nodes_[j]];
491  }
492  }
493  for (uint i = 0; i < this->n_nodes(); ++i) {
494  this->nodes_.set(node_permutation_[i]) = nodes_backup.vec<3>(i);
495  this->node_ids_.add_item( node_ids_backup[new_node_ids[i]] );
496  }
497 
498  BidirectionalMap<int> elem_ids_backup = this->element_ids_;
499  this->element_ids_.clear();
501  std::vector<Element> elements_backup = this->element_vec_;
502  for (uint i = 0; i < bulk_size_; ++i) {
503  this->element_vec_[elem_permutation_[i]] = elements_backup[i];
504  this->element_ids_.add_item( elem_ids_backup[new_elem_ids[i]] );
505  }
506 }
507 
508 
509 //
511 {
512 
513  n_insides = 0;
514  n_exsides = 0;
515  for (auto ele : this->elements_range()) {
516  for(SideIter sde = ele.side(0); sde->side_idx() < ele->n_sides(); ++sde) {
517  if (sde->is_external()) n_exsides++;
518  else n_insides++;
519  }
520  }
521 }
522 
523 
524 
526  // for each node we make a list of elements that use this node
527  node_elements_.resize( this->n_nodes() );
528 
529  for (auto ele : this->elements_range())
530  for (unsigned int n=0; n<ele->n_nodes(); n++)
531  node_elements_[ele.node(n).idx()].push_back(ele.idx());
532 
533  for (vector<vector<unsigned int> >::iterator n=node_elements_.begin(); n!=node_elements_.end(); n++)
534  stable_sort(n->begin(), n->end());
535 }
536 
537 
538 void Mesh::intersect_element_lists(vector<unsigned int> const &nodes_list, vector<unsigned int> &intersection_element_list)
539 {
540  if (node_elements_.size() == 0) {
542  }
543 
544  if (nodes_list.size() == 0) {
545  intersection_element_list.clear();
546  } else if (nodes_list.size() == 1) {
547  intersection_element_list = node_elements_[ nodes_list[0] ];
548  } else {
549  vector<unsigned int>::const_iterator it1=nodes_list.begin();
551  intersection_element_list.resize( node_elements_[*it1].size() ); // make enough space
552 
553  it1=set_intersection(
554  node_elements_[*it1].begin(), node_elements_[*it1].end(),
555  node_elements_[*it2].begin(), node_elements_[*it2].end(),
556  intersection_element_list.begin());
557  intersection_element_list.resize(it1-intersection_element_list.begin()); // resize to true size
558 
559  for(;it2<nodes_list.end();++it2) {
560  it1=set_intersection(
561  intersection_element_list.begin(), intersection_element_list.end(),
562  node_elements_[*it2].begin(), node_elements_[*it2].end(),
563  intersection_element_list.begin());
564  intersection_element_list.resize(it1-intersection_element_list.begin()); // resize to true size
565  }
566  }
567 }
568 
569 
570 bool Mesh::find_lower_dim_element( vector<unsigned int> &element_list, unsigned int dim, unsigned int &element_idx) {
571  bool is_neighbour = false;
572 
573  vector<unsigned int>::iterator e_dest=element_list.begin();
574  for( vector<unsigned int>::iterator ele = element_list.begin(); ele!=element_list.end(); ++ele) {
575  //DebugOut() << "Eid: " << this->elem_index(*ele)
576  // << format(element_vec_[*ele].nodes_);
577 
578  if (element_vec_[*ele].dim() == dim) { // keep only indexes of elements of same dimension
579  *e_dest=*ele;
580  ++e_dest;
581  } else if (element_vec_[*ele].dim() == dim-1) { // get only first element of lower dimension
582  if (is_neighbour) THROW(ExcTooMatchingIds() << EI_ElemId(this->elem_index(*ele)) << EI_ElemIdOther(this->elem_index(element_idx)) );
583 
584  is_neighbour = true;
585  element_idx = *ele;
586  }
587  }
588  element_list.resize( e_dest - element_list.begin());
589  return is_neighbour;
590 }
591 
592 bool Mesh::same_sides(const SideIter &si, vector<unsigned int> &side_nodes) {
593  // check if nodes lists match (this is slow and will be faster only when we convert whole mesh into hierarchical design like in deal.ii)
594  unsigned int ni=0;
595  while ( ni < si->n_nodes()
596  && find(side_nodes.begin(), side_nodes.end(), si->node(ni).idx() ) != side_nodes.end() ) ni++;
597  return ( ni == si->n_nodes() );
598 }
599 
600 /**
601  * TODO:
602  * - use std::is_any for setting is_neigbour
603  * - possibly make appropriate constructors for Edge and Neighbour
604  * - check side!=-1 when searching neigbouring element
605  * - process boundary elements first, there should be no Neigh, but check it
606  * set Edge and boundary there
607  */
608 
610 {
611  ASSERT(bc_element_tmp_.size()==0)
612  .error("Temporary structure of boundary element data is not empty. Did you call create_boundary_elements?");
613 
614  Neighbour neighbour;
615  EdgeData *edg = nullptr;
616  unsigned int ngh_element_idx;
617  unsigned int last_edge_idx = undef_idx;
618 
619  neighbour.mesh_ = this;
620 
622 
623  // pointers to created edges
624  //vector<Edge *> tmp_edges;
625  edges.resize(0); // be sure that edges are empty
626 
628  vector<unsigned int> intersection_list; // list of elements in intersection of node element lists
629 
630  for( unsigned int i=bulk_size_; i<element_vec_.size(); ++i) {
631 
632  ElementAccessor<3> bc_ele = this->element_accessor(i);
633  ASSERT(bc_ele.region().is_boundary());
634  // Find all elements that share this side.
635  side_nodes.resize(bc_ele->n_nodes());
636  for (unsigned n=0; n<bc_ele->n_nodes(); n++) side_nodes[n] = bc_ele->node_idx(n);
637  intersect_element_lists(side_nodes, intersection_list);
638  bool is_neighbour = find_lower_dim_element(intersection_list, bc_ele->dim() +1, ngh_element_idx);
639  if (is_neighbour) {
640  THROW( ExcBdrElemMatchRegular() << EI_ElemId(bc_ele.idx()) << EI_ElemIdOther(this->elem_index(ngh_element_idx)) );
641  } else {
642  if (intersection_list.size() == 0) {
643  // no matching dim+1 element found
644  WarningOut().fmt("Lonely boundary element, id: {}, region: {}, dimension {}.\n",
645  bc_ele.idx(), bc_ele.region().id(), bc_ele->dim());
646  continue; // skip the boundary element
647  }
648  last_edge_idx=edges.size();
649  edges.resize(last_edge_idx+1);
650  edg = &( edges.back() );
651  edg->n_sides = 0;
652  edg->side_ = new struct SideIter[ intersection_list.size() ];
653 
654  // common boundary object
655  unsigned int bdr_idx=boundary_.size();
656  boundary_.resize(bdr_idx+1);
657  BoundaryData &bdr=boundary_.back();
658  bdr.bc_ele_idx_ = i;
659  bdr.edge_idx_ = last_edge_idx;
660  bdr.mesh_=this;
661 
662  // for 1d boundaries there can be more then one 1d elements connected to the boundary element
663  // we do not detect this case later in the main search over bulk elements
664  for( vector<unsigned int>::iterator isect = intersection_list.begin(); isect!=intersection_list.end(); ++isect) {
665  ElementAccessor<3> elem = this->element_accessor(*isect);
666  for (unsigned int ecs=0; ecs<elem->n_sides(); ecs++) {
667  SideIter si = elem.side(ecs);
668  if ( same_sides( si, side_nodes) ) {
669  if (elem->edge_idx(ecs) != undef_idx) {
670  OLD_ASSERT(elem->boundary_idx_!=nullptr, "Null boundary idx array.\n");
671  int last_bc_ele_idx=this->boundary_[elem->boundary_idx_[ecs]].bc_ele_idx_;
672  int new_bc_ele_idx=i;
673  THROW( ExcDuplicateBoundary()
674  << EI_ElemLast(this->find_elem_id(last_bc_ele_idx))
675  << EI_RegLast(this->element_accessor(last_bc_ele_idx).region().label())
676  << EI_ElemNew(this->find_elem_id(new_bc_ele_idx))
677  << EI_RegNew(this->element_accessor(new_bc_ele_idx).region().label())
678  );
679  }
680  element_vec_[*isect].edge_idx_[ecs] = last_edge_idx;
681  edg->side_[ edg->n_sides++ ] = si;
682 
683  if (elem->boundary_idx_ == NULL) {
684  Element *el = &(element_vec_[*isect]);
685  el->boundary_idx_ = new unsigned int [ el->n_sides() ];
686  std::fill( el->boundary_idx_, el->boundary_idx_ + el->n_sides(), undef_idx);
687  }
688  elem->boundary_idx_[ecs] = bdr_idx;
689  break; // next element in intersection list
690  }
691  }
692  }
693 
694  }
695 
696  }
697  // Now we go through all element sides and create edges and neighbours
698  unsigned int new_bc_elem_idx = element_vec_.size(); //Mesh_idx of new boundary element generated in following block
699  for (auto e : this->elements_range()) {
700  for (unsigned int s=0; s<e->n_sides(); s++)
701  {
702  // skip sides that were already found
703  if (e->edge_idx(s) != undef_idx) continue;
704 
705 
706  // Find all elements that share this side.
707  side_nodes.resize(e.side(s)->n_nodes());
708  for (unsigned n=0; n<e.side(s)->n_nodes(); n++) side_nodes[n] = e.side(s)->node(n).idx();
709  intersect_element_lists(side_nodes, intersection_list);
710 
711  bool is_neighbour = find_lower_dim_element(intersection_list, e->dim(), ngh_element_idx);
712 
713  if (is_neighbour) { // edge connects elements of different dimensions
714  // Initialize for the neighbour case.
715  neighbour.elem_idx_ = ngh_element_idx;
716  } else { // edge connects only elements of the same dimension
717  // Initialize for the edge case.
718  last_edge_idx=edges.size();
719  edges.resize(last_edge_idx+1);
720  edg = &( edges.back() );
721  edg->n_sides = 0;
722  edg->side_ = new struct SideIter[ intersection_list.size() ];
723  if (intersection_list.size() > max_edge_sides_[e->dim()-1])
724  max_edge_sides_[e->dim()-1] = intersection_list.size();
725 
726  if (intersection_list.size() == 1) {
727  // outer edge, create boundary object as well
728  Element &elm = element_vec_[e.idx()];
729  edg->n_sides=1;
730  edg->side_[0] = e.side(s);
731  element_vec_[e.idx()].edge_idx_[s] = last_edge_idx;
732 
733  if (e->boundary_idx_ == NULL) {
734  elm.boundary_idx_ = new unsigned int [ e->n_sides() ];
735  std::fill( elm.boundary_idx_, elm.boundary_idx_ + e->n_sides(), undef_idx);
736  }
737 
738  unsigned int bdr_idx=boundary_.size()+1; // need for VTK mesh that has no boundary elements
739  // and bulk elements are indexed from 0
740  boundary_.resize(bdr_idx+1);
741  BoundaryData &bdr=boundary_.back();
742  elm.boundary_idx_[s] = bdr_idx;
743 
744  // fill boundary element
745  Element * bc_ele = add_element_to_vector(-bdr_idx);
746  bc_ele->init(e->dim()-1, region_db_.implicit_boundary_region() );
748  for(unsigned int ni = 0; ni< side_nodes.size(); ni++) bc_ele->nodes_[ni] = side_nodes[ni];
749 
750  // fill Boundary object
751  bdr.edge_idx_ = last_edge_idx;
752  bdr.bc_ele_idx_ = new_bc_elem_idx; //elem_index(-bdr_idx);
753  bdr.mesh_=this;
754  new_bc_elem_idx++;
755 
756  continue; // next side of element e
757  }
758  }
759 
760  // go through the elements connected to the edge or neighbour
761  // setup neigbour or edge
762  for( vector<unsigned int>::iterator isect = intersection_list.begin(); isect!=intersection_list.end(); ++isect) {
763  ElementAccessor<3> elem = this->element_accessor(*isect);
764  for (unsigned int ecs=0; ecs<elem->n_sides(); ecs++) {
765  if (elem->edge_idx(ecs) != undef_idx) continue; // ??? This should not happen.
766  SideIter si = elem.side(ecs);
767  if ( same_sides( si, side_nodes) ) {
768  if (is_neighbour) {
769  // create a new edge and neighbour for this side, and element to the edge
770  last_edge_idx=edges.size();
771  edges.resize(last_edge_idx+1);
772  edg = &( edges.back() );
773  edg->n_sides = 1;
774  edg->side_ = new struct SideIter[1];
775  edg->side_[0] = si;
776  element_vec_[elem.idx()].edge_idx_[ecs] = last_edge_idx;
777 
778  neighbour.edge_idx_ = last_edge_idx;
779 
780  vb_neighbours_.push_back(neighbour); // copy neighbour with this edge setting
781  } else {
782  // connect the side to the edge, and side to the edge
783  ASSERT_PTR_DBG(edg);
784  edg->side_[ edg->n_sides++ ] = si;
785  ASSERT_DBG(last_edge_idx != undef_idx);
786  element_vec_[elem.idx()].edge_idx_[ecs] = last_edge_idx;
787  }
788  break; // next element from intersection list
789  }
790  } // search for side of other connected element
791  } // connected elements
792 
793  if (! is_neighbour)
794  ASSERT_EQ( (unsigned int) edg->n_sides, intersection_list.size())(e.index())(s).error("Missing edge sides.");
795  } // for element sides
796  } // for elements
797 
798  MessageOut().fmt( "Created {} edges and {} neighbours.\n", edges.size(), vb_neighbours_.size() );
799 }
800 
801 
802 
803 //=============================================================================
804 //
805 //=============================================================================
807 {
808 
809  //MessageOut() << "Element to neighbours of vb2 type... "/*orig verb 5*/;
810 
811  for (vector<Element>::iterator ele = element_vec_.begin(); ele!= element_vec_.begin()+bulk_size_; ++ele)
812  ele->n_neighs_vb_ =0;
813 
814  // count vb neighs per element
815  for (auto & ngh : this->vb_neighbours_) ngh.element()->n_neighs_vb_++;
816 
817  // Allocation of the array per element
818  for (vector<Element>::iterator ele = element_vec_.begin(); ele!= element_vec_.begin()+bulk_size_; ++ele)
819  if( ele->n_neighs_vb() > 0 ) {
820  ele->neigh_vb = new struct Neighbour* [ele->n_neighs_vb()];
821  ele->n_neighs_vb_=0;
822  }
823 
824  // fill
825  ElementAccessor<3> ele;
826  for (auto & ngh : this->vb_neighbours_) {
827  ele = ngh.element();
828  ele->neigh_vb[ ele->n_neighs_vb_++ ] = &ngh;
829  }
830 
831  //MessageOut() << "... O.K.\n"/*orig verb 6*/;
832 }
833 
834 
835 
836 
837 
838 
840  /* Algorithm:
841  *
842  * 1) create BIH tree
843  * 2) for every 1D, find list of candidates
844  * 3) compute intersections for 1d, store it to master_elements
845  *
846  */
847  if (! intersections) {
848  intersections = std::make_shared<MixedMeshIntersections>(this);
849  intersections->compute_intersections();
850  }
851  return *intersections;
852 }
853 
854 
855 
857  return ElementAccessor<3>(this, idx);
858 }
859 
860 
861 
862 NodeAccessor<3> Mesh::node(unsigned int idx) const {
863  return NodeAccessor<3>(this, idx);
864 }
865 
866 
867 
868 void Mesh::elements_id_maps( vector<LongIdx> & bulk_elements_id, vector<LongIdx> & boundary_elements_id) const
869 {
870  if (bulk_elements_id.size() ==0) {
872  LongIdx last_id;
873 
874  bulk_elements_id.resize(n_elements());
875  map_it = bulk_elements_id.begin();
876  last_id = -1;
877  for(unsigned int idx=0; idx < n_elements(); idx++, ++map_it) {
878  LongIdx id = this->find_elem_id(idx);
879  last_id=*map_it = id;
880  }
881  std::sort(bulk_elements_id.begin(), bulk_elements_id.end());
882 
883  boundary_elements_id.resize(element_ids_.size()-bulk_size_);
884  map_it = boundary_elements_id.begin();
885  last_id = -1;
886  for(unsigned int idx=bulk_size_; idx<element_ids_.size(); idx++, ++map_it) {
887  LongIdx id = this->find_elem_id(idx);
888  // We set ID for boundary elements created by the mesh itself to "-1"
889  // this force gmsh reader to skip all remaining entries in boundary_elements_id
890  // and thus report error for any remaining data lines
891  if (id < 0) last_id=*map_it=-1;
892  else {
893  if (last_id >= id) THROW( ExcElmWrongOrder() << EI_ElemId(id) );
894  last_id=*map_it = id;
895  }
896  }
897  }
898 }
899 
900 
901 bool compare_points(const arma::vec3 &p1, const arma::vec3 &p2) {
902  static const double point_tolerance = 1E-10;
903  return fabs(p1[0]-p2[0]) < point_tolerance
904  && fabs(p1[1]-p2[1]) < point_tolerance
905  && fabs(p1[2]-p2[2]) < point_tolerance;
906 }
907 
908 
909 std::shared_ptr<EquivalentMeshMap> Mesh::check_compatible_mesh(Mesh & input_mesh)
910 {
911  // Assumptions:
912  // - target (computational) mesh is continous
913  // - source mesh can be both continous (unique nodes) and discontinous (duplicit nodes)
914  // - at least one compatible element must be found (each mesh can be only subdomain of the other one)
915 
916  std::vector<unsigned int> node_ids; // indices map: nodes from source mesh to nodes of target mesh
917  std::shared_ptr<EquivalentMeshMap> map_ptr =
918  std::make_shared<EquivalentMeshMap>(n_elements(), get_bc_mesh()->n_elements(), (LongIdx)undef_idx);
919  // indices map: nodes from source mesh to nodes of target mesh
920 
921  {
922  // create map `node_ids` from node indices of source mesh to node indices of target mesh
923  // - to each node of source mesh there must be one node in target mesh at maximum
924  // - to each node of target mesh there can be more than one node in source mesh
925  // - iterate over nodes of source mesh, use BIH tree of target mesh to find candidate nodes
926  // - check equality of nodes by their L1 distance with tolerance
927  std::vector<unsigned int> searched_elements; // for BIH tree
928  unsigned int i_node, i_elm_node;
929  const BIHTree &bih_tree=this->get_bih_tree();
930 
931  // create nodes of mesh
932  node_ids.resize( input_mesh.n_nodes(), undef_idx );
933  for (auto nod : input_mesh.node_range()) {
934  uint found_i_node = undef_idx;
935  bih_tree.find_point(*nod, searched_elements);
936 
937  for (std::vector<unsigned int>::iterator it = searched_elements.begin(); it!=searched_elements.end(); it++) {
938  ElementAccessor<3> ele = this->element_accessor( *it );
939  for (i_node=0; i_node<ele->n_nodes(); i_node++)
940  {
941  static const double point_tolerance = 1E-10;
942  if ( arma::norm(*ele.node(i_node) - *nod, 1) < point_tolerance) {
943  i_elm_node = ele.node(i_node).idx();
944  if (found_i_node == undef_idx)
945  found_i_node = i_elm_node;
946  else if (found_i_node != i_elm_node) {
947  // duplicate nodes in target mesh - not compatible
948  return std::make_shared<EquivalentMeshMap>();
949  }
950  }
951  }
952  }
953 
954  if (found_i_node!=undef_idx)
955  node_ids[nod.idx()] = found_i_node;
956 
957  searched_elements.clear();
958  }
959  }
960 
961  unsigned int n_found = 0; // number of found equivalent elements
962  // create map for bulk elements
963  n_found += check_compatible_elements(&input_mesh, this, node_ids, map_ptr->bulk);
964  // create map for boundary elements
965  n_found += check_compatible_elements(input_mesh.get_bc_mesh(), this->get_bc_mesh(), node_ids, map_ptr->boundary);
966 
967  // no equivalent element found => mesh is not compatible
968  if (n_found==0)
969  return std::make_shared<EquivalentMeshMap>();
970  else
971  return map_ptr;
972 }
973 
974 unsigned int Mesh::check_compatible_elements(Mesh* source_mesh, Mesh* target_mesh,
975  const std::vector<unsigned int>& node_ids,
977 {
978  // create map `element_ids_map` from ele indices of source mesh to ele indices of target mesh
979  // - iterate over elements of source mesh
980  // - get adjacent nodes of target mesh using `node_ids` map
981  // - find adjacent element of target mesh using the found nodes
982 
983  std::vector<unsigned int> result_list; // list of elements with same dimension as vtk element
984  std::vector<unsigned int> node_list; // auxiliary vector of node indices of a single element
985  std::vector<unsigned int> candidate_list; // auxiliary output vector for intersect_element_lists function
986  bool valid_nodes;
987 
988  unsigned int n_found = 0; // number of found equivalent elements
989 
990  for (auto elm : source_mesh->elements_range()) {
991  valid_nodes = true;
992  for (unsigned int j=0; j<elm->n_nodes(); j++) { // iterate trough all nodes of any element
993  if (node_ids[ elm->node_idx(j) ] == undef_idx)
994  valid_nodes = false;
995  node_list.push_back( node_ids[ elm->node_idx(j) ] );
996  }
997 
998  if (valid_nodes) {
999  target_mesh->intersect_element_lists(node_list, candidate_list);
1000  for (auto i_elm : candidate_list) {
1001  if ( target_mesh->element_accessor(i_elm)->dim() == elm.dim() )
1002  result_list.push_back(i_elm);
1003  }
1004  }
1005 
1006  if (result_list.size() == 1) {
1007  map[result_list[0]] = elm.idx();
1008  n_found++;
1009  }
1010 
1011  node_list.clear();
1012  result_list.clear();
1013  }
1014  return n_found;
1015 }
1016 
1017 
1019 {
1021  it != region_list.end();
1022  ++it) {
1023  // constructor has side effect in the mesh - create new region or set and store them to Mesh::region_db_
1024  (*it).factory< RegionSetBase, const Input::Record &, Mesh * >(*it, this);
1025  }
1026 }
1027 
1029 {
1031  region_db_.el_to_reg_map_.clear();
1032  region_db_.close();
1034 
1035  if ( in_record_.val<bool>("print_regions") ) {
1036  stringstream ss;
1038  MessageOut() << ss.str();
1039  }
1040 }
1041 
1042 
1044  START_TIMER("Mesh::compute_element_boxes");
1046 
1047  // make element boxes
1048  unsigned int i=0;
1049  boxes.resize(this->n_elements());
1050  for (auto element : this->elements_range()) {
1051  boxes[i] = element.bounding_box();
1052  i++;
1053  }
1054 
1055  return boxes;
1056 }
1057 
1059  if (! this->bih_tree_) {
1060  bih_tree_ = std::make_shared<BIHTree>();
1061  bih_tree_->add_boxes( this->get_element_boxes() );
1062  bih_tree_->construct();
1063  }
1064  return *bih_tree_;
1065 }
1066 
1068  return in_record_.val<double>("global_snap_radius");
1069 }
1070 
1071 void Mesh::add_physical_name(unsigned int dim, unsigned int id, std::string name) {
1072  region_db_.add_region(id, name, dim, "$PhysicalNames");
1073 }
1074 
1075 
1076 void Mesh::add_node(unsigned int node_id, arma::vec3 coords) {
1077 
1078  nodes_.append(coords);
1079  node_ids_.add_item(node_id);
1080  node_permutation_.push_back(node_permutation_.size());
1081 }
1082 
1083 
1084 void Mesh::add_element(unsigned int elm_id, unsigned int dim, unsigned int region_id, unsigned int partition_id,
1085  std::vector<unsigned int> node_ids) {
1086  RegionIdx region_idx = region_db_.get_region( region_id, dim );
1087  if ( !region_idx.is_valid() ) {
1088  region_idx = region_db_.add_region( region_id, region_db_.create_label_from_id(region_id), dim, "$Element" );
1089  }
1090  region_db_.mark_used_region(region_idx.idx());
1091 
1092  if (region_idx.is_boundary()) {
1093  bc_element_tmp_.push_back( ElementTmpData(elm_id, dim, region_idx, partition_id, node_ids) );
1094  } else {
1095  if(dim == 0 ) {
1096  WarningOut().fmt("Bulk elements of zero size(dim=0) are not supported. Element ID: {}.\n", elm_id);
1097  }
1098  else {
1099  Element *ele = add_element_to_vector(elm_id);
1100  bulk_size_++;
1101  this->init_element(ele, elm_id, dim, region_idx, partition_id, node_ids);
1102  }
1103  }
1104 }
1105 
1106 
1107 void Mesh::init_element(Element *ele, unsigned int elm_id, unsigned int dim, RegionIdx region_idx, unsigned int partition_id,
1108  std::vector<unsigned int> node_ids) {
1109  ele->init(dim, region_idx);
1110  ele->pid_ = partition_id;
1111 
1112  unsigned int ni=0;
1113  for (; ni<ele->n_nodes(); ni++) {
1114  ele->nodes_[ni] = this->node_index(node_ids[ni]);
1115  }
1116  for( ;ni < 4; ni++) ele->nodes_[ni] = undef_idx;
1117 
1118  // check that tetrahedron element is numbered correctly and is not degenerated
1119  if(ele->dim() == 3)
1120  {
1121  ElementAccessor<3> ea = this->element_accessor( this->elem_index(elm_id) );
1122  double jac = ea.jacobian_S3();
1123  if( ! (jac > 0) ) {
1124  WarningOut().fmt("Tetrahedron element with id {} has wrong numbering or is degenerated (Jacobian = {}).",elm_id, jac);
1125  }
1126  }
1127 }
1128 
1129 
1131  if (node_elements_.size() == 0) {
1132  this->create_node_element_lists();
1133  }
1134  return node_elements_;
1135 }
1136 
1137 
1138 void Mesh::init_element_vector(unsigned int size) {
1139  element_vec_.clear();
1140  element_ids_.clear();
1141  elem_permutation_.clear();
1142  element_vec_.reserve(size);
1143  element_ids_.reserve(size);
1144  elem_permutation_.reserve(size);
1145  bc_element_tmp_.clear();
1146  bc_element_tmp_.reserve(size);
1147  bulk_size_ = 0;
1149 }
1150 
1151 
1152 void Mesh::init_node_vector(unsigned int size) {
1153  nodes_.reinit(size);
1154  node_ids_.clear();
1155  node_ids_.reserve(size);
1156  node_permutation_.clear();
1157  node_permutation_.reserve(size);
1158 }
1159 
1160 
1162  element_vec_.push_back( Element() );
1163  Element * elem = &element_vec_.back(); //[element_vec_.size()-1];
1164  element_ids_.add_item((unsigned int)(id));
1165  elem_permutation_.push_back(elem_permutation_.size());
1166  return elem;
1167 }
1168 
1170  auto bgn_it = make_iter<ElementAccessor<3>>( ElementAccessor<3>(this, 0) );
1171  auto end_it = make_iter<ElementAccessor<3>>( ElementAccessor<3>(this, bulk_size_) );
1172  return Range<ElementAccessor<3>>(bgn_it, end_it);
1173 }
1174 
1176  auto bgn_it = make_iter<NodeAccessor<3>>( NodeAccessor<3>(this, 0) );
1177  auto end_it = make_iter<NodeAccessor<3>>( NodeAccessor<3>(this, n_nodes()) );
1178  return Range<NodeAccessor<3>>(bgn_it, end_it);
1179 }
1180 
1182  auto bgn_it = make_iter<Edge>( Edge(this, 0) );
1183  auto end_it = make_iter<Edge>( Edge(this, edges.size()) );
1184  return Range<Edge>(bgn_it, end_it);
1185 }
1186 
1187 inline void Mesh::check_element_size(unsigned int elem_idx) const
1188 {
1189  ASSERT(elem_idx < element_vec_.size())(elem_idx)(element_vec_.size()).error("Index of element is out of bound of element vector!");
1190 }
1191 
1192 /*
1193  * Output of internal flow data.
1194  */
1196 {
1197  START_TIMER("Mesh::output_internal_ngh_data");
1198 
1199  FilePath raw_output_file_path;
1200  if (! in_record_.opt_val("raw_ngh_output", raw_output_file_path)) return;
1201 
1202  ofstream raw_ngh_output_file;
1203  int rank;
1204  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1205  if (rank == 0) {
1206  MessageOut() << "Opening raw ngh output: " << raw_output_file_path << "\n";
1207  try {
1208  raw_output_file_path.open_stream(raw_ngh_output_file);
1209  } INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, (in_record_))
1210  }
1211 
1212  if (! raw_ngh_output_file.is_open()) return;
1213 
1214  // header
1215  raw_ngh_output_file << "// fields:\n//ele_id n_sides ns_side_neighbors[n] neighbors[n*ns] n_vb_neighbors vb_neighbors[n_vb]\n";
1216  raw_ngh_output_file << fmt::format("{}\n" , n_elements());
1217 
1218  int cit = 0;
1219 
1220  // map from higher dim elements to its lower dim neighbors, using gmsh IDs: ele->id()
1221  unsigned int undefined_ele_id = -1;
1223  for (auto ele : this->elements_range()) {
1224  if(ele->n_neighs_vb() > 0){
1225  for (unsigned int i = 0; i < ele->n_neighs_vb(); i++){
1226  ElementAccessor<3> higher_ele = ele->neigh_vb[i]->side()->element();
1227 
1228  auto search = neigh_vb_map.find(higher_ele.idx());
1229  if(search != neigh_vb_map.end()){
1230  // if found, add id to correct local side idx
1231  search->second[ele->neigh_vb[i]->side()->side_idx()] = ele.idx();
1232  }
1233  else{
1234  // if not found, create new vector, each side can have one vb neighbour
1235  std::vector<unsigned int> higher_ele_side_ngh(higher_ele->n_sides(), undefined_ele_id);
1236  higher_ele_side_ngh[ele->neigh_vb[i]->side()->side_idx()] = ele.idx();
1237  neigh_vb_map[higher_ele.idx()] = higher_ele_side_ngh;
1238  }
1239  }
1240  }
1241  }
1242 
1243  for (unsigned int i_elem=0; i_elem<n_elements(); ++i_elem)
1244  {
1245  auto ele = element_accessor(elem_permutation_[i_elem]);
1246  std::stringstream ss;
1247  ss << ele.index() << " ";
1248  ss << ele->n_sides() << " ";
1249 
1250  // use node permutation to permute sides
1251  auto &new_to_old_node = ele.orig_nodes_order();
1252  std::vector<uint> old_to_new_side(ele->n_sides());
1253  for (unsigned int i = 0; i < ele->n_sides(); i++) {
1254  // According to RefElement<dim>::opposite_node()
1255  uint new_opp_node = ele->n_sides() - i - 1;
1256  uint old_opp_node = new_to_old_node[new_opp_node];
1257  uint old_iside = ele->n_sides() - old_opp_node - 1;
1258  old_to_new_side[old_iside] = i;
1259  }
1260 
1261  auto search_neigh = neigh_vb_map.end();
1262  for (unsigned int i = 0; i < ele->n_sides(); i++) {
1263  uint new_iside = old_to_new_side[i];
1264 
1265  uint n_side_neighs = ele.side(new_iside)->edge().n_sides()-1; //n_sides - the current one
1266  // check vb neighbors (lower dimension)
1267  if(n_side_neighs == 0){
1268  //update search
1269  if(search_neigh == neigh_vb_map.end())
1270  search_neigh = neigh_vb_map.find(ele.idx());
1271 
1272  if(search_neigh != neigh_vb_map.end())
1273  if(search_neigh->second[new_iside] != undefined_ele_id)
1274  n_side_neighs = 1;
1275  }
1276  ss << n_side_neighs << " ";
1277  }
1278 
1279  for (unsigned int i = 0; i < ele->n_sides(); i++) {
1280  uint new_iside = old_to_new_side[i];
1281  Edge edge = ele.side(new_iside)->edge();
1282  if(edge.n_sides() > 1){
1283  for (uint j = 0; j < edge.n_sides(); j++) {
1284  if(edge.side(j) != ele.side(new_iside))
1285  ss << edge.side(j)->element().index() << " ";
1286  }
1287  }
1288  //check vb neighbour
1289  else if(search_neigh != neigh_vb_map.end()
1290  && search_neigh->second[new_iside] != undefined_ele_id){
1291  auto neigh_ele = element_accessor(search_neigh->second[new_iside]);
1292  ss << neigh_ele.index() << " ";
1293  }
1294  }
1295 
1296  // list higher dim neighbours
1297  ss << ele->n_neighs_vb() << " ";
1298  for (unsigned int i = 0; i < ele->n_neighs_vb(); i++)
1299  ss << ele->neigh_vb[i]->side()->element().index() << " ";
1300 
1301  // remove last white space
1302  string line = ss.str();
1303  raw_ngh_output_file << line.substr(0, line.size()-1) << endl;
1304  cit ++;
1305  }
1306  raw_ngh_output_file << "$EndFlowField\n" << endl;
1307 }
1308 
1309 
1311  // Copy boundary elements in temporary storage to the second part of the element vector
1312  for(ElementTmpData &e_data : bc_element_tmp_) {
1313  Element *ele = add_element_to_vector(e_data.elm_id);
1314  this->init_element(ele, e_data.elm_id, e_data.dim, e_data.region_idx,
1315  e_data.partition_id, e_data.node_ids);
1316  }
1317  // release memory
1318  unsigned int bdr_size = bc_element_tmp_.size();
1320  return bdr_size;
1321 }
1322 
1323 
1325  if (bc_mesh_ == nullptr) bc_mesh_ = new BCMesh(this);
1326  return bc_mesh_;
1327 }
1328 
1329 
1331  ASSERT_PTR(el_4_loc).error("Array 'el_4_loc' is not initialized. Did you call Partitioning::id_maps?\n");
1332 
1333  unsigned int i_proc, i_node, i_ghost_node, elm_node;
1334  unsigned int my_proc = el_ds->myp();
1335  unsigned int n_proc = el_ds->np();
1336 
1337  // distribute nodes between processes, every node is assigned to minimal process of elements that own node
1338  // fill node_proc vector with same values on all processes
1339  std::vector<unsigned int> node_proc( this->n_nodes(), n_proc );
1340  std::vector<bool> local_node_flag( this->n_nodes(), false );
1341 
1342  for ( auto elm : this->elements_range() ) {
1343  i_proc = elm.proc();
1344  for (elm_node=0; elm_node<elm->n_nodes(); elm_node++) {
1345  i_node = elm->node_idx(elm_node);
1346  if (i_proc == my_proc) local_node_flag[i_node] = true;
1347  if (i_proc < node_proc[i_node]) node_proc[i_node] = i_proc;
1348  }
1349  }
1350 
1351  unsigned int n_own_nodes=0, n_local_nodes=0; // number of own and ghost nodes
1352  for(uint loc_flag : local_node_flag) if (loc_flag) n_local_nodes++;
1353  for(uint i_proc : node_proc) {
1354  if (i_proc == my_proc)
1355  n_own_nodes++;
1356  else if (i_proc == n_proc)
1357  ASSERT(0)(find_node_id(n_own_nodes)).error("A node does not belong to any element!");
1358  }
1359 
1360  //DebugOut() << print_var(n_own_nodes) << print_var(n_local_nodes) << this->n_nodes();
1361  // create and fill node_4_loc_ (mapping local to global indexes)
1362  node_4_loc_ = new LongIdx [ n_local_nodes ];
1363  i_node=0;
1364  i_ghost_node = n_own_nodes;
1365  for (unsigned int i=0; i<this->n_nodes(); ++i) {
1366  if (local_node_flag[i]) {
1367  if (node_proc[i]==my_proc)
1368  node_4_loc_[i_node++] = i;
1369  else
1370  node_4_loc_[i_ghost_node++] = i;
1371  }
1372  }
1373 
1374  // Construct node distribution object, set number of local nodes (own+ghost)
1375  node_ds_ = new Distribution(n_own_nodes, PETSC_COMM_WORLD);
1376  node_ds_->get_lsizes_array(); // need to initialize lsizes data member
1378 
1379 }
1380 
1381 //-----------------------------------------------------------------------------
1382 // vim: set cindent:
Side::edge
Edge edge() const
Returns pointer to the edge connected to the side.
Definition: accessors_impl.hh:221
MeshOptimizer::calculate_node_curve_values_as_hilbert
void calculate_node_curve_values_as_hilbert()
Definition: mesh_optimizer.hh:59
Mesh::create_boundary_elements
unsigned int create_boundary_elements()
Create boundary elements from data of temporary structure, this method MUST be call after read mesh f...
Definition: mesh.cc:1310
Input::Type::Bool
Class for declaration of the input of type Bool.
Definition: type_base.hh:452
Distribution::np
unsigned int np() const
get num of processors
Definition: distribution.hh:105
Mesh::element_nodes_original_
std::array< std::array< uint, 4 >, 64 > element_nodes_original_
Definition: mesh.h:630
reader_to_storage.hh
Boundary
Definition: accessors.hh:368
BidirectionalMap< int >
Mesh::BCMesh
friend class BCMesh
Definition: mesh.h:638
ref_element.hh
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
Mesh::nodes_
Armor::Array< double > nodes_
Definition: mesh.h:615
Neighbour::mesh_
Mesh * mesh_
Pointer to Mesh to which belonged.
Definition: neighbours.h:136
MeshOptimizer::sort_elements
std::vector< int > sort_elements(std::vector< unsigned int > &elem_permutation)
Definition: mesh_optimizer.hh:108
Region::label
std::string label() const
Returns label of the region (using RegionDB)
Definition: region.cc:32
Mesh::get_input_intersection_variant
static const Input::Type::Selection & get_input_intersection_variant()
The definition of input record for selection of variant of file format.
Definition: mesh.cc:65
Mesh::get_element_boxes
std::vector< BoundingBox > get_element_boxes()
Compute bounding boxes of elements contained in mesh.
Definition: mesh.cc:1043
Neighbour::edge_idx_
unsigned int edge_idx_
Index of Edge in Mesh.
Definition: neighbours.h:138
Input::ReaderToStorage
Reader for (slightly) modified input files.
Definition: reader_to_storage.hh:96
Mesh::node_4_loc_
LongIdx * node_4_loc_
Index set assigning to local node index its global index.
Definition: mesh.h:656
bih_tree.hh
Input::ReaderToStorage::read_stream
void read_stream(istream &in, const Type::TypeBase &root_type, FileFormat format)
This method actually reads the given stream in.
Definition: reader_to_storage.cc:110
mesh_optimizer.hh
Mesh::in_record_
Input::Record in_record_
Definition: mesh.h:586
RefElement
Definition: ref_element.hh:339
Mesh::init_element_vector
void init_element_vector(unsigned int size)
Initialize element_vec_, set size and reset counters of boundary and bulk elements.
Definition: mesh.cc:1138
neighbours.h
Neighbour::elem_idx_
unsigned int elem_idx_
Index of element in Mesh::element_vec_.
Definition: neighbours.h:137
Mesh::n_exsides
int n_exsides
Definition: mesh.h:325
Mesh::init_element
void init_element(Element *ele, unsigned int elm_id, unsigned int dim, RegionIdx region_idx, unsigned int partition_id, std::vector< unsigned int > node_ids)
Initialize element.
Definition: mesh.cc:1107
Distribution::myp
unsigned int myp() const
get my processor
Definition: distribution.hh:107
RegionSetBase::get_input_type
static Input::Type::Abstract & get_input_type()
Definition: region_set.cc:25
MeshOptimizer::calculate_element_curve_values_as_hilbert_of_centers
void calculate_element_curve_values_as_hilbert_of_centers()
Definition: mesh_optimizer.hh:86
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
RegionDB::check_regions
void check_regions()
Definition: region.cc:461
Element::dim
unsigned int dim() const
Definition: elements.h:118
Mesh::elements_range
virtual Range< ElementAccessor< 3 > > elements_range() const
Returns range of bulk elements.
Definition: mesh.cc:1169
Mesh::n_sides
unsigned int n_sides() const
Definition: mesh.cc:238
Mesh::check_compatible_mesh
virtual std::shared_ptr< EquivalentMeshMap > check_compatible_mesh(Mesh &input_mesh)
Definition: mesh.cc:909
distribution.hh
Support classes for parallel programing.
bc_mesh.hh
Edge::n_sides
unsigned int n_sides() const
Returns number of sides aligned with the edge.
Definition: accessors.hh:348
_comparisons
std::array< std::pair< uint, uint >, 6 > _comparisons
Definition: mesh.cc:390
BoundaryData::edge_idx_
unsigned int edge_idx_
Definition: mesh_data.hh:49
MixedMeshIntersections
Main class for computation of intersection of meshes of combined dimensions.
Definition: mixed_mesh_intersections.hh:64
compare_points
bool compare_points(const arma::vec3 &p1, const arma::vec3 &p2)
Definition: mesh.cc:901
Input::Record::val
const Ret val(const string &key) const
Definition: accessors_impl.hh:31
Mesh::boundary_loaded_size_
unsigned int boundary_loaded_size_
Count of boundary elements loaded from mesh file.
Definition: mesh.h:607
Armor::Array::vec
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:821
Input::Type::Selection::close
const Selection & close() const
Close the Selection, no more values can be added.
Definition: type_selection.cc:65
Mesh::tree
DuplicateNodes * tree
Definition: mesh.h:317
Mesh::element_vec_
vector< Element > element_vec_
Definition: mesh.h:598
Neighbour::side
SideIter side()
Definition: neighbours.h:145
Element::pid_
int pid_
Id # of mesh partition.
Definition: elements.h:95
FilePath
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
MeshOptimizer::calculate_sizes
void calculate_sizes()
Definition: mesh_optimizer.hh:40
RegionIdx::is_valid
bool is_valid() const
Returns false if the region has undefined/invalid value.
Definition: region.hh:78
Input::Type::Double
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
Mesh::sort_permuted_nodes_elements
void sort_permuted_nodes_elements(std::vector< int > new_node_ids, std::vector< int > new_elem_ids)
Sort elements and nodes by order stored in permutation vectors.
Definition: mesh.cc:483
RegionDB::mark_used_region
void mark_used_region(unsigned int idx)
Definition: region.cc:235
Mesh::get_input_type
static const Input::Type::Record & get_input_type()
Definition: mesh.cc:76
BIHTree
Class for O(log N) lookup for intersections with a set of bounding boxes.
Definition: bih_tree.hh:38
THROW
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
Mesh::RegionSetBase
friend class RegionSetBase
Definition: mesh.h:634
Mesh::max_edge_sides_
unsigned int max_edge_sides_[3]
Maximal number of sides per one edge in the actual mesh (set in make_neighbours_and_edges()).
Definition: mesh.h:535
std::vector< uint >
Mesh::count_side_types
void count_side_types()
Definition: mesh.cc:510
ElementAccessor< 3 >
Partitioning
Class for the mesh partitioning. This should provide:
Definition: partitioning.hh:52
Element::permutation_
uint permutation_
Index of permutation of input nodes.
Definition: elements.h:92
Input::Type::FileName::output
static FileName output()
The factory function for declaring type FileName for input files.
Definition: type_base.cc:531
system.hh
arma::vec3
Definition: doxy_dummy_defs.hh:17
RegionDB::get_region
Region get_region(unsigned int id, unsigned int dim)
Definition: region.cc:150
BoundaryData
Definition: mesh_data.hh:40
Mesh::node_range
Range< NodeAccessor< 3 > > node_range() const
Returns range of nodes.
Definition: mesh.cc:1175
Partitioning::get_loc_part
const LongIdx * get_loc_part() const
Definition: partitioning.cc:85
Mesh::boundary
Boundary boundary(uint edge_idx) const
Definition: mesh.cc:268
EdgeData
Definition: mesh_data.hh:25
Armor::Array::resize
void resize(uint size)
Definition: armor.hh:710
uint
unsigned int uint
Definition: mh_dofhandler.hh:101
RegionIdx::idx
unsigned int idx() const
Returns a global index of the region.
Definition: region.hh:82
Mesh::n_local_nodes_
unsigned int n_local_nodes_
Hold number of local nodes (own + ghost), value is equal with size of node_4_loc array.
Definition: mesh.h:660
fmt::format
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
duplicate_nodes.h
Neighbour
Definition: neighbours.h:117
ElementAccessor::element
const Element * element() const
Definition: accessors.hh:195
FilePath::open_stream
void open_stream(Stream &stream) const
Definition: file_path.cc:211
Input::Array::begin
Iterator< ValueType > begin() const
Definition: accessors_impl.hh:145
Mesh::read_regions_from_input
void read_regions_from_input(Input::Array region_list)
Definition: mesh.cc:1018
RegionDB::create_label_from_id
std::string create_label_from_id(unsigned int id) const
Definition: region.cc:337
index_types.hh
RegionDB::el_to_reg_map_
MapElementIDToRegionID el_to_reg_map_
Definition: region.hh:571
BoundaryData::bc_ele_idx_
unsigned int bc_ele_idx_
Definition: mesh_data.hh:53
Mesh::get_intersection_search
IntersectionSearch get_intersection_search()
Getter for input type selection for intersection search algorithm.
Definition: mesh.cc:156
Mesh::optimize_memory_locality
bool optimize_memory_locality
Definition: mesh.h:565
Mesh::n_vb_neighbours
unsigned int n_vb_neighbours() const
Definition: mesh.cc:247
exceptions.hh
Mesh::n_elements
virtual unsigned int n_elements() const
Returns count of boundary or bulk elements.
Definition: mesh.h:398
Element
Definition: elements.h:40
MPI_Comm_rank
#define MPI_Comm_rank
Definition: mpi.h:236
ASSERT_PTR_DBG
#define ASSERT_PTR_DBG(ptr)
Definition of assert macro checking non-null pointer (PTR) only for debug mode.
Definition: asserts.hh:340
Mesh::optimize
void optimize()
Definition: mesh.cc:473
Mesh::el_ds
Distribution * el_ds
Parallel distribution of elements.
Definition: mesh.h:654
Region::id
unsigned int id() const
Returns id of the region (using RegionDB)
Definition: region.cc:37
Mesh::intersect_element_lists
void intersect_element_lists(vector< unsigned int > const &nodes_list, vector< unsigned int > &intersection_element_list)
Definition: mesh.cc:538
Mesh::n_sides_
int n_sides_
Definition: mesh.h:326
EdgeData::side_
SideIter * side_
Definition: mesh_data.hh:32
Input::Iterator
Definition: accessors.hh:143
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
RegionDB::undefined_dim
static const unsigned int undefined_dim
Definition: region.hh:332
MeshOptimizer::sort_nodes
std::vector< int > sort_nodes(std::vector< unsigned int > &node_permutation)
Definition: mesh_optimizer.hh:104
Mesh::output_internal_ngh_data
void output_internal_ngh_data()
Output of neighboring data into raw output.
Definition: mesh.cc:1195
Mesh::get_local_part
virtual const LongIdx * get_local_part()
Definition: mesh.cc:278
Distribution
Definition: distribution.hh:50
Mesh::node_ids_
BidirectionalMap< int > node_ids_
Maps node ids to indexes into vector node_vec_.
Definition: mesh.h:618
ElementAccessor::bounding_box
BoundingBox bounding_box() const
Definition: accessors.hh:253
accessors.hh
Mesh::BBsearch
@ BBsearch
Definition: mesh.h:138
Mesh::check_mesh_on_read
void check_mesh_on_read()
Definition: mesh.cc:310
Mesh::n_corners
unsigned int n_corners()
Definition: mesh.cc:252
BIHTree::find_point
void find_point(const Space< 3 >::Point &point, std::vector< unsigned int > &result_list, bool full_list=false) const
Definition: bih_tree.cc:287
Mesh::find_lower_dim_element
bool find_lower_dim_element(vector< unsigned int > &element_list, unsigned int dim, unsigned int &element_idx)
Definition: mesh.cc:570
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Mesh::get_bih_tree
const BIHTree & get_bih_tree()
Getter for BIH. Creates and compute BIH at first call.
Definition: mesh.cc:1058
Mesh::distribute_nodes
void distribute_nodes()
Fill array node_4_loc_ and create object node_ds_ according to element distribution.
Definition: mesh.cc:1330
sys_profiler.hh
Edge::side
SideIter side(const unsigned int i) const
Gets side iterator of the i -th side.
Definition: accessors_impl.hh:171
undef_idx
const unsigned int undef_idx
Definition: index_types.hh:32
Mesh::get_bc_mesh
BCMesh * get_bc_mesh()
Create boundary mesh if doesn't exist and return it.
Definition: mesh.cc:1324
RegionIdx::is_boundary
bool is_boundary() const
Returns true if it is a Boundary region and false if it is a Bulk region.
Definition: region.hh:74
mixed_mesh_intersections.hh
Input::Type::Record::allow_auto_conversion
virtual Record & allow_auto_conversion(const string &from_key)
Allows shorter input of the Record providing only value of the from_key given as the parameter.
Definition: type_record.cc:133
accessors.hh
Mesh::el_4_loc
LongIdx * el_4_loc
Index set assigning to local element index its global index.
Definition: mesh.h:652
Mesh::elements_id_maps
void elements_id_maps(vector< LongIdx > &bulk_elements_id, vector< LongIdx > &boundary_elements_id) const
Definition: mesh.cc:868
INPUT_CATCH
#define INPUT_CATCH(ExceptionType, AddressEITag, input_accessor)
Definition: accessors.hh:63
Element::n_neighs_vb_
unsigned int n_neighs_vb_
Definition: elements.h:97
Mesh::side_nodes
vector< vector< vector< unsigned int > > > side_nodes
Definition: mesh.h:339
Mesh::node_permutation_
std::vector< unsigned int > node_permutation_
Vector of node permutations of optimized mesh (see class MeshOptimizer)
Definition: mesh.h:624
Mesh::canonical_faces
void canonical_faces()
Definition: mesh.cc:393
Mesh::region_db_
RegionDB region_db_
Definition: mesh.h:571
Distribution::get_lsizes_array
const unsigned int * get_lsizes_array()
get local sizes array
Definition: distribution.cc:142
Input::AbstractRecord
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:458
Neighbour::element
ElementAccessor< 3 > element()
Definition: neighbours.h:161
Input::Type::Default::obligatory
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
ElementAccessor::jacobian_S3
double jacobian_S3() const
Definition: accessors.hh:131
Mesh::IntersectionSearch
IntersectionSearch
Types of search algorithm for finding intersection candidates.
Definition: mesh.h:135
RegionDB::close
void close()
Definition: region.cc:249
Mesh::find_elem_id
int find_elem_id(unsigned int pos) const
Return element id (in GMSH file) of element of given position in element vector.
Definition: mesh.h:412
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328
Element::init
void init(unsigned int dim, RegionIdx reg)
Definition: elements.cc:53
Mesh::init
void init()
Definition: mesh.cc:162
RegionDB::find_id
Region find_id(unsigned int id, unsigned int dim) const
Definition: region.cc:180
Input::Record::opt_val
bool opt_val(const string &key, Ret &value) const
Definition: accessors_impl.hh:107
Input::format_JSON
@ format_JSON
Definition: reader_to_storage.hh:60
Input::Type::Record::declare_key
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:503
Input::ReaderToStorage::get_root_interface
T get_root_interface() const
Returns the root accessor.
Definition: reader_to_storage.cc:150
Side::element
ElementAccessor< 3 > element() const
Returns iterator to the element of the side.
Definition: accessors_impl.hh:212
mesh.h
Mesh::bih_tree_
std::shared_ptr< BIHTree > bih_tree_
Definition: mesh.h:580
Mesh::node_ds_
Distribution * node_ds_
Parallel distribution of nodes. Depends on elements distribution.
Definition: mesh.h:658
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
std::map< unsigned int, unsigned int >
Side::n_nodes
unsigned int n_nodes() const
Returns number of nodes of the side.
Definition: accessors.hh:455
Element::region_idx_
RegionIdx region_idx_
Definition: elements.h:104
ElementAccessor::node
NodeAccessor< 3 > node(unsigned int ni) const
Definition: accessors.hh:245
Input::Type::FileName::input
static FileName input()
The factory function for declaring type FileName for input files.
Definition: type_base.cc:524
Mesh::same_sides
bool same_sides(const SideIter &si, vector< unsigned int > &side_nodes)
Definition: mesh.cc:592
Armor::Array::set
ArrayMatSet set(uint index)
Definition: armor.hh:838
Input::Type::Record::close
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Mesh::element_to_neigh_vb
void element_to_neigh_vb()
Definition: mesh.cc:806
Element::node_idx
unsigned int node_idx(unsigned int ni) const
Return index (in Mesh::node_vec) of ni-th node.
Definition: elements.h:70
Mesh::check_element_size
void check_element_size(unsigned int elem_idx) const
Check if given index is in element_vec_.
Definition: mesh.cc:1187
Mesh::add_element
void add_element(unsigned int elm_id, unsigned int dim, unsigned int region_id, unsigned int partition_id, std::vector< unsigned int > node_ids)
Add new element of given id to mesh.
Definition: mesh.cc:1084
Side::side_idx
unsigned int side_idx() const
Returns local index of the side on the element.
Definition: accessors.hh:463
Input::Type
Definition: balance.hh:41
partitioning.hh
Partitioning::get_input_type
static const Input::Type::Record & get_input_type()
Definition: partitioning.cc:49
RegionDB::implicit_boundary_region
Region implicit_boundary_region()
Definition: region.cc:75
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
MPI_Comm
int MPI_Comm
Definition: mpi.h:141
Mesh::Element
friend class Element
Definition: mesh.h:635
Mesh::~Mesh
virtual ~Mesh()
Destructor.
Definition: mesh.cc:213
Mesh::Edge
friend class Edge
Definition: mesh.h:632
Element::neigh_vb
Neighbour ** neigh_vb
Definition: elements.h:83
Element::nodes_
std::array< unsigned int, 4 > nodes_
indices to element's nodes
Definition: elements.h:108
Interaction
Definition: ref_element.hh:286
Mesh::create_node_element_lists
void create_node_element_lists()
Definition: mesh.cc:525
Element::edge_idx
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:133
EdgeData::n_sides
unsigned int n_sides
Definition: mesh_data.hh:29
LongIdx
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
Mesh::setup_topology
void setup_topology()
Definition: mesh.cc:437
input_type.hh
Mesh::add_element_to_vector
Element * add_element_to_vector(int id)
Adds element to mesh data structures (element_vec_, element_ids_), returns pointer to this element.
Definition: mesh.cc:1161
Mesh::modify_element_ids
void modify_element_ids(const RegionDB::MapElementIDToRegionID &map)
Definition: mesh.cc:285
Mesh
Definition: mesh.h:98
Armor::Array::reinit
void reinit(uint size)
Definition: armor.hh:698
Element::n_sides
unsigned int n_sides() const
Definition: elements.h:129
Mesh::BIHsearch
@ BIHsearch
Definition: mesh.h:136
Mesh::elem_index
int elem_index(int elem_id) const
For element of given elem_id returns index in element_vec_ or (-1) if element doesn't exist.
Definition: mesh.h:406
Range
Range helper class.
Definition: range_wrapper.hh:65
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
OLD_ASSERT
#define OLD_ASSERT(...)
Definition: global_defs.h:108
Mesh::edges
std::vector< EdgeData > edges
Vector of MH edges, this should not be part of the geometrical mesh.
Definition: mesh.h:621
Mesh::make_neighbours_and_edges
void make_neighbours_and_edges()
Definition: mesh.cc:609
BidirectionalMap::clear
void clear()
Clear the content. Do not release memory.
Definition: bidirectional_map.hh:121
Mesh::init_node_vector
void init_node_vector(unsigned int size)
Initialize node_vec_, set size.
Definition: mesh.cc:1152
Mesh::elem_permutation_
std::vector< unsigned int > elem_permutation_
Vector of element permutations of optimized mesh (see class MeshOptimizer)
Definition: mesh.h:627
Edge
Definition: accessors.hh:313
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
Mesh::Mesh
Mesh()
Definition: mesh.cc:102
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:278
RegionIdx
Definition: region.hh:67
Input::Type::Record::finish
FinishStatus finish(FinishStatus finish_type=FinishStatus::regular_) override
Finish declaration of the Record type.
Definition: type_record.cc:243
Armor::Array::append
void append(const ArmaMat< Type, nr, nc > &item)
Definition: armor.hh:736
region_set.hh
ElementAccessor::region
Region region() const
Definition: accessors.hh:201
Mesh::node_index
int node_index(int node_id) const
For node of given node_id returns index in element_vec_ or (-1) if node doesn't exist.
Definition: mesh.h:424
BCMesh
Class represents boundary part of mesh.
Definition: bc_mesh.hh:35
Mesh::check_and_finish
void check_and_finish()
Definition: mesh.cc:1028
Mesh::edge_range
Range< Edge > edge_range() const
Returns range of edges.
Definition: mesh.cc:1181
NodeAccessor
Definition: mesh.h:55
Mesh::node_elements_
vector< vector< unsigned int > > node_elements_
For each node the vector contains a list of elements that use this node.
Definition: mesh.h:403
MPI_COMM_WORLD
#define MPI_COMM_WORLD
Definition: mpi.h:123
ASSERT_LT_DBG
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:300
region.hh
Mesh::element_ids_
BidirectionalMap< int > element_ids_
Maps element ids to indexes into vector element_vec_.
Definition: mesh.h:610
Armor::Array< double >
Mesh::add_node
void add_node(unsigned int node_id, arma::vec3 coords)
Add new node of given id and coordinates to mesh.
Definition: mesh.cc:1076
Mesh::bc_element_tmp_
vector< ElementTmpData > bc_element_tmp_
Hold data of boundary elements during reading mesh (allow to preserve correct order during reading of...
Definition: mesh.h:601
ElementAccessor::idx
unsigned int idx() const
Return local idx of element in boundary / bulk part of element vector.
Definition: accessors.hh:223
NDEF
#define NDEF
Definition: mesh.cc:61
RegionDB::add_region
Region add_region(unsigned int id, const std::string &label, unsigned int dim, const std::string &address="implicit")
Definition: region.cc:85
MeshOptimizer
Definition: mesh_optimizer.hh:35
Mesh::part_
std::shared_ptr< Partitioning > part_
Definition: mesh.h:575
Mesh::check_compatible_elements
unsigned int check_compatible_elements(Mesh *source_mesh, Mesh *target_mesh, const std::vector< unsigned int > &node_ids, std::vector< LongIdx > &map)
Definition: mesh.cc:974
print_var
#define print_var(var)
Definition: logger.hh:292
Mesh::bulk_size_
unsigned int bulk_size_
Count of bulk elements.
Definition: mesh.h:604
BidirectionalMap::add_item
unsigned int add_item(T val)
Add new item at the end position of map.
Definition: bidirectional_map.hh:106
RegionDB::print_region_table
void print_region_table(std::ostream &stream) const
Definition: region.cc:409
Mesh::row_4_el
LongIdx * row_4_el
Index set assigning to global element index the local index used in parallel vectors.
Definition: mesh.h:650
Mesh::node_elements
const vector< vector< unsigned int > > & node_elements()
Definition: mesh.cc:1130
Mesh::global_snap_radius
double global_snap_radius() const
Maximal distance of observe point from Mesh relative to its size.
Definition: mesh.cc:1067
Mesh::boundary_
vector< BoundaryData > boundary_
Definition: mesh.h:301
Mesh::Boundary
friend class Boundary
Definition: mesh.h:637
Mesh::n_local_nodes
unsigned int n_local_nodes() const
Definition: mesh.h:213
Mesh::get_part
virtual Partitioning * get_part()
Definition: mesh.cc:274
Mesh::n_insides
int n_insides
Definition: mesh.h:324
Side::node
NodeAccessor< 3 > node(unsigned int i) const
Returns node for given local index i on the side.
Definition: accessors_impl.hh:206
Mesh::bc_mesh_
BCMesh * bc_mesh_
Boundary mesh, object is created only if it's necessary.
Definition: mesh.h:662
Mesh::mixed_intersections
MixedMeshIntersections & mixed_intersections()
Definition: mesh.cc:839
DebugOut
#define DebugOut()
Macro defining 'debug' record of log.
Definition: logger.hh:284
Input::Type::Selection::add_value
Selection & add_value(const int value, const std::string &key, const std::string &description="", TypeBase::attribute_map attributes=TypeBase::attribute_map())
Adds one new value with name given by key to the Selection.
Definition: type_selection.cc:50
Mesh::BIHonly
@ BIHonly
Definition: mesh.h:137
ASSERT_PTR
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:336
ElementAccessor::side
SideIter side(const unsigned int loc_index)
Definition: accessors_impl.hh:139
Mesh::node
NodeAccessor< 3 > node(unsigned int idx) const
Create and return NodeAccessor to node of given idx.
Definition: mesh.cc:862
Mesh::element_accessor
virtual ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:856
BoundaryData::mesh_
Mesh * mesh_
Definition: mesh_data.hh:54
BidirectionalMap::reserve
void reserve(unsigned int init_size=0)
Reset data of map, reserve space for given size.
Definition: bidirectional_map.hh:139
Input::Type::Default::optional
static Default optional()
The factory function to make an empty default value which is optional.
Definition: type_record.hh:124
Mesh::n_nodes
virtual unsigned int n_nodes() const
Definition: mesh.h:170
START_TIMER
#define START_TIMER(tag)
Starts a timer with specified tag.
Definition: sys_profiler.hh:115
Input::Array::end
IteratorBase end() const
Definition: accessors_impl.hh:157
Mesh::find_node_id
int find_node_id(unsigned int pos) const
Return node id (in GMSH file) of node of given position in node vector.
Definition: mesh.h:430
ElementAccessor::index
unsigned int index() const
Definition: accessors.hh:235
SideIter
Definition: accessors.hh:509
Input::Record::is_empty
bool is_empty() const
Definition: accessors.hh:365
Element::boundary_idx_
unsigned int * boundary_idx_
Definition: elements.h:79
Mesh::edge
Edge edge(uint edge_idx) const
Definition: mesh.cc:262
Mesh::add_physical_name
void add_physical_name(unsigned int dim, unsigned int id, std::string name)
Add new node of given id and coordinates to mesh.
Definition: mesh.cc:1071
Mesh::vb_neighbours_
vector< Neighbour > vb_neighbours_
Definition: mesh.h:322
END_TIMER
#define END_TIMER(tag)
Ends a timer with specified tag.
Definition: sys_profiler.hh:149
Element::n_nodes
unsigned int n_nodes() const
Definition: elements.h:123
Mesh::ElementTmpData
Definition: mesh.h:463
DuplicateNodes
Definition: duplicate_nodes.h:96
BidirectionalMap::size
unsigned int size() const
Return size of map.
Definition: bidirectional_map.hh:80
range_wrapper.hh
Implementation of range helper class.
MessageOut
#define MessageOut()
Macro defining 'message' record of log.
Definition: logger.hh:275
node_accessor.hh
Mesh::intersections
std::shared_ptr< MixedMeshIntersections > intersections
Definition: mesh.h:309