RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_builder_topology.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 
42 
49 namespace RINGMesh
50 {
51  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderBase );
52  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilder );
53 
54  ALIAS_2D_AND_3D( GeoModelBuilder );
55 } // namespace RINGMesh
56 
57 namespace RINGMesh
58 {
59  template < index_t DIMENSION >
60  class RINGMESH_API GeoModelBuilderTopologyBase
61  {
64  friend class GeoModelBuilderBase< DIMENSION >;
65  friend class GeoModelBuilder< DIMENSION >;
66 
67  public:
68  virtual ~GeoModelBuilderTopologyBase() = default;
75  void copy_topology( const GeoModel< DIMENSION >& from );
76 
90  bool get_dependent_entities( std::set< gmme_id >& mesh_entities,
91  std::set< gmge_id >& geological_entities ) const;
92 
93  virtual gmme_id create_mesh_entity( const MeshEntityType& type );
94 
95  virtual bool create_mesh_entities(
96  const MeshEntityType& type, index_t nb_additional_entities );
97 
98  void remove_mesh_entity_boundary_relation(
99  const gmme_id& incident_entity, const gmme_id& boundary );
100 
101  virtual void add_mesh_entity_boundary_relation(
102  const gmme_id& incident_entity_id,
103  const gmme_id& boundary_id,
104  bool side = false );
105 
106  virtual void set_mesh_entity_boundary( const gmme_id& gmme,
107  index_t id,
108  index_t boundary_id,
109  bool side = false );
110 
111  void set_mesh_entity_incident_entity(
112  const gmme_id& gmme, index_t id, index_t incident_entity_id );
113 
114  void delete_mesh_entity( const MeshEntityType& type, index_t index );
115 
121  gmme_id find_or_create_corner( const vecn< DIMENSION >& point );
122  gmme_id find_or_create_corner( index_t geomodel_point_id );
123 
129  gmme_id find_or_create_line(
130  const std::vector< vecn< DIMENSION > >& vertices );
131 
135  gmme_id find_or_create_line(
136  const std::vector< index_t >& sorted_adjacent_surfaces,
137  const gmme_id& first_corner,
138  const gmme_id& second_corner );
139 
140  protected:
142  GeoModel< DIMENSION >& geomodel );
143 
144  template < template < index_t > class ENTITY >
145  gmme_id create_mesh_entity( const MeshType& mesh_type = "" );
146 
147  template < template < index_t > class ENTITY >
148  bool create_mesh_entities(
149  index_t nb_additionnal_entities, const MeshType& type = "" );
150 
151  template < template < index_t > class ENTITY >
153  {
154  const MeshEntityType& type =
155  ENTITY< DIMENSION >::type_name_static();
156  create_mesh_entities< ENTITY >( from.nb_mesh_entities( type ) );
157 
158  parallel_for( geomodel_.nb_mesh_entities( type ),
159  [&type, &from, this]( index_t i ) {
160  gmme_id id( type, i );
162  geomodel_access_.modifiable_mesh_entity( id ) );
163  gmme_access.copy( from.mesh_entity( id ) );
164  } );
165  }
166 
167  index_t check_if_boundary_incident_entity_relation_already_exists(
168  const gmme_id& incident_entity, const gmme_id& boundary );
169 
170  virtual void copy_all_mesh_entity_topology(
171  const GeoModel< DIMENSION >& from );
172 
173  protected:
177  };
178 
180 
181  template < index_t DIMENSION >
182  class RINGMESH_API GeoModelBuilderTopology
183  : public GeoModelBuilderTopologyBase< DIMENSION >
184  {
185  };
186 
187  template <>
188  class RINGMESH_API GeoModelBuilderTopology< 2 >
189  : public GeoModelBuilderTopologyBase< 2 >
190  {
191  friend class GeoModelBuilderBase< 2 >;
192  friend class GeoModelBuilder< 2 >;
193 
194  public:
195  void add_mesh_entity_boundary_relation(
196  const gmme_id& incident_entity_id,
197  const gmme_id& boundary_id,
198  bool side = false ) override;
199 
200  void set_mesh_entity_boundary( const gmme_id& gmme,
201  index_t id,
202  index_t boundary_id,
203  bool side = false ) override;
204 
205  private:
207  GeoModelBuilder2D& builder, GeoModel2D& geomodel )
208  : GeoModelBuilderTopologyBase< 2 >( builder, geomodel )
209  {
210  }
211  };
212 
213  template <>
214  class RINGMESH_API GeoModelBuilderTopology< 3 >
215  : public GeoModelBuilderTopologyBase< 3 >
216  {
217  friend class GeoModelBuilderBase< 3 >;
218  friend class GeoModelBuilder< 3 >;
219 
220  public:
221  gmme_id create_mesh_entity( const MeshEntityType& type ) override;
222 
223  bool create_mesh_entities( const MeshEntityType& type,
224  index_t nb_additional_entities ) override;
225 
226  void add_mesh_entity_boundary_relation(
227  const gmme_id& incident_entity_id,
228  const gmme_id& boundary_id,
229  bool side = false ) override;
230 
231  void set_mesh_entity_boundary( const gmme_id& gmme,
232  index_t id,
233  index_t boundary_id,
234  bool side = false ) override;
235 
236  private:
238  GeoModelBuilder3D& builder, GeoModel3D& geomodel )
239  : GeoModelBuilderTopologyBase< 3 >( builder, geomodel )
240  {
241  }
242 
243  void copy_all_mesh_entity_topology( const GeoModel3D& from ) override;
244  };
245 
246 } // namespace RINGMesh
#define ringmesh_disable_copy_and_move(Class)
Definition: common.h:76
GEO::vecng< DIMENSION, double > vecn
Definition: types.h:74
Base class to build or edit a GeoModel.
GeoModelBuilderTopology(GeoModelBuilder3D &builder, GeoModel3D &geomodel)
#define ringmesh_template_assert_2d_or_3d(type)
Definition: common.h:80
ALIAS_2D_AND_3D(Box)
void copy(const GeoModelMeshEntity< DIMENSION > &from)
std::string MeshType
Definition: mesh.h:69
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
GeoModelBuilderTopology(GeoModelBuilder2D &builder, GeoModel2D &geomodel)
virtual index_t nb_mesh_entities(const MeshEntityType &type) const
Returns the number of mesh entities of the given type.
Definition: geomodel.cpp:108
void copy_mesh_entity_topology(const GeoModel< DIMENSION > &from)
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
void parallel_for(index_t size, const ACTION &action)
Definition: common.h:244
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)