refineable_tetgen_mesh.template.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: 1174 $
7 //LIC//
8 //LIC// $LastChangedDate: 2016-05-11 10:03:56 +0100 (Wed, 11 May 2016) $
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 
31 #ifndef OOMPH_REFINEABLE_TETGEN_MESH_HEADER
32 #define OOMPH_REFINEABLE_TETGEN_MESH_HEADER
33 
34 // Config header generated by autoconfig
35 #ifdef HAVE_CONFIG_H
36  #include <oomph-lib-config.h>
37 #endif
38 
39 
40 #include "../generic/tetgen_scaffold_mesh.h"
41 #include "../generic/tet_mesh.h"
42 #include "../generic/refineable_mesh.h"
43 #include "tetgen_mesh.template.h"
44 
45 namespace oomph
46 {
47 
48 
49 
50 //=========================================================================
51 // Unstructured refineable TetgenMesh
52 //=========================================================================
53 template<class ELEMENT>
54  class RefineableTetgenMesh : public virtual TetgenMesh<ELEMENT>,
55  public virtual RefineableTetMeshBase
56  {
57 
58  public:
59 
60  /// \short Build mesh, based on a TetMeshFacetedClosedSurface that specifies
61  /// the outer boundary of the domain and any number of internal
62  /// closed curves, specified by TetMeshFacetedSurfaces.
63  /// Also specify target volume for uniform element size.
65  TetMeshFacetedClosedSurface* const &outer_boundary_pt,
66  Vector<TetMeshFacetedSurface*>& internal_closed_surface_pt,
67  const double &element_volume,
68  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper,
69  const bool &use_attributes = false,
70  const bool& split_corner_elements = false) :
71  TetgenMesh<ELEMENT>(outer_boundary_pt,
72  internal_closed_surface_pt,
73  element_volume,
74  time_stepper_pt,
75  use_attributes,
76  split_corner_elements), Corner_elements_must_be_split(split_corner_elements)
77  {
78  // Initialise the data associated with adaptation
80  }
81 
82 
83  private:
84 
85  /// \short Specialised constructor used during adaptation only.
86  /// Element sizes are specified by vector tetgen_io is passed in
87  /// from previous mesh (is then modified to build new mesh)
88  /// Ditto with use_attributes, which comes from the previous mesh
89  RefineableTetgenMesh(const Vector<double> &target_volume,
90  tetgenio* const &tetgen_io_pt,
91  TetMeshFacetedClosedSurface* const &outer_boundary_pt,
92  Vector<TetMeshFacetedSurface*>& internal_surface_pt,
93  TimeStepper* time_stepper_pt=
95  const bool &use_attributes=false)
96  {
97 
98  // NOTE THERE IS A CERTAIN AMOUNT OF DUPLICATION BETWEEN THE
99  // CODE IN HERE AND THE ONE IN THE CONSTRUCTOR OF THE TetgenMesh
100  // BUT THE FACT THAT WE HAVE TO MODIFY THE TETGENIO STRUCTURE
101  // MEANS WE CAN'T QUITE RECYCLE THIS.
102 
103  // Mesh can only be built with 3D Telements.
104  MeshChecker::assert_geometric_element<TElementGeometricBase,ELEMENT>(3);
105 
106  // Initialise the data associated with adaptation
108 
109  // Store Timestepper used to build elements
110  this->Time_stepper_pt=time_stepper_pt;
111 
112  // Triangulation has been created -- remember to wipe it!
113  this->Tetgenio_exists =true;
114  this->Tetgenio_pt = new tetgenio;
115 
116  // Add the volume constraints to the tetgenio data object.
117  // Note that since the tetgenio structure is referred to by pointer
118  // we're also modifying the one associated with the (still existing)
119  // original mesh. Bit naughty but shouldn't cause any problems
120  // since that mesh is already built and about to go out of scope
121  // anyway.
122 
123  //Create a local copy
124  tetgenio *tetgen_input_pt = new tetgenio;;
125  this->deep_copy_of_tetgenio(tetgen_io_pt,tetgen_input_pt);
126 
127  //Add volume constraints
128  tetgen_input_pt->tetrahedronvolumelist =
129  new double[tetgen_input_pt->numberoftetrahedra];
130  for(int e=0;e<tetgen_input_pt->numberoftetrahedra;++e)
131  {
132  tetgen_input_pt->tetrahedronvolumelist[e] = target_volume[e];
133  }
134 
135  // Input string
136  std::stringstream input_string_stream;
137  input_string_stream<< "Vqra";
138 
139  // Convert to a *char
140  char tetswitches[100];
141  sprintf(tetswitches,"%s",input_string_stream.str().c_str());
142 
143  // Build triangulateio refined object
144  tetrahedralize(tetswitches, tetgen_input_pt, this->Tetgenio_pt);
145  // Build scaffold
146  this->Tmp_mesh_pt=new TetgenScaffoldMesh(*this->Tetgenio_pt);
147 
148  // Convert mesh from scaffold to actual mesh
149  this->build_from_scaffold(time_stepper_pt,use_attributes);
150 
151  // Kill the scaffold
152  delete this->Tmp_mesh_pt;
153  this->Tmp_mesh_pt=0;
154 
155  //delete the input
156  delete tetgen_input_pt;
157 
158  //Store the boundary
159  this->Outer_boundary_pt = outer_boundary_pt;
160 
161  // Setup reverse lookup scheme
162  {
163  unsigned n_facet=this->Outer_boundary_pt->nfacet();
164  for (unsigned f=0;f<n_facet;f++)
165  {
166  unsigned b=this->Outer_boundary_pt->one_based_facet_boundary_id(f);
167  if (b!=0)
168  {
170  this->Tet_mesh_facet_pt[b-1]=this->Outer_boundary_pt->facet_pt(f);
171  }
172  else
173  {
174  std::ostringstream error_message;
175  error_message << "Boundary IDs have to be one-based. Yours is "
176  << b << "\n";
177  throw OomphLibError(error_message.str(),
178  OOMPH_CURRENT_FUNCTION,
179  OOMPH_EXCEPTION_LOCATION);
180  }
181  }
182  }
183 
184  //Store the internal boundary
185  this->Internal_surface_pt = internal_surface_pt;
186 
187  // Setup reverse lookup scheme
188  {
189  unsigned n=this->Internal_surface_pt.size();
190  for (unsigned i=0;i<n;i++)
191  {
192  unsigned n_facet=this->Internal_surface_pt[i]->nfacet();
193  for (unsigned f=0;f<n_facet;f++)
194  {
195  unsigned b=this->Internal_surface_pt[i]->
196  one_based_facet_boundary_id(f);
197  if (b!=0)
198  {
199  this->Tet_mesh_faceted_surface_pt[b-1]=
200  this->Internal_surface_pt[i];
201  this->Tet_mesh_facet_pt[b-1]=
202  this->Internal_surface_pt[i]->facet_pt(f);
203  }
204  else
205  {
206  std::ostringstream error_message;
207  error_message << "Boundary IDs have to be one-based. Yours is "
208  << b << "\n";
209  throw OomphLibError(error_message.str(),
210  OOMPH_CURRENT_FUNCTION,
211  OOMPH_EXCEPTION_LOCATION);
212  }
213  }
214  }
215  }
216 
217 
218  // Setup boundary coordinates for boundaries
219  unsigned nb=nboundary();
220  for (unsigned b=0;b<nb;b++)
221  {
222  this->template setup_boundary_coordinates<ELEMENT>(b);
223  }
224 
225  // Now snap onto geometric objects associated with triangular facets
226  // (if any!)
228 
229  }
230 
231 
232  public:
233 
234  /// Empty Destructor
236 
237  /// Refine mesh uniformly and doc process
239  {
240  // hierher do it
241  throw OomphLibError("refine_uniformly() not implemented yet",
242  OOMPH_CURRENT_FUNCTION,
243  OOMPH_EXCEPTION_LOCATION);
244  }
245 
246  /// \short Unrefine mesh uniformly: Return 0 for success,
247  /// 1 for failure (if unrefinement has reached the coarsest permitted
248  /// level)
250  {
251  // hierher do it
252  throw OomphLibError("unrefine_uniformly() not implemented yet",
253  OOMPH_CURRENT_FUNCTION,
254  OOMPH_EXCEPTION_LOCATION);
255  // dummy return
256  return 0;
257  }
258 
259  /// Adapt mesh, based on elemental error provided
260  void adapt(const Vector<double>& elem_error);
261 
262 
263  /// Is projection of old solution onto new mesh disabled?
265  {
266  return Projection_is_disabled;
267  }
268 
269  /// Disable projection of old solution onto new mesh
271  {
273  }
274 
275  /// Disable projection of old solution onto new mesh
277  {
279  }
280 
281 
282  protected:
283 
284  /// Helper function to initialise data associated with adaptation
286  {
287  // Set max and min targets for adaptation
288  this->Max_element_size=1.0;
289  this->Min_element_size=0.001;
290  this->Max_permitted_edge_ratio=2.0;
291 
292  /// By default we project solution onto new mesh during adaptation
294  }
295 
296  /// Disable projection of solution onto new mesh during adaptation
298 
299  /// \short Corner elements which have all of their nodes on the outer
300  /// boundary are to be split into elements which have some non-boundary
301  /// nodes
303  };
304 
305 /////////////////////////////////////////////////////////////////////////////
306 /////////////////////////////////////////////////////////////////////////////
307 /////////////////////////////////////////////////////////////////////////////
308 
309 }
310 
311 #endif
312 
313 
static Steady< 0 > Default_TimeStepper
Default Steady Timestepper, to be used in default arguments to Mesh constructors. ...
Definition: mesh.h:85
void build_from_scaffold(TimeStepper *time_stepper_pt, const bool &use_attributes)
Build mesh from scaffold.
Information for documentation of results: Directory and file number to enable output in the form RESL...
TimeStepper * Time_stepper_pt
Timestepper used to build nodes.
Definition: tet_mesh.h:1055
RefineableTetgenMesh(const Vector< double > &target_volume, tetgenio *const &tetgen_io_pt, TetMeshFacetedClosedSurface *const &outer_boundary_pt, Vector< TetMeshFacetedSurface *> &internal_surface_pt, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper, const bool &use_attributes=false)
Specialised constructor used during adaptation only. Element sizes are specified by vector tetgen_io ...
cstr elem_len * i
Definition: cfortran.h:607
TetgenScaffoldMesh * Tmp_mesh_pt
Temporary scaffold mesh.
bool Projection_is_disabled
Disable projection of solution onto new mesh during adaptation.
TetMeshFacet * facet_pt(const unsigned &j) const
Pointer to j-th facet.
Definition: tet_mesh.h:369
e
Definition: cfortran.h:575
double Max_element_size
Max permitted element size.
void snap_nodes_onto_geometric_objects()
Move the nodes on boundaries with associated GeomObjects so that they exactly coincide with the geome...
Definition: tet_mesh.cc:431
bool Tetgenio_exists
Boolean to indicate whether a tetgenio representation of the mesh exists.
Unstructured tet mesh based on output from Tetgen: http://wias-berlin.de/software/tetgen/.
void refine_uniformly(DocInfo &doc_info)
Refine mesh uniformly and doc process.
TetMeshFacetedClosedSurface * Outer_boundary_pt
Faceted surface that defines outer boundaries.
Definition: tet_mesh.h:1036
unsigned nboundary() const
Return number of boundaries.
Definition: mesh.h:806
std::map< unsigned, TetMeshFacetedSurface * > Tet_mesh_faceted_surface_pt
Reverse lookup scheme: Pointer to faceted surface (if any!) associated with boundary b...
Definition: tet_mesh.h:1043
void deep_copy_of_tetgenio(tetgenio *const &input_pt, tetgenio *&output_pt)
double Min_element_size
Min permitted element size.
unsigned nfacet() const
Number of facets.
Definition: tet_mesh.h:321
unsigned unrefine_uniformly()
Unrefine mesh uniformly: Return 0 for success, 1 for failure (if unrefinement has reached the coarses...
void adapt(const Vector< double > &elem_error)
Adapt mesh, based on elemental error provided.
bool projection_is_disabled()
Is projection of old solution onto new mesh disabled?
DocInfo doc_info()
Access fct for DocInfo.
bool Corner_elements_must_be_split
Corner elements which have all of their nodes on the outer boundary are to be split into elements whi...
RefineableTetgenMesh(TetMeshFacetedClosedSurface *const &outer_boundary_pt, Vector< TetMeshFacetedSurface *> &internal_closed_surface_pt, const double &element_volume, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper, const bool &use_attributes=false, const bool &split_corner_elements=false)
Build mesh, based on a TetMeshFacetedClosedSurface that specifies the outer boundary of the domain an...
unsigned one_based_facet_boundary_id(const unsigned &j) const
One-based boundary id of j-th facet.
Definition: tet_mesh.h:327
Mesh that is based on input files generated by the tetrahedra mesh generator tetgen.
virtual ~RefineableTetgenMesh()
Empty Destructor.
void initialise_adaptation_data()
Helper function to initialise data associated with adaptation.
Base class for refineable tet meshes.
void enable_projection()
Disable projection of old solution onto new mesh.
void disable_projection()
Disable projection of old solution onto new mesh.
Base class for time-stepping schemes. Timestepper provides an approximation of the temporal derivativ...
Definition: timesteppers.h:219
Vector< TetMeshFacetedSurface * > Internal_surface_pt
Vector to faceted surfaces that define internal boundaries.
Definition: tet_mesh.h:1039
std::map< unsigned, TetMeshFacet * > Tet_mesh_facet_pt
Reverse lookup scheme: Pointer to facet (if any!) associated with boundary b.
Definition: tet_mesh.h:1047
double Max_permitted_edge_ratio
Max edge ratio before remesh gets triggered.
tetgenio * Tetgenio_pt
Tetgen representation of mesh.