RINGMesh  Version 5.0.0
A programming library for geological model meshes
test-get-dependent-entities.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 
36 #include <ringmesh/ringmesh_tests_config.h>
37 
40 #include <ringmesh/io/io.h>
41 
47 using namespace RINGMesh;
48 
49 template < typename GME >
51  const std::set< GME >& to_compare,
52  const std::set< GME >& with,
53  const std::string& set_name )
54 {
55  if( to_compare != with )
56  {
57  // To debug it is nice to know which entity fails...
58  for( const GME& cur_gme_id : to_compare )
59  {
60  if( find( with.begin(), with.end(), cur_gme_id ) == with.end() )
61  {
62  throw RINGMeshException( "RINGMesh Test", cur_gme_id.type(),
63  " ", cur_gme_id.index(), " is not in the ", set_name, "." );
64  }
65  }
67  }
68 }
69 
70 void test_template( GeoModel3D& geomodel,
71  const std::set< gmme_id >& solution_gmme_id,
72  const std::set< gmge_id >& solution_gmge_id,
73  const std::string& to_insert_type,
74  index_t to_insert_id )
75 {
76  const GeoModelBuilder3D model_builder( geomodel );
77  std::set< gmme_id > in_mesh_entities;
78  std::set< gmge_id > in_geological_entities;
79 
80  const MeshEntityType mesh_type( to_insert_type );
81  if( geomodel.entity_type_manager().mesh_entity_manager.is_valid_type(
82  mesh_type ) )
83  {
84  in_mesh_entities.insert( { mesh_type, to_insert_id } );
85  }
86  else
87  {
88  const GeologicalEntityType geological_type( to_insert_type );
90  geomodel.entity_type_manager()
91  .geological_entity_manager.is_valid_type( geological_type ) );
92  in_geological_entities.insert( { geological_type, to_insert_id } );
93  }
94 
95  const GeoModelBuilder3D geomodel_builder( geomodel );
96  geomodel_builder.topology.get_dependent_entities(
97  in_mesh_entities, in_geological_entities );
98  check_element_of_a_set_are_in_another_set< gmme_id >(
99  in_mesh_entities, solution_gmme_id, "solution" );
100  check_element_of_a_set_are_in_another_set< gmge_id >(
101  in_geological_entities, solution_gmge_id, "solution" );
102  check_element_of_a_set_are_in_another_set< gmme_id >(
103  solution_gmme_id, in_mesh_entities, "output" );
104  check_element_of_a_set_are_in_another_set< gmge_id >(
105  solution_gmge_id, in_geological_entities, "output" );
106 }
107 
108 void test_on_top_region( GeoModel3D& geomodel )
109 {
110  // Solution:
111  // Corners: 31, 33, 54, 55, 56, 57, 58, 93, 118, 128, 129.
112  // Lines: 41, 43, 68, 69, 70, 71, 72, 73, 131, 135, 144, 177, 182, 203, 205,
113  // 207, 210, 233, 234, 238.
114  // Surfaces: 11, 37, 40, 60, 85, 91, 99, 110, 114.
115  // Region: 4.
116  std::set< gmme_id > solution_gmme_id = { { Corner3D::type_name_static(),
117  31 },
118  { Corner3D::type_name_static(), 33 },
119  { Corner3D::type_name_static(), 54 },
120  { Corner3D::type_name_static(), 55 },
121  { Corner3D::type_name_static(), 56 },
122  { Corner3D::type_name_static(), 57 },
123  { Corner3D::type_name_static(), 58 },
124  { Corner3D::type_name_static(), 93 },
125  { Corner3D::type_name_static(), 118 },
126  { Corner3D::type_name_static(), 128 },
127  { Corner3D::type_name_static(), 129 },
128  { Line3D::type_name_static(), 41 }, { Line3D::type_name_static(), 43 },
129  { Line3D::type_name_static(), 68 }, { Line3D::type_name_static(), 69 },
130  { Line3D::type_name_static(), 70 }, { Line3D::type_name_static(), 71 },
131  { Line3D::type_name_static(), 72 }, { Line3D::type_name_static(), 73 },
132  { Line3D::type_name_static(), 131 },
133  { Line3D::type_name_static(), 135 },
134  { Line3D::type_name_static(), 144 },
135  { Line3D::type_name_static(), 177 },
136  { Line3D::type_name_static(), 182 },
137  { Line3D::type_name_static(), 203 },
138  { Line3D::type_name_static(), 205 },
139  { Line3D::type_name_static(), 207 },
140  { Line3D::type_name_static(), 210 },
141  { Line3D::type_name_static(), 233 },
142  { Line3D::type_name_static(), 234 },
143  { Line3D::type_name_static(), 238 },
144  { Surface3D::type_name_static(), 11 },
145  { Surface3D::type_name_static(), 37 },
146  { Surface3D::type_name_static(), 40 },
147  { Surface3D::type_name_static(), 60 },
148  { Surface3D::type_name_static(), 85 },
149  { Surface3D::type_name_static(), 91 },
150  { Surface3D::type_name_static(), 99 },
151  { Surface3D::type_name_static(), 110 },
152  { Surface3D::type_name_static(), 114 },
153  { Region3D::type_name_static(), 4 } };
154 
155  // Solution:
156  // Contacts: 26, 27, 28, 78, 79, 83.
157  // Interface: 21.
158  // Layer: 0.
159  std::set< gmge_id > solution_gmge_id = {
160  { Contact3D::type_name_static(), 26 },
161  { Contact3D::type_name_static(), 27 },
162  { Contact3D::type_name_static(), 28 },
163  { Contact3D::type_name_static(), 78 },
164  { Contact3D::type_name_static(), 79 },
165  { Contact3D::type_name_static(), 83 },
166  { Interface3D::type_name_static(), 21 },
167  { Layer3D::type_name_static(), 0 },
168  };
169 
170  test_template( geomodel, solution_gmme_id, solution_gmge_id,
171  Region3D::type_name_static().string(), 4 );
172 }
173 
175  GeoModel3D& geomodel )
176 {
177  // Solution:
178  // Corner: none.
179  // Line: 98.
180  // Surface: 24.
181  // Region: none.
182  std::set< gmme_id > solution_gmme_id = { { Line3D::type_name_static(), 98 },
183  { Surface3D::type_name_static(), 24 } };
184 
185  // Solution:
186  // Contact: 36.
187  // Interface: 3.
188  // Layer: none.
189  std::set< gmge_id > solution_gmge_id = { { Contact3D::type_name_static(),
190  36 },
191  { Interface3D::type_name_static(), 3 } };
192 
193  test_template( geomodel, solution_gmme_id, solution_gmge_id,
194  Surface3D::type_name_static().string(), 24 );
195 }
196 
197 void test_on_fault_not_connected_to_any_surface( GeoModel3D& geomodel )
198 {
199  // Solution:
200  // Corner: none.
201  // Lines: 163, 165, 166, 168.
202  // Surfaces: 52, 53, 54, 55, 56, 57.
203  // Region: none.
204  std::set< gmme_id > solution_gmme_id = { { Line3D::type_name_static(),
205  163 },
206  { Line3D::type_name_static(), 165 },
207  { Line3D::type_name_static(), 166 },
208  { Line3D::type_name_static(), 168 },
209  { Surface3D::type_name_static(), 52 },
210  { Surface3D::type_name_static(), 53 },
211  { Surface3D::type_name_static(), 54 },
212  { Surface3D::type_name_static(), 55 },
213  { Surface3D::type_name_static(), 56 },
214  { Surface3D::type_name_static(), 57 } };
215 
216  // Solution:
217  // Contact: 55.
218  // Interface: 8.
219  // Layer: none.
220  std::set< gmge_id > solution_gmge_id = { { Contact3D::type_name_static(),
221  55 },
222  { Interface3D::type_name_static(), 8 } };
223 
224  test_template( geomodel, solution_gmme_id, solution_gmge_id,
225  Interface3D::type_name_static().string(), 8 );
226 }
227 
228 void test_on_corner_on_botom_corner_voi( GeoModel3D& geomodel )
229 {
230  // Solution:
231  // Corner: 135.
232  // Line: none.
233  // Surface: none.
234  // Region: none.
235  std::set< gmme_id > solution_gmme_id = { { Corner3D::type_name_static(),
236  135 } };
237 
238  // Solution:
239  // Contact: none.
240  // Interface: none.
241  // Layer: none.
242  std::set< gmge_id > solution_gmge_id;
243 
244  test_template( geomodel, solution_gmme_id, solution_gmge_id,
245  Corner3D::type_name_static().string(), 135 );
246 }
247 
248 void test_on_top_layer( GeoModel3D& geomodel )
249 {
250  // Solution:
251  // Corners: 31, 33, 54, 55, 56, 57, 58, 93, 118, 128, 129.
252  // Lines: 41, 43, 68, 69, 70, 71, 72, 73, 131, 135, 144, 177, 182, 203, 205,
253  // 207, 210, 233, 234, 238.
254  // Surfaces: 11, 37, 40, 60, 85, 91, 99, 110, 114.
255  // Region: 4.
256  std::set< gmme_id > solution_gmme_id = { { Corner3D::type_name_static(),
257  31 },
258  { Corner3D::type_name_static(), 33 },
259  { Corner3D::type_name_static(), 54 },
260  { Corner3D::type_name_static(), 55 },
261  { Corner3D::type_name_static(), 56 },
262  { Corner3D::type_name_static(), 57 },
263  { Corner3D::type_name_static(), 58 },
264  { Corner3D::type_name_static(), 93 },
265  { Corner3D::type_name_static(), 118 },
266  { Corner3D::type_name_static(), 128 },
267  { Corner3D::type_name_static(), 129 },
268  { Line3D::type_name_static(), 41 }, { Line3D::type_name_static(), 43 },
269  { Line3D::type_name_static(), 68 }, { Line3D::type_name_static(), 69 },
270  { Line3D::type_name_static(), 70 }, { Line3D::type_name_static(), 71 },
271  { Line3D::type_name_static(), 72 }, { Line3D::type_name_static(), 73 },
272  { Line3D::type_name_static(), 131 },
273  { Line3D::type_name_static(), 135 },
274  { Line3D::type_name_static(), 144 },
275  { Line3D::type_name_static(), 177 },
276  { Line3D::type_name_static(), 182 },
277  { Line3D::type_name_static(), 203 },
278  { Line3D::type_name_static(), 205 },
279  { Line3D::type_name_static(), 207 },
280  { Line3D::type_name_static(), 210 },
281  { Line3D::type_name_static(), 233 },
282  { Line3D::type_name_static(), 234 },
283  { Line3D::type_name_static(), 238 },
284  { Surface3D::type_name_static(), 11 },
285  { Surface3D::type_name_static(), 37 },
286  { Surface3D::type_name_static(), 40 },
287  { Surface3D::type_name_static(), 60 },
288  { Surface3D::type_name_static(), 85 },
289  { Surface3D::type_name_static(), 91 },
290  { Surface3D::type_name_static(), 99 },
291  { Surface3D::type_name_static(), 110 },
292  { Surface3D::type_name_static(), 114 },
293  { Region3D::type_name_static(), 4 } };
294 
295  // Solution:
296  // Contacts: 26, 27, 28, 78, 79, 83.
297  // Interface: 21.
298  // Layer: 0.
299  std::set< gmge_id > solution_gmge_id = {
300  { Contact3D::type_name_static(), 26 },
301  { Contact3D::type_name_static(), 27 },
302  { Contact3D::type_name_static(), 28 },
303  { Contact3D::type_name_static(), 78 },
304  { Contact3D::type_name_static(), 79 },
305  { Contact3D::type_name_static(), 83 },
306  { Interface3D::type_name_static(), 21 },
307  { Layer3D::type_name_static(), 0 },
308  };
309 
310  test_template( geomodel, solution_gmme_id, solution_gmge_id,
311  Layer3D::type_name_static().string(), 0 );
312 }
313 
314 void run_tests( GeoModel3D& geomodel )
315 {
316  test_on_top_region( geomodel );
320  test_on_top_layer( geomodel ); // Should be the same as test_on_top_region
321 }
322 
323 void load_geomodel( GeoModel3D& geomodel )
324 {
325  std::string file_name{ ringmesh_test_data_path };
326  file_name += "CloudSpin_fixed.ml";
327 
328  // Load the model
329  auto init_model_is_valid = geomodel_load( geomodel, file_name );
330  if( !init_model_is_valid )
331  {
332  throw RINGMeshException( "RINGMesh Test", "Input test model ",
333  geomodel.name(), " must be valid." );
334  }
335 }
336 
337 int main()
338 {
339  try
340  {
342  Logger::out(
343  "TEST", "Test GeoModelBuilderTopology::get_dependent_entities" );
344 
345  GeoModel3D geomodel;
346  load_geomodel( geomodel );
347  run_tests( geomodel );
348  }
349  catch( const RINGMeshException& e )
350  {
351  Logger::err( e.category(), e.what() );
352  return 1;
353  }
354  catch( const std::exception& e )
355  {
356  Logger::err( "Exception", e.what() );
357  return 1;
358  }
359  Logger::out( "TEST", "SUCCESS" );
360  return 0;
361 }
void test_on_fault_not_connected_to_any_surface(GeoModel3D &geomodel)
void run_tests(GeoModel3D &geomodel)
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
Definition: entity_type.h:137
void check_element_of_a_set_are_in_another_set(const std::set< GME > &to_compare, const std::set< GME > &with, const std::string &set_name)
void test_on_top_region(GeoModel3D &geomodel)
bool geomodel_load(GeoModel< DIMENSION > &geomodel, const std::string &filename)
Definition: io.cpp:131
void test_template(GeoModel3D &geomodel, const std::set< gmme_id > &solution_gmme_id, const std::set< gmge_id > &solution_gmge_id, const std::string &to_insert_type, index_t to_insert_id)
index_t find(const container &in, const T &value)
Returns the position of the first entity matching.
Definition: algorithm.h:55
static void err(const std::string &feature, const Args &... args)
Definition: logger.h:68
void test_on_corner_on_botom_corner_voi(GeoModel3D &geomodel)
static void out(const std::string &feature, const Args &... args)
Definition: logger.h:61
void test_on_top_layer(GeoModel3D &geomodel)
void test_on_surface_within_bottom_region_partially_connected_to_voi(GeoModel3D &geomodel)
void load_geomodel(GeoModel3D &geomodel)
#define ringmesh_assert(x)
const std::string & category() const
Definition: common.h:165
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
void RINGMESH_API default_configure()
Definition: common.cpp:99
#define ringmesh_assert_not_reached