triangle_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// Copyright (C) 2006-2023 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 // Common base class for all Triangle Meshes
27 #ifndef OOMPH_GENERIC_TRIANGLE_MESH_HEADER
28 #define OOMPH_GENERIC_TRIANGLE_MESH_HEADER
29 
30 // Config header generated by autoconfig
31 #ifdef HAVE_CONFIG_H
32 #include <oomph-lib-config.h>
33 #endif
34 
35 // Oomph-lib includes
36 #include "Vector.h"
37 #include "nodes.h"
38 #include "matrices.h"
39 #include "mesh.h"
41 
42 namespace oomph
43 {
44  //================================================================
45  /// Base class for triangle meshes (meshes made of 2D triangle elements).
46  /// Note: we choose to template TriangleMeshBase here because certain
47  /// functions in UnstructuredTwoDMeshGeometryBase need template parameters
48  /// and it's much cleaner simply to template the entire class
49  //================================================================
51  public virtual Mesh
52  {
53  public:
54  /// Constructor
56  {
57 #ifdef OOMPH_HAS_TRIANGLE_LIB
58  // Initialise the TriangulateIO Data structure
60 
61  // Enable triangulateio specific parts for dump/restart by default.
63 #endif
64  }
65 
66  /// Broken copy constructor
67  TriangleMeshBase(const TriangleMeshBase& node) = delete;
68 
69  /// Broken assignment operator
70  // Commented out broken assignment operator because this can lead to a
71  // conflict warning when used in the virtual inheritence hierarchy.
72  // Essentially the compiler doesn't realise that two separate
73  // implementations of the broken function are the same and so, quite
74  // rightly, it shouts.
75  /*void operator=(const TriangleMeshBase&) = delete;*/
76 
77  /// Destructor (empty)
79  {
80 #ifdef OOMPH_HAS_TRIANGLE_LIB
81  // Clear the triangulate data structure
83 #endif
84  }
85 
86  /// Setup lookup schemes which establish whic elements are located
87  /// next to mesh's boundaries (wrapper to suppress doc).
89  {
90  std::ofstream outfile;
92  }
93 
94  /// Setup lookup schemes which establish which elements are located
95  /// next to mesh's boundaries. Doc in outfile (if it's open).
96  void setup_boundary_element_info(std::ostream& outfile);
97 
98 #ifdef OOMPH_HAS_TRIANGLE_LIB
99  /// const access for Use_triangulateio_restart.
101  {
103  }
104 
105  /// write access for Use_triangulateio_restart.
107  {
109  }
110 
111  /// write access for Use_triangulateio_restart.
113  {
115  }
116 
117  /// Access to the triangulateio representation of the mesh
119  {
120  return Triangulateio;
121  }
122 
123  /// Helper function. Write a TriangulateIO object file with all the
124  /// triangulateio fields. String s is add to assign a different value for
125  /// the input and/or output structure
126  void write_triangulateio(TriangulateIO& triangulate_io, std::string& s);
127 
128  /// Helper function. Clean up the memory associated with the
129  /// TriangulateIO object. This should really only be used to save
130  /// memory in extremely tight situations.
132  {
134  }
135 
136  /// Dump the triangulateio structure to a dump file and
137  /// record boundary coordinates of boundary nodes
138  void dump_triangulateio(std::ostream& dump_file);
139 
140 #ifdef OOMPH_HAS_MPI
141  /// Virtual function that is used to dump info. related with
142  /// distributed triangle meshes
143  virtual void dump_distributed_info_for_restart(std::ostream& dump_file)
144  {
145  std::ostringstream error_stream;
146  error_stream << "Empty default dump disributed info. method called.\n";
147  error_stream << "This should be overloaded in a specific TriangleMesh\n";
148  throw OomphLibError(
149  error_stream.str(),
150  "TriangleMeshBase::dump_distributed_info_for_restart()",
151  OOMPH_EXCEPTION_LOCATION);
152  }
153 
154  /// Virtual function that is used to dump info. related with
155  /// distributed triangle meshes
156  virtual void dump_info_to_reset_halo_haloed_scheme(std::ostream& dump_file)
157  {
158  std::ostringstream error_stream;
159  error_stream << "Empty default dump info. to reset halo haloed scheme.\n";
160  error_stream << "This should be overloaded in a specific TriangleMesh\n";
161  throw OomphLibError(
162  error_stream.str(),
163  "TriangleMeshBase::dump_info_to_reset_halo_haloed_scheme()",
164  OOMPH_EXCEPTION_LOCATION);
165  }
166 
167  /// Virtual function that is used to read info. related with
168  /// distributed triangle meshes
169  virtual void read_distributed_info_for_restart(std::istream& restart_file)
170  {
171  std::ostringstream error_stream;
172  error_stream << "Empty default read disributed info. method called.\n";
173  error_stream << "This should be overloaded in a specific TriangleMesh\n";
174  throw OomphLibError(
175  error_stream.str(),
176  "TriangleMeshBase::read_distributed_info_for_restart()",
177  OOMPH_EXCEPTION_LOCATION);
178  }
179 
180  /// Virtual function used to re-establish any additional info. related with
181  /// the distribution after a re-starting for triangle meshes
183  OomphCommunicator* comm_pt, std::istream& restart_file)
184  {
185  std::ostringstream error_stream;
186  error_stream << "Empty default reestablish disributed info method "
187  << "called.\n";
188  error_stream << "This should be overloaded in a specific "
189  << "RefineableTriangleMesh\n";
190  throw OomphLibError(
191  error_stream.str(),
192  "TriangleMeshBase::reestablish_distribution_info_for_restart()",
193  OOMPH_EXCEPTION_LOCATION);
194  }
195 #endif
196 
197  /// Virtual function used to update the polylines representation after
198  /// restart
200  {
201  std::ostringstream error_stream;
202  error_stream << "Empty default update polylines representation from "
203  << "restart method called.\n";
204  error_stream << "This should be overloaded in a specific "
205  << "RefineableTriangleMesh\n";
206  throw OomphLibError(
207  error_stream.str(),
208  "TriangleMeshBase::update_polyline_representation_from_restart()",
209  OOMPH_EXCEPTION_LOCATION);
210  }
211 
212  /// Regenerate the mesh from a dumped triangulateio file
213  /// and dumped boundary coordinates of boundary nodes
214  void remesh_from_triangulateio(std::istream& restart_file);
215 
216  /// Virtual function that is used for specific remeshing from the
217  /// triangulateio
219  {
220  std::ostringstream error_stream;
221  error_stream << "Empty default remesh function called.\n";
222  error_stream << "This should be overloaded in a specific TriangleMesh\n";
223  throw OomphLibError(
224  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
225  }
226 
227 #endif // #ifdef OOMPH_HAS_TRIANGLE_LIB
228 
229  /// Virtual function to perform the load balance rutines
230  virtual void load_balance(
231  const Vector<unsigned>& target_domain_for_local_non_halo_element)
232  {
233  std::ostringstream error_stream;
234  error_stream << "Empty default load balancing function called.\n";
235  error_stream << "This should be overloaded in a specific TriangleMesh\n";
236  throw OomphLibError(error_stream.str(),
237  "TriangleMeshBase::load_balance()",
238  OOMPH_EXCEPTION_LOCATION);
239  }
240 
241  /// Virtual function to perform the reset boundary elements info rutines
243  Vector<unsigned>& ntmp_boundary_elements,
244  Vector<Vector<unsigned>>& ntmp_boundary_elements_in_region,
245  Vector<FiniteElement*>& deleted_elements)
246  {
247  std::ostringstream error_stream;
248  error_stream << "Empty default reset boundary element info function"
249  << "called.\n";
250  error_stream << "This should be overloaded in a specific "
251  << "TriangleMesh\n";
252  throw OomphLibError(error_stream.str(),
253  "TriangleMeshBase::reset_boundary_element_info()",
254  OOMPH_EXCEPTION_LOCATION);
255  }
256 
257  protected:
258 #ifdef OOMPH_HAS_TRIANGLE_LIB
259 
260  /// TriangulateIO representation of the mesh
262 
263  /// Should we use triangulateio specific parts for dump/restart? (Doesn't
264  /// work with some elements and isn't needed if not using adaptivity).
266 
267 #endif // OOMPH_HAS_TRIANGLE
268  };
269 
270 } // namespace oomph
271 
272 #endif
static char t char * s
Definition: cfortran.h:568
A general mesh class.
Definition: mesh.h:67
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
Definition: communicator.h:54
An OomphLibError object which should be thrown when an run-time error is encountered....
Base class for triangle meshes (meshes made of 2D triangle elements). Note: we choose to template Tri...
Definition: triangle_mesh.h:52
TriangulateIO & triangulateio_representation()
Access to the triangulateio representation of the mesh.
virtual void remesh_from_internal_triangulateio()
Virtual function that is used for specific remeshing from the triangulateio.
void dump_triangulateio(std::ostream &dump_file)
Dump the triangulateio structure to a dump file and record boundary coordinates of boundary nodes.
virtual void dump_info_to_reset_halo_haloed_scheme(std::ostream &dump_file)
Virtual function that is used to dump info. related with distributed triangle meshes.
TriangulateIO Triangulateio
TriangulateIO representation of the mesh.
bool Use_triangulateio_restart
Should we use triangulateio specific parts for dump/restart? (Doesn't work with some elements and isn...
void clear_triangulateio()
Helper function. Clean up the memory associated with the TriangulateIO object. This should really onl...
virtual void read_distributed_info_for_restart(std::istream &restart_file)
Virtual function that is used to read info. related with distributed triangle meshes.
TriangleMeshBase(const TriangleMeshBase &node)=delete
Broken copy constructor.
bool use_triangulateio_restart() const
const access for Use_triangulateio_restart.
void remesh_from_triangulateio(std::istream &restart_file)
Regenerate the mesh from a dumped triangulateio file and dumped boundary coordinates of boundary node...
void disable_triangulateio_restart()
write access for Use_triangulateio_restart.
void setup_boundary_element_info()
Setup lookup schemes which establish whic elements are located next to mesh's boundaries (wrapper to ...
Definition: triangle_mesh.h:88
void write_triangulateio(TriangulateIO &triangulate_io, std::string &s)
Helper function. Write a TriangulateIO object file with all the triangulateio fields....
virtual void reset_boundary_element_info(Vector< unsigned > &ntmp_boundary_elements, Vector< Vector< unsigned >> &ntmp_boundary_elements_in_region, Vector< FiniteElement * > &deleted_elements)
Virtual function to perform the reset boundary elements info rutines.
void enable_triangulateio_restart()
write access for Use_triangulateio_restart.
virtual void load_balance(const Vector< unsigned > &target_domain_for_local_non_halo_element)
Virtual function to perform the load balance rutines.
virtual void dump_distributed_info_for_restart(std::ostream &dump_file)
Virtual function that is used to dump info. related with distributed triangle meshes.
virtual void reestablish_distribution_info_for_restart(OomphCommunicator *comm_pt, std::istream &restart_file)
Virtual function used to re-establish any additional info. related with the distribution after a re-s...
virtual void update_polyline_representation_from_restart()
Virtual function used to update the polylines representation after restart.
virtual ~TriangleMeshBase()
Broken assignment operator.
Definition: triangle_mesh.h:78
TriangleMeshBase()
Constructor.
Definition: triangle_mesh.h:55
Contains functions which define the geometry of the mesh, i.e. regions, boundaries,...
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
void initialise_triangulateio(TriangulateIO &triangle_io)
Initialise TriangulateIO structure.
void clear_triangulateio(TriangulateIO &triangulate_io, const bool &clear_hole_data)
Clear TriangulateIO structure.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
The Triangle data structure, modified from the triangle.h header supplied with triangle 1....