RINGMesh  Version 5.0.0
A programming library for geological model meshes
test-stratigraphic-column.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 <iostream>
37 #include <ringmesh/basic/common.h>
42 #include <ringmesh/io/io.h>
43 #include <ringmesh/ringmesh_tests_config.h>
44 
45 using namespace RINGMesh;
46 
48 {
50  "RockFeature", "Test RockFeature building and editing" );
51 
52  RockFeature rock( "rock", ROCKTYPE::NONE );
53  if( rock.get_rock_type() != ROCKTYPE::NONE )
54  {
55  throw RINGMeshException(
56  "Test", "Failed when testing RockFeature::get_rock_type()" );
57  }
59  if( rock.get_rock_type() != ROCKTYPE::MULTIPLE )
60  {
61  throw RINGMeshException(
62  "Test", "Failed when changing RockFeature type" );
63  }
64 
65  RockFeature rock_two( "rock2" );
66  if( rock_two.get_name() != "rock2" )
67  {
68  throw RINGMeshException(
69  "Test", "Failed when testing RockFeature::get_name() " );
70  }
71  rock_two.set_name( "rock2_renamed" );
72  if( rock_two.get_name() != "rock2_renamed" )
73  {
74  throw RINGMeshException(
75  "Test", "Failed when renaming the RockFeature" );
76  }
77 }
78 
79 void test_stratigraphic_unit( const GeoModel3D& in )
80 {
82  "StratigraphicUnit", "Test StratigraphicUnit building" );
83 
84  RockFeature rock( "rock", ROCKTYPE::NONE );
85  UnsubdividedStratigraphicUnit test_strat_unit( "strat unit",
86  dynamic_cast< const Interface3D& >(
87  in.geological_entity( Interface3D::type_name_static(), 1 ) ),
88  dynamic_cast< const Interface3D& >(
89  in.geological_entity( Interface3D::type_name_static(), 0 ) ),
90  dynamic_cast< const Layer3D& >(
91  in.geological_entity( Layer3D::type_name_static(), 0 ) ),
93  if( test_strat_unit.get_name() != "strat unit" )
94  {
95  throw RINGMeshException(
96  "Test", "Failed when testing StratigraphicUnit::get_name()" );
97  }
98  if( !test_strat_unit.is_conformable_base() )
99  {
100  throw RINGMeshException( "Test",
101  "Failed when testing StratigraphicUnit::is_conformable_base()" );
102  }
103  if( !test_strat_unit.is_conformable_top() )
104  {
105  throw RINGMeshException( "Test",
106  "Failed when testing StratigraphicUnit::is_conformable_top()" );
107  }
108 
109  if( test_strat_unit.get_relation_base() != RELATION::CONFORMABLE )
110  {
111  throw RINGMeshException( "Test",
112  "Failed when testing StratigraphicUnit::get_relation_base()" );
113  }
114  if( test_strat_unit.get_relation_top() != RELATION::CONFORMABLE )
115  {
116  throw RINGMeshException( "Test",
117  "Failed when testing StratigraphicUnit::get_relation_top()" );
118  }
119  if( test_strat_unit.get_min_thick() != 0 )
120  {
121  throw RINGMeshException(
122  "Test", "Failed when testing StratigraphicUnit::get_min_thick()" );
123  }
124  if( test_strat_unit.get_max_thick() != 10 )
125  {
126  throw RINGMeshException(
127  "Test", "Failed when testing StratigraphicUnit::get_max_thick()" );
128  }
129 }
130 
131 void test_stratigraphic_column_building( const GeoModel3D& in )
132 {
134  "StratigraphicColumn", "Test StratigraphicColumn building" );
136  "StratigraphicColumn", "Init RockFeature and StratigraphicUnit" );
137 
138  RockFeature rock( "rock", ROCKTYPE::NONE );
139 
140  std::string one_name = "one";
141  std::string two_name = "two";
142  std::string three_name = "three";
143  std::string four_name = "four";
144 
145  UnsubdividedStratigraphicUnit one( one_name,
146  dynamic_cast< const Interface3D& >(
147  in.geological_entity( Interface3D::type_name_static(), 1 ) ),
148  dynamic_cast< const Interface3D& >(
149  in.geological_entity( Interface3D::type_name_static(), 0 ) ),
150  dynamic_cast< const Layer3D& >(
151  in.geological_entity( Layer3D::type_name_static(), 0 ) ),
153  UnsubdividedStratigraphicUnit two( two_name,
154  dynamic_cast< const Interface3D& >(
155  in.geological_entity( Interface3D::type_name_static(), 2 ) ),
156  dynamic_cast< const Interface3D& >(
157  in.geological_entity( Interface3D::type_name_static(), 1 ) ),
158  dynamic_cast< const Layer3D& >(
159  in.geological_entity( Layer3D::type_name_static(), 1 ) ),
161  UnsubdividedStratigraphicUnit three( three_name,
162  dynamic_cast< const Interface3D& >(
163  in.geological_entity( Interface3D::type_name_static(), 3 ) ),
164  dynamic_cast< const Interface3D& >(
165  in.geological_entity( Interface3D::type_name_static(), 2 ) ),
166  dynamic_cast< const Layer3D& >(
167  in.geological_entity( Layer3D::type_name_static(), 2 ) ),
169  UnsubdividedStratigraphicUnit four( four_name,
170  dynamic_cast< const Interface3D& >(
171  in.geological_entity( Interface3D::type_name_static(), 11 ) ),
172  dynamic_cast< const Interface3D& >(
173  in.geological_entity( Interface3D::type_name_static(), 3 ) ),
174  dynamic_cast< const Layer3D& >(
175  in.geological_entity( Layer3D::type_name_static(), 3 ) ),
177 
178  RINGMesh::Logger::out( "StratigraphicColumn",
179  "First building with a vector of StratigraphicUnit" );
180 
181  std::vector< const StratigraphicUnit* > units;
182  units.push_back( &one );
183  units.push_back( &two );
184  units.push_back( &three );
185  units.push_back( &four );
186 
187  StratigraphicColumn test1(
189  if( test1.get_unit_above( two )->get_name() != "one" )
190  {
191  throw RINGMeshException( "Test",
192  "Failed when testing StratigraphicColumn::get_unit_above()" );
193  }
194 
195  if( test1.get_unit_below( three )->get_name() != "four" )
196  {
197  throw RINGMeshException( "Test",
198  "Failed when testing StratigraphicColumn::get_unit_below()" );
199  }
200 
201  test1.remove_unit( two );
202  if( test1.get_unit( 1 )->get_name() != "three" )
203  {
204  throw RINGMeshException(
205  "Test", "Failed when testing StratigraphicColumn::remove_unit()" );
206  }
207 
208  test1.insert_unit_below( one, two );
209  if( test1.get_unit( 1 )->get_name() != "two" )
210  {
211  throw RINGMeshException( "Test",
212  "Failed when testing StratigraphicColumn::insert_unit_below()" );
213  }
214 
215  if( test1.get_top_unit()->get_name() != "one" )
216  {
217  throw RINGMeshException(
218  "Test", "Failed when testing StratigraphicColumn::get_top_unit()" );
219  };
220 
221  if( test1.get_base_unit()->get_name() != "four" )
222  {
223  throw RINGMeshException( "Test",
224  "Failed when testing StratigraphicColumn::get_base_unit()" );
225  }
226 
227  RINGMesh::Logger::out( "StratigraphicColumn",
228  "Second building with a vector of StratigraphicUnit" );
229 
230  StratigraphicColumn test2(
232 
233  test2.insert_top_unit( one );
234  if( test2.get_top_unit()->get_name() != "one" )
235  {
236  throw RINGMeshException( "Test",
237  "Failed when testing StratigraphicColumn::insert_top_unit()" );
238  }
239 
240  test2.insert_base_unit( four );
241  if( test2.get_base_unit()->get_name() != "four" )
242  {
243  throw RINGMeshException( "Test",
244  "Failed when testing StratigraphicColumn::insert_base_unit()" );
245  }
246 
247  if( test2.get_unit( "one" )->get_name() != "one" )
248  {
249  throw RINGMeshException(
250  "Test", "Failed when testing StratigraphicColumn::get_unit()" );
251  }
252 
254  "StratigraphicColumn", "Third building a mixed StratigraphicColumn" );
255 
256  std::vector< const StratigraphicUnit* > mixed;
257  mixed.push_back( &one );
258  mixed.push_back( &two );
259  std::vector< const StratigraphicUnit* > sub_units;
260  RockFeature rocks( "several", ROCKTYPE::MULTIPLE );
261  sub_units.push_back( &three );
262  sub_units.push_back( &four );
263  SubdividedStratigraphicUnit subdivided_unit(
264  "subdivided", rocks, sub_units );
265  mixed.push_back( &subdivided_unit );
266 
269  if( !mix.is_conformable_base() )
270  {
271  throw RINGMeshException( "Test",
272  "Failed when testing StratigraphicColumn::is_conformable_base()" );
273  }
274 
275  if( !mix.is_conformable_top() )
276  {
277  throw RINGMeshException( "Test",
278  "Failed when testing StratigraphicColumn::is_conformable_top()" );
279  }
280 
282  {
283  throw RINGMeshException( "Test",
284  "Failed when testing StratigraphicColumn::get_relation_base()" );
285  }
286 
288  {
289  throw RINGMeshException( "Test",
290  "Failed when testing StratigraphicColumn::get_relation_top()" );
291  }
292 
293  if( mix.get_column_min_thick() != 0 )
294  {
295  throw RINGMeshException( "Test",
296  "Failed when testing StratigraphicColumn::get_column_min_thick()" );
297  }
298 
299  if( mix.get_column_max_thick() != 100 )
300  {
301  throw RINGMeshException( "Test",
302  "Failed when testing StratigraphicColumn::get_column_max_thick()" );
303  }
304 
305  if( mix.get_unit_above( two )->get_name() != "one" )
306  {
307  throw RINGMeshException( "Test",
308  "Failed when testing StratigraphicColumn::get_unit_above()" );
309  }
310 
311  if( mix.get_unit_below( two )->get_name() != "subdivided" )
312  {
313  throw RINGMeshException( "Test",
314  "Failed when testing StratigraphicColumn::get_unit_below()" );
315  }
316 
317  mix.remove_unit( two );
318  if( mix.get_unit( 1 )->get_name() != "subdivided" )
319  {
320  throw RINGMeshException(
321  "Test", "Failed when testing StratigraphicColumn::remove_unit()" );
322  }
323 
324  mix.insert_unit_below( one, two );
325  if( mix.get_unit( 1 )->get_name() != "two" )
326  {
327  throw RINGMeshException( "Test",
328  "Failed when testing StratigraphicColumn::insert_unit_below()" );
329  }
330 
331  if( mix.get_top_unit()->get_name() != "one" )
332  {
333  throw RINGMeshException(
334  "Test", "Failed when testing StratigraphicColumn::get_top_unit()" );
335  }
336 
337  if( mix.get_base_unit()->get_name() != "subdivided" )
338  {
339  throw RINGMeshException( "Test",
340  "Failed when testing StratigraphicColumn::get_base_unit()" );
341  }
342 }
343 
345 {
346  std::string input_geomodel_file_name( ringmesh_test_data_path );
347  input_geomodel_file_name += "CloudSpin_fixed.ml";
348  GeoModel3D in;
349  geomodel_load( in, input_geomodel_file_name );
350 
351  std::string input_column_file_name( RINGMesh::ringmesh_test_data_path );
352  input_column_file_name += "CloudSpin.xml";
353 
355 
357  column, in, input_column_file_name );
358  sc_builder.load_file();
359 }
360 
361 int main()
362 {
363  using namespace RINGMesh;
364 
365  try
366  {
368 
369  // Set an output log file
370  std::string log_file( ringmesh_test_output_path );
371  log_file += "log.txt";
372  GEO::FileLogger* file_logger = new GEO::FileLogger( log_file );
373  Logger::instance()->register_client( file_logger );
374 
375  // build geomodel
376  std::string input_model_file_name( ringmesh_test_data_path );
377  input_model_file_name += "CloudSpin_fixed.ml";
378  GeoModel3D in;
379  geomodel_load( in, input_model_file_name );
380 
381  // test RockFeature
383 
384  // test Stratigraphic Unit building
386 
387  // test StratigraphicColumn building
389 
390  // load StratigraphicColumn from gocad XML file
392  }
393  catch( const RINGMeshException& e )
394  {
395  Logger::err( e.category(), e.what() );
396  return 1;
397  }
398  catch( const std::exception& e )
399  {
400  Logger::err( "Exception", e.what() );
401  return 1;
402  }
403  Logger::out( "TEST", "SUCCESS" );
404  return 0;
405 }
void test_stratigraphic_unit(const GeoModel3D &in)
const StratigraphicUnit * get_base_unit() const
RELATION get_relation_base()
get_relation_base for the Stratigraphic Column
RELATION get_relation_top()
get_relation_top for the Stratigraphic Column
Manages the RockFeature, which contains a RockType and more informations.
void insert_top_unit(const StratigraphicUnit &to_add)
Declarations of a stratigraphic column, stratigraphic unit, rock features and so on.
const StratigraphicUnit * get_unit(const index_t index) const
void set_name(const std::string &name)
void test_rock_feature()
const StratigraphicUnit * get_unit_below(const StratigraphicUnit &unit) const
void remove_unit(const StratigraphicUnit &unit)
void test_load_from_gocad_xml_file()
virtual const std::string & get_name() const
const StratigraphicUnit * get_unit_above(const StratigraphicUnit &unit) const
bool geomodel_load(GeoModel< DIMENSION > &geomodel, const std::string &filename)
Definition: io.cpp:131
static void err(const std::string &feature, const Args &... args)
Definition: logger.h:68
static void out(const std::string &feature, const Args &... args)
Definition: logger.h:61
static GEO::Logger * instance()
Definition: logger.h:81
A stratigraphic column is composed of several stratigraphic units.
const ROCKTYPE & get_rock_type() const
void test_stratigraphic_column_building(const GeoModel3D &in)
void set_rock_type(ROCKTYPE type)
bool is_conformable_base() const
is_conformable_base for the Stratigraphic Column
const std::string & category() const
Definition: common.h:165
const std::string & get_name() const
void insert_base_unit(const StratigraphicUnit &to_add)
bool is_conformable_top() const
is_conformable_top for the Stratigraphic Column
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
void insert_unit_below(const StratigraphicUnit &above, const StratigraphicUnit &unit_to_add)
void RINGMESH_API default_configure()
Definition: common.cpp:99
const StratigraphicUnit * get_top_unit() const