RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_geological_entity.cpp
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 
42 
45 
46 namespace
47 {
48  using namespace RINGMesh;
49 
50  template < index_t DIMENSION >
51  bool check_has_children( const GeoModelGeologicalEntity< DIMENSION >& E )
52  {
53  if( E.nb_children() == 0 )
54  {
56  "GeoModel", E.type_name(), " ", E.index(), " has no children" );
57  return false;
58  }
59  return true;
60  }
61 }
62 
63 namespace RINGMesh
64 {
65  template < index_t DIMENSION >
68  const std::string& in )
69  {
70  if( in == "reverse_fault" )
71  {
72  return GEOL_FEATURE::REVERSE_FAULT;
73  }
74  else if( in == "normal_fault" )
75  {
76  return GEOL_FEATURE::NORMAL_FAULT;
77  }
78  else if( in == "fault" )
79  {
80  return GEOL_FEATURE::FAULT;
81  }
82  else if( in == "top" )
83  {
84  return GEOL_FEATURE::STRATI;
85  }
86  else if( in == "none" )
87  {
88  // This might seem strange - but it seems that what's
89  // Gocad is doing
90  return GEOL_FEATURE::STRATI;
91  }
92  else if( in == "topographic" )
93  {
94  return GEOL_FEATURE::STRATI;
95  }
96  else if( in == "unconformity" )
97  {
98  return GEOL_FEATURE::UNCONFORMITY;
99  }
100  else if( in == "boundary" )
101  {
102  return GEOL_FEATURE::VOI;
103  }
104  else if( in == "lease" )
105  {
106  return GEOL_FEATURE::VOI;
107  }
108  else
109  {
110  // Default case - no information
111  return GEOL_FEATURE::NO_GEOL;
112  }
113  }
114 
115  template < index_t DIMENSION >
118  {
119  switch( feature )
120  {
121  case GEOL_FEATURE::STRATI:
122  return "top";
123  case GEOL_FEATURE::FAULT:
124  return "fault";
125  case GEOL_FEATURE::REVERSE_FAULT:
126  return "reverse_fault";
127  case GEOL_FEATURE::NORMAL_FAULT:
128  return "normal_fault";
129  case GEOL_FEATURE::UNCONFORMITY:
130  return "unconformity";
131  case GEOL_FEATURE::VOI:
132  return "boundary";
133  case GEOL_FEATURE::NO_GEOL:
134  return "no_geological_feature";
135  default:
136  return "no_geological_feature";
137  break;
138  }
139  }
140 
141  template < index_t DIMENSION >
144  {
145  return feature == GEOL_FEATURE::FAULT
146  || feature == GEOL_FEATURE::REVERSE_FAULT
147  || feature == GEOL_FEATURE::NORMAL_FAULT;
148  }
149 
150  template < index_t DIMENSION >
152  index_t x ) const
153  {
154  ringmesh_assert( x < nb_children() );
155  return this->geomodel()
156  .entity_type_manager()
157  .relationship_manager.child_of_gmge( children_[x] );
158  }
159 
160  template < index_t DIMENSION >
163  {
164  return this->geomodel().mesh_entity( child_gmme( x ) );
165  }
166 
167  template < index_t DIMENSION >
169  {
170  for( auto i : range( nb_children() ) )
171  {
172  if( !child( i ).is_on_voi() )
173  {
174  return false;
175  }
176  }
177  return true;
178  }
179 
180  template < index_t DIMENSION >
182  {
183  return this->index()
184  < this->geomodel().nb_geological_entities( type_name() );
185  }
186 
187  template < index_t DIMENSION >
189  {
190  bool valid = true;
191  if( nb_children() == 0 )
192  {
193  Logger::warn(
194  "GeologicalEntity", gmge(), " is undefined. No child. " );
195  valid = false;
196  }
197  else
198  {
199  // All children must have this entity as a parent
200  const GeologicalEntityType entity_type = type_name();
201  for( auto i : range( nb_children() ) )
202  {
203  const GeoModelMeshEntity< DIMENSION >& one_child = child( i );
204  if( one_child.parent_gmge( entity_type ) != gmge() )
205  {
206  Logger::warn( "GeoModelEntity",
207  "Inconsistency child-parent between ", gmge(), " and ",
208  one_child.gmme() );
209  valid = false;
210  }
211  }
212  }
213  return valid;
214  }
215 
216  template < index_t DIMENSION >
218  {
219  bool is_valid = true;
220  if( !gmge().is_defined() )
221  {
222  Logger::err( "GeoModelGeologicalEntity",
223  " Entity associated to geomodel ", this->geomodel().name(),
224  "has no type and/or no index " );
225  is_valid = false;
226  // No further checks are possible - This really should not happen
228  }
229  if( !is_index_valid() )
230  {
231  Logger::warn( "GeoModelGeologicalEntity", " Entity index ", gmge(),
232  " is not valid. " );
233  // This really should not happen
234  is_valid = false;
236  }
237  return is_valid;
238  }
239 
240  template < index_t DIMENSION >
242  {
243  return check_has_children( *this );
244  }
245 
246  template <>
248  {
249  GeoModelGeologicalEntityFactory2D::register_creator< Contact2D >(
250  Contact2D::type_name_static() );
251  GeoModelGeologicalEntityFactory2D::register_creator< Interface2D >(
252  Interface2D::type_name_static() );
253  GeoModelGeologicalEntityFactory2D::register_creator< Layer2D >(
254  Layer2D::type_name_static() );
255  }
256 
257  template <>
259  {
260  GeoModelGeologicalEntityFactory3D::register_creator< Contact3D >(
261  Contact3D::type_name_static() );
262  GeoModelGeologicalEntityFactory3D::register_creator< Interface3D >(
263  Interface3D::type_name_static() );
264  GeoModelGeologicalEntityFactory3D::register_creator< Layer3D >(
265  Layer3D::type_name_static() );
266  }
267 
268  template <>
270  {
271  return Corner2D::type_name_static();
272  }
273 
274  template <>
276  {
277  return Line2D::type_name_static();
278  }
279 
280  template <>
282  {
283  return Surface2D::type_name_static();
284  }
285 
286  template <>
288  {
289  return Line3D::type_name_static();
290  }
291 
292  template <>
294  {
295  return Surface3D::type_name_static();
296  }
297 
298  template <>
300  {
301  return Region3D::type_name_static();
302  }
303 
304  template < index_t DIMENSION >
305  std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > >
307  const GeologicalEntityType& type,
308  const GeoModel< DIMENSION >& geomodel,
309  index_t index_in_geomodel )
310  {
312  type, geomodel );
313  GMGE->id_ = index_in_geomodel;
314  return GMGE;
315  }
316 
317  template class RINGMESH_API GeoModelGeologicalEntity< 2 >;
318  template class RINGMESH_API GeoModelGeologicalEntityAccess< 2 >;
319 
320  template class RINGMESH_API GeoModelGeologicalEntity< 3 >;
321  template class RINGMESH_API GeoModelGeologicalEntityAccess< 3 >;
322 
323 } // namespace RINGMesh
const GeoModelMeshEntity< DIMENSION > & child(index_t x) const
Abstract base class for GeoModelMeshEntity.
static std::unique_ptr< BaseClass > create(const Key &key, const Args &... args)
Definition: factory.h:85
MeshEntityType child_type_name() const override
virtual GeologicalEntityType type_name() const
static std::string geol_name(GEOL_FEATURE feature)
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
Definition: entity_type.h:137
static void warn(const std::string &feature, const Args &... args)
Definition: logger.h:75
static std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > create_geological_entity(const GeologicalEntityType &type, const GeoModel< DIMENSION > &geomodel, index_t index_in_geomodel)
GEOL_FEATURE
Geological feature types for GeoModelEntity.
const gmge_id & parent_gmge(index_t id) const
static void err(const std::string &feature, const Args &... args)
Definition: logger.h:68
const gmme_id & child_gmme(index_t x) const
MeshEntityType child_type_name() const override
static bool is_fault(GEOL_FEATURE feature)
#define ringmesh_assert(x)
MeshEntityType child_type_name() const override
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
static GEOL_FEATURE determine_geological_type(const std::string &in)
Map the name of a geological type with a value of GEOL_FEATURE.
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
#define ringmesh_assert_not_reached