RINGMesh  Version 5.0.0
A programming library for geological model meshes
entity_type_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
36 #pragma once
37 
38 #include <ringmesh/basic/common.h>
39 
41 
43 
44 #include <deque>
45 #include <vector>
46 
47 namespace RINGMesh
48 {
50  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelMeshEntity );
55  FORWARD_DECLARATION_DIMENSION_STRUCT( EntityTypeManager );
56  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderTopologyBase );
57  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderTopology );
58  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderGeology );
59 } // namespace RINGMesh
60 
61 namespace RINGMesh
62 {
63  using MeshEntityTypeMap = std::map< MeshEntityType, MeshEntityType >;
64 
72  template < index_t DIMENSION >
74  {
77  const MeshEntityType& type, const MeshEntityType& boundary )
78  {
79  map.emplace( type, boundary );
80  }
82 
83  private:
84  void initialize_base();
85  };
86 
94  template < index_t DIMENSION >
96  {
99  const MeshEntityType& type, const MeshEntityType& incident_entity )
100  {
101  map.emplace( type, incident_entity );
102  }
104 
105  private:
106  void initialize_base();
107  };
108 
109  template < index_t DIMENSION >
111  {
112  public:
113  MeshEntityTypes();
114 
115  index_t size() const
116  {
117  return static_cast< index_t >( mesh_entity_types_.size() );
118  }
119  const std::vector< MeshEntityType >& container() const
120  {
121  return mesh_entity_types_;
122  }
123 
124  private:
125  void initialize_base();
126 
127  private:
128  std::vector< MeshEntityType > mesh_entity_types_;
129  };
130 
137  template < index_t DIMENSION >
139  {
140  public:
141  bool is_corner( const MeshEntityType& type ) const
142  {
143  return type == mesh_entity_types_.container()[0];
144  }
145 
146  bool is_line( const MeshEntityType& type ) const
147  {
148  return type == mesh_entity_types_.container()[1];
149  }
150 
151  bool is_surface( const MeshEntityType& type ) const
152  {
153  return type == mesh_entity_types_.container()[2];
154  }
155 
156  bool is_valid_type( const MeshEntityType& type ) const
157  {
158  return find( mesh_entity_types_.container(), type ) != NO_ID;
159  }
160 
162  const MeshEntityType& mesh_entity_type ) const
163  {
164  MeshEntityTypeMap::const_iterator itr{
165  boundary_relationships_.map.find( mesh_entity_type )
166  };
167  ringmesh_assert( itr != boundary_relationships_.map.end() );
168  return itr->second;
169  }
170 
172  const MeshEntityType& mesh_entity_type ) const
173  {
174  MeshEntityTypeMap::const_iterator itr{
175  incident_entity_relationships_.map.find( mesh_entity_type )
176  };
177  ringmesh_assert( itr != incident_entity_relationships_.map.end() );
178  return itr->second;
179  }
180 
181  const std::vector< MeshEntityType >& mesh_entity_types() const
182  {
183  return mesh_entity_types_.container();
184  }
185 
186  index_t nb_mesh_entity_types() const
187  {
188  return static_cast< index_t >( mesh_entity_types_.size() );
189  }
190 
191  protected:
192  MeshEntityTypeManagerBase() = default;
193 
194  protected:
199  };
200 
201  template < index_t DIMENSION >
203  {
204  };
205 
206  template <>
207  class RINGMESH_API MeshEntityTypeManager< 3 >
208  : public MeshEntityTypeManagerBase< 3 >
209  {
210  public:
211  bool is_region( const MeshEntityType& type ) const
212  {
213  return type == mesh_entity_types_.container()[3];
214  }
215  };
217 
224  class RINGMESH_API GeologicalTypeManager
225  {
226  friend class GeoModelBuilderGeology< 2 >;
227  friend class GeoModelBuilderGeology< 3 >;
228 
229  public:
230  index_t nb_geological_entity_types() const;
231  const std::vector< GeologicalEntityType >&
232  geological_entity_types() const;
233  const GeologicalEntityType& geological_entity_type(
234  index_t index ) const;
235  index_t geological_entity_type_index(
236  const GeologicalEntityType& type ) const;
237  bool is_valid_type( const GeologicalEntityType& type ) const;
238 
239  private:
240  std::vector< GeologicalEntityType > geological_entity_types_;
241 
242  private:
244  const GeologicalEntityType& geological_type_name )
245  {
246  if( !contains( geological_entity_types_, geological_type_name ) )
247  {
248  geological_entity_types_.push_back( ( geological_type_name ) );
249  }
250  }
251  };
252 
262  class RINGMESH_API RelationshipManager
263  {
264  friend class GeoModelBuilderGeology< 2 >;
265  friend class GeoModelBuilderTopologyBase< 2 >;
266  friend class GeoModelBuilderGeology< 3 >;
267  friend class GeoModelBuilderTopologyBase< 3 >;
268 
269  public:
271  std::map< GeologicalEntityType, MeshEntityType >;
272  using MeshEntityToParents =
273  std::map< MeshEntityType, std::set< GeologicalEntityType > >;
274 
275  std::vector< GeologicalEntityType > parent_types(
276  const MeshEntityType& child_type ) const;
277  index_t nb_parent_types( const MeshEntityType& child_type ) const;
278  const MeshEntityType child_type(
279  const GeologicalEntityType& parent_type ) const;
280 
286  const gmme_id& boundary_gmme( index_t relation_id ) const
287  {
288  ringmesh_assert( relation_id < boundary_relationships_.size() );
289  return boundary_relationships_[relation_id].boundary_id_;
290  }
291  const gmme_id& incident_entity_gmme( index_t relation_id ) const
292  {
293  ringmesh_assert( relation_id < boundary_relationships_.size() );
294  return boundary_relationships_[relation_id].incident_entity_id_;
295  }
296 
302  const gmge_id& parent_of_gmme( index_t relation_id ) const
303  {
304  ringmesh_assert( relation_id < parent_child_relationships_.size() );
305  return parent_child_relationships_[relation_id].parent_id_;
306  }
307  const gmme_id& child_of_gmge( index_t relation_id ) const
308  {
309  ringmesh_assert( relation_id < parent_child_relationships_.size() );
310  return parent_child_relationships_[relation_id].child_id_;
311  }
312 
313  private:
315  const GeologicalEntityType& parent_type_name,
316  const MeshEntityType& child_type_name )
317  {
318  parent_to_child_[parent_type_name] = child_type_name;
319  child_to_parents_[child_type_name].insert( parent_type_name );
320  }
321 
328  const gmme_id& incident_entity, const gmme_id& boundary )
329  {
330  index_t relationship_id{ static_cast< index_t >(
331  boundary_relationships_.size() ) };
332  boundary_relationships_.emplace_back( incident_entity, boundary );
333  return relationship_id;
334  }
335 
337  const gmme_id& incident_entity, const gmme_id& boundary )
338  {
339  return find( boundary_relationships_,
340  BoundaryRelationship( incident_entity, boundary ) );
341  }
342 
344  index_t relationship_id, const gmme_id& boundary )
345  {
346  boundary_relationships_[relationship_id].boundary_id_ = boundary;
347  }
348 
350 
351  index_t relationship_id, const gmme_id& incident_entity )
352  {
353  boundary_relationships_[relationship_id].incident_entity_id_ =
354  incident_entity;
355  }
356 
358  {
359  BoundaryRelationship( gmme_id incident_entity, gmme_id boundary )
360  : incident_entity_id_( std::move( incident_entity ) ),
361  boundary_id_( std::move( boundary ) )
362  {
363  }
364  bool operator==( const BoundaryRelationship& rhs ) const
365  {
366  return incident_entity_id_ == rhs.incident_entity_id_
367  && boundary_id_ == rhs.boundary_id_;
368  }
371  };
372 
379  const gmge_id& parent, const gmme_id& child )
380  {
381  index_t relationship_id{ static_cast< index_t >(
382  parent_child_relationships_.size() ) };
383  parent_child_relationships_.emplace_back( parent, child );
384  return relationship_id;
385  }
386 
388  const gmge_id& parent, const gmme_id& child )
389  {
390  return find( parent_child_relationships_,
391  ParentChildRelationship( parent, child ) );
392  }
393 
395  index_t relationship_id, const gmge_id& parent )
396  {
397  parent_child_relationships_[relationship_id].parent_id_ = parent;
398  }
399 
401  index_t relationship_id, const gmme_id& child )
402  {
403  parent_child_relationships_[relationship_id].child_id_ = child;
404  }
405 
407  {
409  : parent_id_( std::move( parent ) ),
410  child_id_( std::move( child ) )
411  {
412  }
413  bool operator==( const ParentChildRelationship& rhs ) const
414  {
415  return parent_id_ == rhs.parent_id_
416  && child_id_ == rhs.child_id_;
417  }
420  };
421 
422  private:
425 
426  std::deque< BoundaryRelationship > boundary_relationships_;
427  std::deque< ParentChildRelationship > parent_child_relationships_;
428  };
429 
434  template < index_t DIMENSION >
436  {
440  };
441 } // namespace RINGMesh
void set_incident_entity_to_boundary_relationship(index_t relationship_id, const gmme_id &incident_entity)
MeshEntityToParents child_to_parents_
void register_incident_entity(const MeshEntityType &type, const MeshEntityType &incident_entity)
bool operator==(const ParentChildRelationship &rhs) const
std::map< GeologicalEntityType, MeshEntityType > GeologicalEntityToChild
GeologicalTypeManager geological_entity_manager
this class contains methods to manage the type of the GeoModelGeologicalEntity. It gives access to th...
void register_geology_relationship(const GeologicalEntityType &parent_type_name, const MeshEntityType &child_type_name)
bool operator==(const BoundaryRelationship &rhs) const
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
Definition: entity_type.h:137
MeshEntityTypeBoundaryMap< DIMENSION > boundary_relationships_
void set_boundary_to_boundary_relationship(index_t relationship_id, const gmme_id &boundary)
index_t find_boundary_relationship(const gmme_id &incident_entity, const gmme_id &boundary)
GeologicalEntityToChild parent_to_child_
MeshEntityTypes< DIMENSION > mesh_entity_types_
std::vector< MeshEntityType > mesh_entity_types_
const std::vector< MeshEntityType > & container() const
std::map< MeshEntityType, std::set< GeologicalEntityType > > MeshEntityToParents
std::deque< ParentChildRelationship > parent_child_relationships_
MeshEntityTypeIncidentEntityMap< DIMENSION > incident_entity_relationships_
bool is_line(const MeshEntityType &type) const
ALIAS_2D_AND_3D(Box)
const gmme_id & boundary_gmme(index_t relation_id) const
index_t find_parent_child_relationship(const gmge_id &parent, const gmme_id &child)
RelationshipManager relationship_manager
MeshEntityTypeManager< DIMENSION > mesh_entity_manager
index_t add_parent_child_relationship(const gmge_id &parent, const gmme_id &child)
const gmge_id & parent_of_gmme(index_t relation_id) const
void register_geological_entity_type(const GeologicalEntityType &geological_type_name)
bool is_surface(const MeshEntityType &type) const
BoundaryRelationship(gmme_id incident_entity, gmme_id boundary)
FORWARD_DECLARATION_DIMENSION_STRUCT(EntityTypeManager)
index_t find(const container &in, const T &value)
Returns the position of the first entity matching.
Definition: algorithm.h:55
void register_boundary(const MeshEntityType &type, const MeshEntityType &boundary)
bool is_corner(const MeshEntityType &type) const
struct used to map the type of a Mesh Entity to the type of its incident mesh entity "Line" is incide...
const gmme_id & child_of_gmge(index_t relation_id) const
index_t add_boundary_relationship(const gmme_id &incident_entity, const gmme_id &boundary)
const std::vector< MeshEntityType > & mesh_entity_types() const
bool is_valid_type(const MeshEntityType &type) const
Global entity manager which could be associated to a geomodel to give access to different manager to ...
#define ringmesh_assert(x)
bool contains(const container &in, const T &value)
Definition: algorithm.h:87
const MeshEntityType & incident_entity_type(const MeshEntityType &mesh_entity_type) const
std::deque< BoundaryRelationship > boundary_relationships_
const MeshEntityType & boundary_entity_type(const MeshEntityType &mesh_entity_type) const
struct used to map the type of a Mesh Entity to the type of its boundary "Corner" is boundary of "Lin...
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
This template is a specialization of a gme_id to the GeoModelGeologicalEntity.
Definition: entity_type.h:262
this class contains methods to manage relations between Geological and Mesh entities. For instance: A "Contact" can be the parent of one or more "Line" An "Interface" can the parent of one or more "Surface" A "Layer" can be the parent of one or more "Region"
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
this class contains only static methods to manage the type of the GeoModelMeshEntity. It gives access to the number of meshed entities of each type and also their (in) boundary
void set_child_to_parent_child_relationship(index_t relationship_id, const gmme_id &child)
std::map< MeshEntityType, MeshEntityType > MeshEntityTypeMap
std::vector< GeologicalEntityType > geological_entity_types_
bool is_region(const MeshEntityType &type) const
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)
void set_parent_to_parent_child_relationship(index_t relationship_id, const gmge_id &parent)
const gmme_id & incident_entity_gmme(index_t relation_id) const