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