41 #include <boost/tokenizer.hpp>
42 #include "boost/lexical_cast.hpp"
43 #include <boost/make_shared.hpp>
66 namespace IT = Input::Type;
70 =
IT::Record(
"Mesh",
"Record with mesh related data." )
72 "Input file with mesh description.")
74 "List of additional region definitions not contained in the mesh.")
76 "List of region set definitions. There are three region sets implicitly defined:\n"
77 "ALL (all regions of the mesh), BOUNDARY (all boundary regions), and BULK (all bulk regions)")
98 : in_record_(in_record),
131 for(
int i=0; i < 3; i++) {
133 for(
int j=0; j < i+2; j++)
137 for (
unsigned int sid=0; sid<RefElement<1>::n_sides; sid++)
138 for (
unsigned int nid=0; nid<RefElement<1>::n_nodes_per_side; nid++)
141 for (
unsigned int sid=0; sid<RefElement<2>::n_sides; sid++)
142 for (
unsigned int nid=0; nid<RefElement<2>::n_nodes_per_side; nid++)
145 for (
unsigned int sid=0; sid<RefElement<3>::n_sides; sid++)
146 for (
unsigned int nid=0; nid<RefElement<3>::n_nodes_per_side; nid++)
153 if (edg.side_)
delete[] edg.side_;
156 if (ele->node)
delete[] ele->node;
157 if (ele->edge_idx_)
delete[] ele->edge_idx_;
158 if (ele->permutation_idx_)
delete[] ele->permutation_idx_;
159 if (ele->boundary_idx_)
delete[] ele->boundary_idx_;
182 unsigned int li, count = 0;
202 switch (elm->dim()) {
259 if (ele->quality_measure_smooth() < 0.001)
xprintf(
Warn,
"Bad quality (<0.001) of the element %u.\n", ele.id());
290 for (
unsigned int n=0; n<e->n_nodes(); n++)
294 stable_sort(n->begin(), n->end());
300 if (nodes_list.size() == 0) {
301 intersection_element_list.clear();
302 }
else if (nodes_list.size() == 1) {
307 intersection_element_list.resize(
node_elements[*it1].size() );
309 it1=set_intersection(
312 intersection_element_list.begin());
313 intersection_element_list.resize(it1-intersection_element_list.begin());
315 for(;it2<nodes_list.end();++it2) {
316 it1=set_intersection(
317 intersection_element_list.begin(), intersection_element_list.end(),
319 intersection_element_list.begin());
320 intersection_element_list.resize(it1-intersection_element_list.begin());
327 unsigned int dim,
unsigned int &element_idx) {
328 bool is_neighbour =
false;
332 if (elements[*ele].dim() == dim) {
335 }
else if (elements[*ele].dim() == dim-1) {
336 if (is_neighbour)
xprintf(
UsrErr,
"Too matching elements id: %d and id: %d in the same mesh.\n",
337 elements(*ele).id(), elements(element_idx).id() );
342 element_list.resize( e_dest - element_list.begin());
350 && find(side_nodes.begin(), side_nodes.end(),
node_vector.
index( si->
node(ni) ) ) != side_nodes.end() ) ni++;
351 return ( ni == si->
n_nodes() );
367 unsigned int ngh_element_idx, last_edge_idx;
380 side_nodes.resize(bc_ele->n_nodes());
381 for (
unsigned n=0; n<bc_ele->n_nodes(); n++) side_nodes[n] =
node_vector.
index(bc_ele->node[n]);
385 xprintf(
UsrErr,
"Boundary element (id: %d) match a regular element (id: %d) of lower dimension.\n",
386 bc_ele.id(),
element(ngh_element_idx).id());
388 if (intersection_list.size() == 0) {
390 xprintf(
Warn,
"Lonely boundary element, id: %d, region: %d, dimension %d.\n", bc_ele.id(), bc_ele->region().id(), bc_ele->dim());
393 last_edge_idx=
edges.size();
394 edges.resize(last_edge_idx+1);
395 edg = &(
edges.back() );
397 edg->
side_ =
new struct SideIter[ intersection_list.size() ];
411 for (
unsigned int ecs=0; ecs<elem->
n_sides(); ecs++) {
433 for (
unsigned int s=0; s<e->n_sides(); s++)
436 if (e->edge_idx_[s] != Mesh::undef_idx)
continue;
440 side_nodes.resize(e->side(s)->n_nodes());
441 for (
unsigned n=0; n<e->side(s)->n_nodes(); n++) side_nodes[n] =
node_vector.
index(e->side(s)->node(n));
450 last_edge_idx=
edges.size();
451 edges.resize(last_edge_idx+1);
452 edg = &(
edges.back() );
454 edg->
side_ =
new struct SideIter[ intersection_list.size() ];
458 if (intersection_list.size() == 1) {
460 edg->
side_[0] = e->side(s);
461 e->edge_idx_[s] = last_edge_idx;
463 if (e->boundary_idx_ == NULL) {
464 e->boundary_idx_ =
new unsigned int [ e->n_sides() ];
465 std::fill( e->boundary_idx_, e->boundary_idx_ + e->n_sides(),
Mesh::undef_idx);
471 e->boundary_idx_[s] = bdr_idx;
476 for(
unsigned int ni = 0; ni< side_nodes.size(); ni++) bc_ele->node[ni] = &(
node_vector[side_nodes[ni]] );
490 for (
unsigned int ecs=0; ecs<elem->
n_sides(); ecs++) {
491 if (elem->
edge_idx_[ecs] != Mesh::undef_idx)
continue;
496 last_edge_idx=
edges.size();
497 edges.resize(last_edge_idx+1);
498 edg = &(
edges.back() );
516 ASSERT( is_neighbour || ( (
unsigned int) edg->
n_sides ) == intersection_list.size(),
"Some connected sides were not found.\n");
530 edg->side(0)->element()->permutation_idx_[edg->side(0)->el_idx()] = 0;
532 if (edg->n_sides > 1)
535 unsigned int permutation[edg->side(0)->n_nodes()];
537 for (
unsigned int i=0; i<edg->side(0)->n_nodes(); i++)
538 node_numbers[edg->side(0)->node(i)] = i;
540 for (
int sid=1; sid<edg->n_sides; sid++)
542 for (
unsigned int i=0; i<edg->side(0)->n_nodes(); i++)
543 permutation[node_numbers[edg->side(sid)->node(i)]] = i;
545 switch (edg->side(0)->dim())
564 unsigned int permutation[nb->element()->n_nodes()];
568 for (
unsigned int i=0; i<nb->element()->n_nodes(); i++)
569 node_numbers[nb->element()->node[i]] = i;
571 for (
unsigned int i=0; i<nb->side()->n_nodes(); i++)
572 permutation[node_numbers[nb->side()->node(i)]] = i;
574 switch (nb->side()->dim())
608 if( ele->n_neighs_vb > 0 ) {
609 ele->neigh_vb =
new struct Neighbour* [ele->n_neighs_vb];
616 ele = ngh->element();
642 for(
unsigned int i_ele=0; i_ele<
n_elements(); i_ele++) {
645 if (ele.
dim() == 1) {
650 for(
unsigned int i_elm : candidate_list) {
652 if (elm->dim() == 2) {
685 for(
unsigned int idx=0; idx <
element.
size(); idx++, ++map_it) {
687 if (last_id >=
id)
xprintf(
UsrErr,
"Element IDs in non-increasing order, ID: %d\n",
id);
688 last_id=*map_it = id;
699 if (
id < 0) last_id=*map_it=-1;
701 if (last_id >=
id)
xprintf(
UsrErr,
"Element IDs in non-increasing order, ID: %d\n",
id);
702 last_id=*map_it = id;
Class for the mesh partitioning. This should provide:
Mesh(const std::string &input_str="{mesh_file=\"\"}", MPI_Comm com=MPI_COMM_WORLD)
void read_regions_from_input(Input::Array region_list, MapElementIDToRegionID &map)
#define FOR_ELEMENT_NODES(i, j)
vector< vector< unsigned int > > node_elements
unsigned int * boundary_idx_
int get_id(const T *it) const
void read_sets_from_input(Input::Array arr)
void find_bounding_box(const BoundingBox &boundingBox, std::vector< unsigned int > &result_list)
void make_intersec_elements()
#define FOR_ELEMENTS(_mesh_, __i)
unsigned int * permutation_idx_
static const unsigned int undef_idx
void create_node_element_lists()
static unsigned int permutation_index(unsigned int p[n_nodes_per_side])
unsigned int max_edge_sides_[3]
Maximal number of sides per one edge in the actual mesh (set in make_neighbours_and_edges()).
boost::shared_ptr< Partitioning > part_
FullIter add_item(int id)
vector< vector< vector< unsigned int > > > side_nodes
ElementAccessor< 3 > element_accessor(unsigned int idx, bool boundary=false)
vector< Boundary > boundary_
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
Partitioning * get_part()
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
unsigned int n_elements() const
bool same_sides(const SideIter &si, vector< unsigned int > &side_nodes)
static Input::Type::Record input_type
std::vector< T >::iterator iterator
vector< int > const & elements_id_maps(bool boundary_domain) const
unsigned int n_sides() const
#define START_TIMER(tag)
Starts a timer with specified tag.
Class for O(log N) lookup for intersections with a set of bounding boxes.
unsigned int index(const T *pointer) const
#define FOR_NEIGHBOURS(_mesh_, it)
ElementVector bc_elements
SideIter side(const unsigned int loc_index)
Region implicit_boundary_region()
vector< int > boundary_elements_id_
void count_element_types()
Dedicated class for storing path to input and output files.
void read_gmsh_from_stream(istream &in)
vector< vector< unsigned int > > master_elements
vector< Neighbour > vb_neighbours_
void read_mesh(Mesh *mesh, const RegionDB::MapElementIDToRegionID *el_to_reg_map=NULL)
static Input::Type::Record region_input_type
static Input::Type::Record input_type
std::vector< Edge > edges
Vector of MH edges, this should not be part of the geometrical mesh.
vector< Intersection > intersections
void intersect_element_lists(vector< unsigned int > const &nodes_list, vector< unsigned int > &intersection_element_list)
void make_edge_permutations()
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
unsigned int n_nodes() const
void element_to_neigh_vb()
static Input::Type::Record region_set_input_type
const Node * node(unsigned int i) const
void reinit(Input::Record in_record)
FullIter end()
Returns FullFullIterer of the fictions past the end element.
#define FOR_SIDES(_mesh_, it)
void GetIntersection(const TBisector &, const TBisector &, TPosition &, double &, double &)
bool find_lower_dim_element(ElementVector &elements, vector< unsigned int > &element_list, unsigned int dim, unsigned int &element_idx)
vector< int > bulk_elements_id_
IntersectionType get_type() const
void make_neighbours_and_edges()
NodeVector node_vector
Vector of nodes of the mesh.
ElementVector element
Vector of elements of the mesh.
unsigned int n_nodes() const
BoundingBox bounding_box()