RINGMesh  Version 5.0.0
A programming library for geological model meshes
well.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 
40 #include <array>
41 #include <memory>
42 
43 #include <geogram/basic/attributes.h>
44 
46 
52 namespace RINGMesh
53 {
59  struct ElementLocalVertex;
60 } // namespace RINGMesh
61 
62 namespace RINGMesh
63 {
64  template < index_t DIMENSION >
65  class WellEntity
66  {
69 
70  protected:
71  explicit WellEntity( const Well< DIMENSION >* well );
72  virtual ~WellEntity() = default;
73 
74  public:
78  const Well< DIMENSION >& well() const
79  {
80  return *well_;
81  }
82 
83  protected:
86  };
87 
89 
90  // --------------------------------------------------------------------------
91 
92  template < index_t DIMENSION >
93  class WellCorner : public WellEntity< DIMENSION >
94  {
95  public:
97  const vecn< DIMENSION >& point,
98  bool is_on_surface,
99  index_t id );
100 
101  const vecn< DIMENSION >& point() const;
102 
103  bool is_on_surface() const
104  {
105  return is_on_surface_;
106  }
107 
108  bool id() const
109  {
110  return id_;
111  }
112 
113  GEO::AttributesManager& vertex_attribute_manager() const;
114 
115  private:
119  index_t id_;
120  std::unique_ptr< PointSetMesh< DIMENSION > > mesh_;
121  };
122 
124 
125  // --------------------------------------------------------------------------
126 
127  template < index_t DIMENSION >
128  class WellPart : public WellEntity< DIMENSION >
129  {
130  public:
137  WellPart( const Well< DIMENSION >* well, index_t id );
138 
144  void set_corner( index_t c, index_t id )
145  {
146  corners_[c] = id;
147  }
153  index_t corner( index_t c ) const
154  {
155  ringmesh_assert( c < 2 );
156  return corners_[c];
157  }
158 
164  void set_points( const std::vector< vecn< DIMENSION > >& points );
165 
169  index_t nb_edges() const;
170  index_t nb_vertices() const;
171 
175  double length() const;
176 
182  void set_id( index_t id )
183  {
184  id_ = id;
185  }
189  index_t id() const
190  {
191  return id_;
192  }
193  const vecn< DIMENSION >& vertex( index_t v ) const;
194  const vecn< DIMENSION >& edge_vertex(
195  const ElementLocalVertex& well_edge_local_vertex ) const;
196 
197  GEO::AttributesManager& vertex_attribute_manager() const;
198  GEO::AttributesManager& edge_attribute_manager() const;
199 
200  const NNSearch< DIMENSION >& vertices_nn_search() const;
201 
202  private:
205  index_t id_;
207  std::array< index_t, 2 > corners_;
208  std::unique_ptr< LineMesh< DIMENSION > > mesh_;
209  };
210 
212 
213  // --------------------------------------------------------------------------
214 
215  template < index_t DIMENSION >
216  class Edge
217  {
218  public:
219  Edge( const vecn< DIMENSION >& v0, const vecn< DIMENSION >& v1 )
220  {
221  vertices_[0] = v0;
222  vertices_[1] = v1;
223  }
224 
225  const vecn< DIMENSION >& vertex( index_t i ) const
226  {
227  return vertices_[i];
228  }
229 
231  {
232  return ( vertices_[0] + vertices_[1] ) * 0.5;
233  }
234 
235  private:
236  std::array< vecn< DIMENSION >, 2 > vertices_;
237  };
238 
240 
241  // --------------------------------------------------------------------------
242 
243  template < index_t DIMENSION >
244  class Well
245  {
247 
248  public:
249  Well();
250  ~Well() = default;
251 
257  void copy_corners_and_informations( Well< DIMENSION >& well ) const;
258 
264  void get_part_edges(
265  index_t part_id, std::vector< Edge< DIMENSION > >& edges ) const;
271  void get_region_edges(
272  index_t part_id, std::vector< Edge< DIMENSION > >& edges ) const;
273 
281  index_t create_corner(
282  const vecn< DIMENSION >& vertex, bool is_on_surface, index_t id )
283  {
284  index_t corner_id = static_cast< index_t >( corners_.size() );
285  corners_.emplace_back( new WellCorner< DIMENSION >(
286  this, vertex, is_on_surface, id ) );
287  return corner_id;
288  }
297  index_t find_corner(
298  const vecn< DIMENSION >& vertex, double epsilon ) const;
303  const WellCorner< DIMENSION >& corner( index_t c ) const
304  {
305  ringmesh_assert( c < corners_.size() );
306  return *corners_[c];
307  }
308 
314  index_t create_part( index_t region )
315  {
316  index_t part_id = static_cast< index_t >( parts_.size() );
317  parts_.emplace_back( new WellPart< DIMENSION >( this, part_id ) );
318  part_region_id_.push_back( region );
319  return part_id;
320  }
325  const WellPart< DIMENSION >& part( index_t part_id ) const
326  {
327  ringmesh_assert( part_id < parts_.size() );
328  return *parts_[part_id];
329  }
334  WellPart< DIMENSION >& part( index_t part_id )
335  {
336  ringmesh_assert( part_id < parts_.size() );
337  return *parts_[part_id];
338  }
344  index_t part_region_id( index_t part_id ) const
345  {
346  ringmesh_assert( part_id < nb_parts() );
347  return part_region_id_[part_id];
348  }
349 
353  index_t nb_corners() const
354  {
355  return static_cast< index_t >( corners_.size() );
356  }
360  index_t nb_parts() const
361  {
362  return static_cast< index_t >( parts_.size() );
363  }
367  index_t nb_edges() const;
372  void set_name( const std::string& name )
373  {
374  name_ = name;
375  }
379  const std::string& name() const
380  {
381  return name_;
382  }
383 
384  private:
386  std::vector< std::unique_ptr< WellCorner< DIMENSION > > > corners_;
388  std::vector< std::unique_ptr< WellPart< DIMENSION > > > parts_;
390  std::vector< index_t > part_region_id_;
392  std::string name_;
394  index_t nb_edges_;
395  };
396 
398 
399  // --------------------------------------------------------------------------
400 
404  template < index_t DIMENSION >
405  class WellGroup
406  {
408 
409  public:
410  WellGroup();
411  virtual ~WellGroup() = default;
412 
418  void get_region_edges(
419  index_t region, std::vector< Edge< DIMENSION > >& edges ) const;
420 
426  void get_region_edges( index_t region,
427  std::vector< std::vector< Edge< DIMENSION > > >& edges ) const;
428 
433  {
434  return geomodel_;
435  }
440  {
441  geomodel_ = geomodel;
442  }
443 
449  index_t find_well( const std::string& name ) const;
450 
455  void create_wells( index_t nb_wells );
456 
463  void add_well(
464  const LineMesh< DIMENSION >& mesh, const std::string& name );
465 
469  index_t nb_wells() const
470  {
471  return static_cast< index_t >( wells_.size() );
472  }
478  const Well< DIMENSION >& well( index_t w ) const
479  {
480  return *wells_[w];
481  }
482 
483  private:
484  void compute_conformal_mesh(
486 
487  protected:
489  std::vector< Well< DIMENSION >* > wells_;
492  };
493 
495 } // namespace RINGMesh
index_t part_region_id(index_t part_id) const
Definition: well.h:344
index_t id_
Definition: well.h:205
GEO::vecng< DIMENSION, double > vecn
Definition: types.h:74
std::vector< index_t > part_region_id_
Vector of the region id of the parts.
Definition: well.h:390
void set_name(const std::string &name)
Definition: well.h:372
std::vector< Well< DIMENSION > *> wells_
Vector of the wells.
Definition: well.h:489
std::unique_ptr< LineMesh< DIMENSION > > mesh_
Definition: well.h:208
WellEntity(const Well< DIMENSION > *well)
Definition: well.cpp:290
WellPart< DIMENSION > & part(index_t part_id)
Definition: well.h:334
index_t create_part(index_t region)
Definition: well.h:314
Edge(const vecn< DIMENSION > &v0, const vecn< DIMENSION > &v1)
Definition: well.h:219
const std::string & name() const
Definition: well.h:379
index_t id() const
Definition: well.h:189
index_t id_
The id of the corresponding surface or region.
Definition: well.h:119
ALIAS_2D_AND_3D(Box)
bool is_on_surface() const
Definition: well.h:103
std::array< index_t, 2 > corners_
id in the corners_ vector the the well
Definition: well.h:207
ringmesh_template_assert_2d_or_3d(DIMENSION)
const Well< DIMENSION > & well(index_t w) const
Definition: well.h:478
index_t corner(index_t c) const
Definition: well.h:153
const WellCorner< DIMENSION > & corner(index_t c) const
Definition: well.h:303
index_t nb_corners() const
Definition: well.h:353
vecn< DIMENSION > barycenter() const
Definition: well.h:230
void set_corner(index_t c, index_t id)
Definition: well.h:144
ringmesh_disable_copy_and_move(WellEntity)
std::unique_ptr< PointSetMesh< DIMENSION > > mesh_
Definition: well.h:120
index_t nb_wells() const
Definition: well.h:469
const Well< DIMENSION > * well_
Pointer to the Well owning this entity.
Definition: well.h:85
void set_id(index_t id)
Definition: well.h:182
index_t create_corner(const vecn< DIMENSION > &vertex, bool is_on_surface, index_t id)
Definition: well.h:281
const vecn< DIMENSION > & vertex(index_t i) const
Definition: well.h:225
#define ringmesh_assert(x)
const WellPart< DIMENSION > & part(index_t part_id) const
Definition: well.h:325
std::string name_
Name of the well.
Definition: well.h:392
index_t nb_edges_
Number of edges in the well.
Definition: well.h:394
index_t nb_parts() const
Definition: well.h:360
bool is_on_surface_
True is the corner is on a surface, false if is in a region.
Definition: well.h:117
const Well< DIMENSION > & well() const
Definition: well.h:78
void set_geomodel(GeoModel< DIMENSION > *geomodel)
Definition: well.h:439
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
const GeoModel< DIMENSION > * geomodel() const
Definition: well.h:432
std::vector< std::unique_ptr< WellPart< DIMENSION > > > parts_
Vector of the parts of the well.
Definition: well.h:388
GeoModel< DIMENSION > * geomodel_
Associated GeoModel.
Definition: well.h:491
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)
std::array< vecn< DIMENSION >, 2 > vertices_
Definition: well.h:236
bool id() const
Definition: well.h:108
std::vector< std::unique_ptr< WellCorner< DIMENSION > > > corners_
Vector of the corners of the well.
Definition: well.h:386
virtual ~WellEntity()=default