refineable_r_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-2022 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 //Header file for my Refineable_r_mesh class
27 
28 namespace oomph
29 {
30 
31 //======================================================================
33 //======================================================================
34 template <class ELEMENT>
35 class Refineable_r_mesh : public RectangularQuadMesh<ELEMENT>,
36 public RefineableQuadMesh<ELEMENT>
37 {
38 protected:
39 
40  //Storage for pointers to fluid elements
42 
43 public:
44 
46  ELEMENT* fluid_elt_pt(unsigned e)
47  {return Fluid_elt_pt[e];}
49  unsigned fluid_elt_length() {return Fluid_elt_pt.size();}
52 
55  Refineable_r_mesh(const unsigned int &nx,const unsigned int &ny) :
58  -1.0,1.0)
59  {
60  //Call the generic mesh construction routine
61  //(Defined in RectangularQuadMesh<ELEMENT>)
62  //this->build_mesh();
63 
64  //Function to log space the mesh
66 
67  // Nodal positions etc. were created in constructor for
68  // RectangularMesh<...>. Only need to setup quadtree forest
69  this->setup_quadtree_forest();
70  }
71 
72 private:
73 
74  void stretch_mesh()
75  {
76  unsigned long n_node = this -> nnode();
77  //Get number of elements in x
78  unsigned Nx = this->Nx;
79 
80  //Look up the size of the mesh
81  double R_min = this->Xmin;
82  double R_max = this->Xmax;
83 
84  //Work out a best guess for the last 7% of elements in x
85  //Always rounds down due to truncation
86  int end=static_cast<int>(0.07*Nx);
87  //int end=static_cast<int>(0.2*Nx);
88  if(end==0)
89  {
90  std::cout << std::endl << "Warning, no elements in outlet region" << std::endl;
91  std::cout << "Adjusting to one element" << std::endl;
92  end=1;
93  }
94 
95  //Work out how where that element boundary will fall:
96  double cut=R_min+(R_max-R_min)*((static_cast<double>(Nx-end))/Nx);
97 
98  //Now spread those final 7% of elements out over the final 10% of the domain
99  double a=cut;
100  double b=R_min+0.9*(R_max-R_min);
101 
103  {
104  //Output what I'm doing
105  std::cout << std::endl << "Number of end elements in r: " << end << std::endl;
106  std::cout << "Start of outlet region: " << cut << std::endl << std::endl;
107  }
108 
109  for(unsigned long n=0;n<n_node;n++)
110  {
111  //Work out old nodal position:
112  double r_pos = this -> Node_pt[ n ] -> x( 0 );
113 
115  {
116  if(r_pos<a)
117  {
118  //Log space until old_r = a
119  this -> Node_pt[ n ] -> x( 0 ) = log_spacing( r_pos,a,b,R_min);
120  }
121  else
122  {
123  //Linear spacing from old_r = a to 1
124  this -> Node_pt[ n ] -> x( 0 ) = linear_spacing(r_pos,a,b,R_max);
125  }
126  }
127  else
128  {
129  //Log space across whole domain
130  this -> Node_pt[ n ] -> x( 0 ) = log_spacing( r_pos,R_max,R_max,R_min);
131  }
132  }
133 
134  }//End of stretch mesh
135 
136  double log_spacing( const double& r,const double& a,const double& b,double R_min)
137  {
138  return R_min*exp(((r-R_min)/(a-R_min))*log(b/R_min));
139  }
140 
141  double linear_spacing( const double& r,const double& a,const double& b,double R_max)
142  {
143  if((R_max-a)<1.e-14)
144  {std::cout << "Warning - no elements in outlet region. Attempting to divide by zero" << std::endl;}
145  return R_max+(r - R_max)*((R_max-b)/(R_max-a));
146  }
147 
148 }; //End of Refineable_r_mesh class
149 
150 } //End of namespace oomph
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Scalar * b
Definition: benchVecAdd.cpp:17
Vector< Node * > Node_pt
Vector of pointers to nodes.
Definition: mesh.h:183
unsigned long nnode() const
Return number of nodes in the mesh.
Definition: mesh.h:596
Definition: rectangular_quadmesh.template.h:59
unsigned Nx
Nx: number of elements in x-direction.
Definition: rectangular_quadmesh.template.h:63
const unsigned & ny() const
Return number of elements in y direction.
Definition: rectangular_quadmesh.template.h:231
double Xmax
Maximum value of x coordinate.
Definition: rectangular_quadmesh.template.h:72
const unsigned & nx() const
Return number of elements in x direction.
Definition: rectangular_quadmesh.template.h:224
double Xmin
Minimum value of x coordinate.
Definition: rectangular_quadmesh.template.h:70
Definition: refineable_quad_mesh.h:53
void setup_quadtree_forest()
Definition: refineable_quad_mesh.h:88
My log r spaced mesh.
Definition: refineable_r_mesh.h:37
Vector< GeneralisedElement * > Fluid_elt_pt
Definition: refineable_r_mesh.h:41
double linear_spacing(const double &r, const double &a, const double &b, double R_max)
Definition: refineable_r_mesh.h:141
unsigned fluid_elt_length()
Return length of fluid element vector.
Definition: refineable_r_mesh.h:49
ELEMENT * fluid_elt_pt(unsigned e)
Return pointer to fluid element e.
Definition: refineable_r_mesh.h:46
void stretch_mesh()
Definition: refineable_r_mesh.h:74
Vector< GeneralisedElement * > fluid_elt_vector()
Return pointer to vector of all Fluid elements.
Definition: refineable_r_mesh.h:51
double log_spacing(const double &r, const double &a, const double &b, double R_min)
Definition: refineable_r_mesh.h:136
Refineable_r_mesh(const unsigned int &nx, const unsigned int &ny)
Definition: refineable_r_mesh.h:55
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79
const Scalar * a
Definition: level2_cplx_impl.h:32
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:615
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:618
Global variables.
Definition: TwenteMeshGluing.cpp:60
bool new_outlet_region
Definition: jeffery_hamel.cc:93
bool log_mesh
Definition: jeffery_hamel.cc:92
double R_l
Definition: jeffery_hamel.cc:57
double R_r
Definition: jeffery_hamel.cc:58
r
Definition: UniformPSDSelfTest.py:20
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
list x
Definition: plotDoE.py:28