tet_mesh.h
Go to the documentation of this file.
1 //LIC// ====================================================================
2 //LIC// This file forms part of oomph-lib, the object-oriented,
3 //LIC// multi-physics finite-element library, available
4 //LIC// at http://www.oomph-lib.org.
5 //LIC//
6 //LIC// Version 1.0; svn revision $LastChangedRevision: 1097 $
7 //LIC//
8 //LIC// $LastChangedDate: 2015-12-17 11:53:17 +0000 (Thu, 17 Dec 2015) $
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 // Common base class for all Tet Meshes
31 #ifndef OOMPH_TETMESH_HEADER
32 #define OOMPH_TETMESH_HEADER
33 
34 // Config header generated by autoconfig
35 #ifdef HAVE_CONFIG_H
36  #include <oomph-lib-config.h>
37 #endif
38 
39 //oomph-lib includes
40 #include "Vector.h"
41 #include "nodes.h"
42 #include "matrices.h"
43 #include "mesh.h"
44 
45 namespace oomph
46 {
47 
48 //=======================================================================
49 /// Base class defining a closed (orientable) surface for Tetgen-based
50 /// mesh generation.
51 //=======================================================================
53 {
54 
55 public:
56 
57  /// Empty constructor
59  {
60  //Set default value for the region (no region)
61  Region = 0;
62  }
63 
64  /// Empty destructor
66 
67  /// Coordinate of the internal point
68  const double &internal_point(const unsigned &i) const
69  {return Internal_point[i];}
70 
71  void set_hole(const Vector<double> &hole_point)
72  {
73  Region = -1;
74  Internal_point = hole_point;
75  }
76 
77  /// Set the region
78  void set_region(const int &region,
79  const Vector<double> &region_point)
80  {
81  Internal_point = region_point;
82  Region = region;
83  }
84 
85  /// Return the region flag
86  const int &region() {return Region;}
87 
88  /// Is this a hole
89  bool is_hole() {if (Region==-1) {return true;} else {return false;}}
90 
91  /// Is it a specified region (i.e. region is positive)
92  bool is_region() {if(Region > 0) {return true;} else {return false;}}
93 
94  protected:
95 
96  ///\short Integer to indicate the region contained within the surface
97  /// Default values -10 (no internal point set), -1 (it's a hole)
98  int Region;
99 
100  /// Storage for an internal point
102 
103 };
104 
105 
106 //========================================================================
107 /// Class that represents a (closed) tetgen boundary bounded by polygonal
108 /// planar facets
109 //========================================================================
111 {
112  public:
113 
114  ///\short Constructor: Takes a vector of vertex coordinates,
115  /// a vector of facet connectivities and an optional vector of
116  /// boundary ids associated with each facet. The final boolean argument
117  /// is used to control whether boundaries can be split. If it is false
118  /// then additional nodes will NOT be added on any boundaries.
120  const Vector<Vector<unsigned> > &facet,
121  const bool &split_boundaries=true) :
123  Split_boundaries(split_boundaries)
124  {
125  //Check for dimensions
126 #ifdef PARANOID
127  //Find the number of vertices
128  const unsigned n_vertex=Vertex_coordinate.size();
129  for (unsigned i=0;i<n_vertex;i++)
130  {
131  if (Vertex_coordinate[i].size()!=3)
132  {
133  std::ostringstream error_stream;
134  error_stream
135  << "TetgenMeshPoly should only be used in 3D!\n"
136  << "Your Vector of coordinates, contains data for "
137  << Vertex_coordinate[i].size()
138  << "-dimensional coordinates." << std::endl;
139  throw OomphLibError(error_stream.str(),
140  OOMPH_CURRENT_FUNCTION,
141  OOMPH_EXCEPTION_LOCATION);
142  }
143  }
144 
145  //Check for same size
146 #endif
147  }
148 
149  ///\short Constructor: Takes a vector of vertex coordinates,
150  /// a vector of facet connectivities and an optional vector of
151  /// boundary ids associated with each facet.
152  /// The final boolean argument
153  /// is used to control whether boundaries can be split. If it is false
154  /// then additional nodes will NOT be added on any boundaries.
156  const Vector<Vector<unsigned> > &facet,
158  const bool &split_boundaries=true) :
160  Facet_boundary_id(facet_boundary_id), Split_boundaries(split_boundaries)
161  {
162  //Find the number of vertices
163  const unsigned n_vertex=Vertex_coordinate.size();
164 
165  //Check for dimensions
166 #ifdef PARANOID
167  for (unsigned i=0;i<n_vertex;i++)
168  {
169  if (Vertex_coordinate[i].size()!=3)
170  {
171  std::ostringstream error_stream;
172  error_stream
173  << "TetgenMeshPoly should only be used in 3D!\n"
174  << "Your Vector of coordinates, contains data for "
175  << Vertex_coordinate[i].size()
176  << "-dimensional coordinates." << std::endl;
177  throw OomphLibError(error_stream.str(),
178  OOMPH_CURRENT_FUNCTION,
179  OOMPH_EXCEPTION_LOCATION);
180  }
181  }
182 
183  //Check for same size
184 #endif
185 
186  //Assign boundary ids to the verticess. It doesn't matter which one is used
187  //just the first
188  //If boundary ids have been attached to the facets
189  if(Facet_boundary_id.size()!=0)
190  {
191  //Resize the vertex boundary id vector
192  Vertex_boundary_id.resize(n_vertex);
193  //Now loop over the facets and assign ids to the nodes
194  //This will involve some overwriting, but it doesn't matter
195  const unsigned n_facet = Facet.size();
196  for(unsigned f=0;f<n_facet;++f)
197  {
198  //Find the number of nodes
199  const unsigned n_node = Facet[f].size();
200  for(unsigned i=0;i<n_node;++i)
201  {
203  }
204  }
205  }
206  }
207 
208 
209 
210  /// Empty destructor
212 
213  /// Number of vertices
214  unsigned nvertex() const {return Vertex_coordinate.size();}
215 
216  /// Number of facets
217  unsigned nfacet() const {return Facet.size();}
218 
219  /// Boundary id
220  unsigned facet_boundary_id(const unsigned &i) const
221  {return Facet_boundary_id[i];}
222 
223  ///Return the vertex boundary id
224  const unsigned &vertex_boundary_id(const unsigned &n) const
225  {return Vertex_boundary_id[n];}
226 
227  /// i-th coordinats of n-th vertex
228  const double &vertex_coordinate(const unsigned &n, const unsigned &i)
229  const
230  {return Vertex_coordinate[n][i];}
231 
232  /// Coordinate vector of i-th vertex (const version)
233  Vector<double> vertex_coordinate(const unsigned& i) const
234  {
235  return Vertex_coordinate[i];
236  }
237 
238  /// Coordinate vector of i-th vertex
240  {
241  return Vertex_coordinate[i];
242  }
243 
244  /// Definition of ith facet via connectivity list (const version)
245  Vector<unsigned> facet(const unsigned &i) const
246  {
247  return Facet[i];
248  }
249 
250  /// Definition of ith facet via connectivity list
251  Vector<unsigned> &facet(const unsigned &i)
252  {
253  return Facet[i];
254  }
255 
256  /// Test whether boundaries can be split
258 
259 private:
260 
261  /// Vector of Vector of vertex coordinates
263 
264  /// Vector of vectors of facet connectivity
266 
267  /// Vector of vertex boundary ids
269 
270  /// Vector of Facet boundary ids
272 
273  /// Boolean to indicate whether extra vertices can be added on the boundary
275 
276 };
277 
278 
279 
280 
281 ///////////////////////////////////////////////////////////////////////
282 ///////////////////////////////////////////////////////////////////////
283 ///////////////////////////////////////////////////////////////////////
284 
285 
286 //================================================================
287 /// Base class for triangle meshes (meshes made of 3D tet elements).
288 //================================================================
289 class TetMeshBase : public virtual Mesh
290 {
291 
292 public:
293 
294  /// Constructor (empty)
296 
297  /// Broken copy constructor
298  TetMeshBase(const TetMeshBase& node)
299  {
300  BrokenCopy::broken_copy("TetMeshBase");
301  }
302 
303  /// Broken assignment operator
304  void operator=(const TetMeshBase&)
305  {
306  BrokenCopy::broken_assign("TetMeshBase");
307  }
308 
309  /// Destructor (empty)
310  virtual ~TetMeshBase(){}
311 
312  /// \short Global static data that specifies the permitted
313  /// error in the setup of the boundary coordinates
315 
316  /// Setup lookup schemes which establish whic elements are located
317  /// next to mesh's boundaries (wrapper to suppress doc).
319  {
320  std::ofstream outfile;
322  }
323 
324  /// \short Setup lookup schemes which establish which elements are located
325  /// next to mesh's boundaries. Doc in outfile (if it's open).
326  void setup_boundary_element_info(std::ostream &outfile);
327 
328 };
329 
330 }
331 
332 #endif
333 
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
static double Tolerance_for_boundary_finding
Global static data that specifies the permitted error in the setup of the boundary coordinates...
Definition: tet_mesh.h:314
const double & internal_point(const unsigned &i) const
Coordinate of the internal point.
Definition: tet_mesh.h:68
Vector< Vector< double > > Vertex_coordinate
Vector of Vector of vertex coordinates.
Definition: tet_mesh.h:262
Vector< Vector< unsigned > > Facet
Vector of vectors of facet connectivity.
Definition: tet_mesh.h:265
const double & vertex_coordinate(const unsigned &n, const unsigned &i) const
i-th coordinats of n-th vertex
Definition: tet_mesh.h:228
unsigned nvertex() const
Number of vertices.
Definition: tet_mesh.h:214
unsigned nfacet() const
Number of facets.
Definition: tet_mesh.h:217
Vector< double > Internal_point
Storage for an internal point.
Definition: tet_mesh.h:101
cstr elem_len * i
Definition: cfortran.h:607
Base class for triangle meshes (meshes made of 3D tet elements).
Definition: tet_mesh.h:289
const int & region()
Return the region flag.
Definition: tet_mesh.h:86
Vector< double > & vertex_coordinate(const unsigned &i)
Coordinate vector of i-th vertex.
Definition: tet_mesh.h:239
TetgenMeshFacetedSurface(const Vector< Vector< double > > &vertex_coordinate, const Vector< Vector< unsigned > > &facet, const bool &split_boundaries=true)
Constructor: Takes a vector of vertex coordinates, a vector of facet connectivities and an optional v...
Definition: tet_mesh.h:119
int Region
Integer to indicate the region contained within the surface Default values -10 (no internal point set...
Definition: tet_mesh.h:98
bool is_region()
Is it a specified region (i.e. region is positive)
Definition: tet_mesh.h:92
Vector< unsigned > & facet(const unsigned &i)
Definition of ith facet via connectivity list.
Definition: tet_mesh.h:251
const unsigned & vertex_boundary_id(const unsigned &n) const
Return the vertex boundary id.
Definition: tet_mesh.h:224
void setup_boundary_element_info()
Definition: tet_mesh.h:318
void set_region(const int &region, const Vector< double > &region_point)
Set the region.
Definition: tet_mesh.h:78
TetgenMeshFacetedSurface(const Vector< Vector< double > > &vertex_coordinate, const Vector< Vector< unsigned > > &facet, const Vector< unsigned > &facet_boundary_id, const bool &split_boundaries=true)
Constructor: Takes a vector of vertex coordinates, a vector of facet connectivities and an optional v...
Definition: tet_mesh.h:155
virtual ~TetgenMeshClosedSurface()
Empty destructor.
Definition: tet_mesh.h:65
bool Split_boundaries
Boolean to indicate whether extra vertices can be added on the boundary.
Definition: tet_mesh.h:274
Vector< unsigned > Facet_boundary_id
Vector of Facet boundary ids.
Definition: tet_mesh.h:271
bool is_hole()
Is this a hole.
Definition: tet_mesh.h:89
virtual ~TetMeshBase()
Destructor (empty)
Definition: tet_mesh.h:310
bool can_boundaries_be_split()
Test whether boundaries can be split.
Definition: tet_mesh.h:257
TetgenMeshClosedSurface()
Empty constructor.
Definition: tet_mesh.h:58
virtual ~TetgenMeshFacetedSurface()
Empty destructor.
Definition: tet_mesh.h:211
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
void operator=(const TetMeshBase &)
Broken assignment operator.
Definition: tet_mesh.h:304
Vector< unsigned > Vertex_boundary_id
Vector of vertex boundary ids.
Definition: tet_mesh.h:268
Vector< unsigned > facet(const unsigned &i) const
Definition of ith facet via connectivity list (const version)
Definition: tet_mesh.h:245
TetMeshBase()
Constructor (empty)
Definition: tet_mesh.h:295
void set_hole(const Vector< double > &hole_point)
Definition: tet_mesh.h:71
Vector< double > vertex_coordinate(const unsigned &i) const
Coordinate vector of i-th vertex (const version)
Definition: tet_mesh.h:233
TetMeshBase(const TetMeshBase &node)
Broken copy constructor.
Definition: tet_mesh.h:298
A general mesh class.
Definition: mesh.h:74
unsigned facet_boundary_id(const unsigned &i) const
Boundary id.
Definition: tet_mesh.h:220