rectangular_quadmesh.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// 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 a relatively simple Quad Meshe
27 #ifndef OOMPH_RECTANGULAR_QUADMESH_HEADER
28 #define OOMPH_RECTANGULAR_QUADMESH_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 headers
36 #include "../generic/mesh.h"
37 #include "../generic/quad_mesh.h"
38 #include "../generic/refineable_quad_mesh.h"
39 
40 namespace oomph
41 {
42  //==========================================================================
56  //===========================================================================
57  template<class ELEMENT>
58  class RectangularQuadMesh : public virtual QuadMeshBase
59  {
60  protected:
61  // Mesh variables
63  unsigned Nx;
65  unsigned Ny;
67  unsigned Np;
68 
70  double Xmin;
72  double Xmax;
73 
75  double Ymin;
77  double Ymax;
78 
81  bool Xperiodic;
82 
84  void build_mesh(TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper);
85 
94  const unsigned& nx,
95  const unsigned& ny,
96  const double& xmin,
97  const double& xmax,
98  const double& ymin,
99  const double& ymax,
100  const bool& periodic_in_x,
101  const bool& build,
102  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
103  : Nx(nx),
104  Ny(ny),
105  Xmin(xmin),
106  Xmax(xmax),
107  Ymin(ymin),
108  Ymax(ymax),
109  Xperiodic(periodic_in_x)
110  {
111  if (build)
112  {
113  // Call the generic mesh constructor
114  build_mesh(time_stepper_pt);
115  }
116  }
117 
118  public:
124  const unsigned& nx,
125  const unsigned& ny,
126  const double& lx,
127  const double& ly,
128  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
129  : Nx(nx),
130  Ny(ny),
131  Xmin(0.0),
132  Xmax(lx),
133  Ymin(0.0),
134  Ymax(ly),
135  Xperiodic(false)
136  {
137  // Mesh can only be built with 2D Qelements.
138  MeshChecker::assert_geometric_element<QElementGeometricBase, ELEMENT>(2);
139 
140  // Call the generic mesh constructor
141  build_mesh(time_stepper_pt);
142  }
143 
147  const unsigned& nx,
148  const unsigned& ny,
149  const double& xmin,
150  const double& xmax,
151  const double& ymin,
152  const double& ymax,
153  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
154  : Nx(nx),
155  Ny(ny),
156  Xmin(xmin),
157  Xmax(xmax),
158  Ymin(ymin),
159  Ymax(ymax),
160  Xperiodic(false)
161  {
162  // Mesh can only be built with 2D Qelements.
163  MeshChecker::assert_geometric_element<QElementGeometricBase, ELEMENT>(2);
164 
165  // Call the generic mesh constructor
166  build_mesh(time_stepper_pt);
167  }
168 
175  const unsigned& nx,
176  const unsigned& ny,
177  const double& lx,
178  const double& ly,
179  const bool& periodic_in_x,
180  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
181  : Nx(nx),
182  Ny(ny),
183  Xmin(0.0),
184  Xmax(lx),
185  Ymin(0.0),
186  Ymax(ly),
187  Xperiodic(periodic_in_x)
188  {
189  // Mesh can only be built with 2D Qelements.
190  MeshChecker::assert_geometric_element<QElementGeometricBase, ELEMENT>(2);
191 
192  // Call the generic mesh constructor
193  build_mesh(time_stepper_pt);
194  }
195 
200  const unsigned& nx,
201  const unsigned& ny,
202  const double& xmin,
203  const double& xmax,
204  const double& ymin,
205  const double& ymax,
206  const bool& periodic_in_x,
207  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
208  : Nx(nx),
209  Ny(ny),
210  Xmin(xmin),
211  Xmax(xmax),
212  Ymin(ymin),
213  Ymax(ymax),
214  Xperiodic(periodic_in_x)
215  {
216  // Mesh can only be built with 2D Qelements.
217  MeshChecker::assert_geometric_element<QElementGeometricBase, ELEMENT>(2);
218 
219  // Call the generic mesh constructor
220  build_mesh(time_stepper_pt);
221  }
222 
224  const unsigned& nx() const
225  {
226  // Return the value of Nx
227  return Nx;
228  }
229 
231  const unsigned& ny() const
232  {
233  // Return the value of Ny
234  return Ny;
235  }
236 
238  const double x_min() const
239  {
240  // Return the value of Xmin
241  return Xmin;
242  }
243 
245  const double x_max() const
246  {
247  // Return the value of Xmax
248  return Xmax;
249  }
250 
252  const double y_min() const
253  {
254  // Return the value of Ymin
255  return Ymin;
256  }
257 
259  const double y_max() const
260  {
261  // Return the value of Ymax
262  return Ymax;
263  }
264 
271  virtual void element_reorder();
272 
279  virtual double x_spacing_function(unsigned xelement,
280  unsigned xnode,
281  unsigned yelement,
282  unsigned ynode)
283  {
284  // Calculate the values of equal increments in nodal values
285  double xstep = (Xmax - Xmin) / ((Np - 1) * Nx);
286  // Return the appropriate value
287  return (Xmin + xstep * ((Np - 1) * xelement + xnode));
288  }
289 
296  virtual double y_spacing_function(unsigned xelement,
297  unsigned xnode,
298  unsigned yelement,
299  unsigned ynode)
300  {
301  double ystep = (Ymax - Ymin) / ((Np - 1) * Ny);
302  // Return the appropriate value
303  return (Ymin + ystep * ((Np - 1) * yelement + ynode));
304  }
305  };
306 
307 
308  //==========================================================================
321  //===========================================================================
322  template<class ELEMENT>
324  : public virtual RectangularQuadMesh<ELEMENT>,
325  public RefineableQuadMesh<ELEMENT>
326  {
327  public:
333  const unsigned& nx,
334  const unsigned& ny,
335  const double& lx,
336  const double& ly,
337  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
338  : RectangularQuadMesh<ELEMENT>(nx, ny, lx, ly, time_stepper_pt)
339  {
340  // Nodal positions etc. were created in constructor for
341  // RectangularMesh<...>. Only need to setup quadtree forest
342  this->setup_quadtree_forest();
343  }
344 
351  const unsigned& nx,
352  const unsigned& ny,
353  const double& lx,
354  const double& ly,
355  const bool& periodic_in_x,
356  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
357  : RectangularQuadMesh<ELEMENT>(
358  nx, ny, lx, ly, periodic_in_x, time_stepper_pt)
359  {
360  // Nodal positions etc. were created in constructor for
361  // RectangularMesh<...>. Only need to setup quadtree forest
362  this->setup_quadtree_forest();
363  }
364 
369  const unsigned& nx,
370  const unsigned& ny,
371  const double& xmin,
372  const double& xmax,
373  const double& ymin,
374  const double& ymax,
375  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
376  : RectangularQuadMesh<ELEMENT>(
377  nx, ny, xmin, xmax, ymin, ymax, time_stepper_pt)
378  {
379  // Nodal positions etc. were created in constructor for
380  // RectangularMesh<...>. Only need to setup quadtree forest
381  this->setup_quadtree_forest();
382  }
383 
388  const unsigned& nx,
389  const unsigned& ny,
390  const double& xmin,
391  const double& xmax,
392  const double& ymin,
393  const double& ymax,
394  const bool& periodic_in_x,
395  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
396  : RectangularQuadMesh<ELEMENT>(
397  nx, ny, xmin, xmax, ymin, ymax, periodic_in_x, time_stepper_pt)
398  {
399  // Nodal positions etc. were created in constructor for
400  // RectangularMesh<...>. Only need to setup quadtree forest
401  this->setup_quadtree_forest();
402  }
403  };
404 
405 
409 
410 
411  //================================================================
418  //================================================================
419  template<class ELEMENT>
421  : public virtual RectangularQuadMesh<ELEMENT>,
422  public virtual SolidMesh
423  {
424  public:
430  const unsigned& nx,
431  const unsigned& ny,
432  const double& lx,
433  const double& ly,
434  const Vector<double>& origin,
435  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
436  : RectangularQuadMesh<ELEMENT>(nx, ny, lx, ly, time_stepper_pt)
437  {
438  // Translate the nodes
439  unsigned nnod = nnode();
440  for (unsigned j = 0; j < nnod; j++)
441  {
442  node_pt(j)->x(0) += origin[0];
443  node_pt(j)->x(1) += origin[1];
444  }
445 
450 
451  // Setup boundary coordinates
452  set_boundary_coordinates(origin);
453  }
454 
455 
460  const unsigned& nx,
461  const unsigned& ny,
462  const double& lx,
463  const double& ly,
464  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
465  : RectangularQuadMesh<ELEMENT>(nx, ny, lx, ly, time_stepper_pt)
466  {
467  // No shift
468  Vector<double> origin(2, 0.0);
469 
474 
475  // Setup boundary coordinates
476  set_boundary_coordinates(origin);
477  }
478 
479 
485  const unsigned& nx,
486  const unsigned& ny,
487  const double& lx,
488  const double& ly,
489  const bool& periodic_in_x,
490  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
492  nx, ny, lx, ly, periodic_in_x, time_stepper_pt)
493  {
494  // No shift
495  Vector<double> origin(2, 0.0);
496 
501 
502  // Setup boundary coordinates
503  set_boundary_coordinates(origin);
504  }
505 
506  private:
511  {
512  // 1D vector fo boundary coordinate
513  Vector<double> zeta(1);
514 
515  // Loop over boundaries 0 and 2 where xi_0 is the varying
516  // boundary coordinate
517  for (unsigned b = 0; b < 3; b += 2)
518  {
519  // Number of nodes on those boundaries
520  unsigned n_nod = nboundary_node(b);
521 
522  // Loop over the nodes
523  for (unsigned i = 0; i < n_nod; i++)
524  {
525  // Boundary coordinate varies between 0 and L
526  zeta[0] = boundary_node_pt(b, i)->xi(0) - origin[0];
528  }
530  }
531 
532 
533  // Loop over boundaries 1 and 3 where xi_1 is the varying
534  // boundary coordinate
535  for (unsigned b = 1; b < 4; b += 2)
536  {
537  // Number of nodes on those boundaries
538  unsigned n_nod = nboundary_node(b);
539 
540  // Loop over the nodes
541  for (unsigned i = 0; i < n_nod; i++)
542  {
543  // Boundary coordinate varies between +/- H/2
544  zeta[0] = boundary_node_pt(b, i)->xi(1) - origin[1] -
545  0.5 * (this->Ymax - this->Ymin);
547  }
549  }
550  }
551  };
552 
553 
557 
558 
559  //================================================================
568  //================================================================
569  template<class ELEMENT>
571  : public virtual ElasticRectangularQuadMesh<ELEMENT>,
572  public RefineableQuadMesh<ELEMENT>
573  {
574  public:
580  const unsigned& nx,
581  const unsigned& ny,
582  const double& lx,
583  const double& ly,
584  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
585  : RectangularQuadMesh<ELEMENT>(nx, ny, lx, ly, time_stepper_pt),
586  ElasticRectangularQuadMesh<ELEMENT>(nx, ny, lx, ly, time_stepper_pt)
587 
588  {
589  // Nodal positions etc. were created in base class.
590  // Only need to setup quadtree forest
591  this->setup_quadtree_forest();
592  }
593 
594 
600  const unsigned& nx,
601  const unsigned& ny,
602  const double& lx,
603  const double& ly,
604  const bool& periodic_in_x,
605  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
607  nx, ny, lx, ly, periodic_in_x, time_stepper_pt),
609  nx, ny, lx, ly, periodic_in_x, time_stepper_pt)
610  {
611  // Nodal positions etc. were created in base class.
612  // Only need to setup quadtree forest
613  this->setup_quadtree_forest();
614  }
615 
616 
623  const unsigned& nx,
624  const unsigned& ny,
625  const double& lx,
626  const double& ly,
627  const Vector<double>& origin,
628  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
629  : RectangularQuadMesh<ELEMENT>(nx, ny, lx, ly, time_stepper_pt),
631  nx, ny, lx, ly, origin, time_stepper_pt)
632 
633  {
634  // Nodal positions etc. were created in base class.
635  // Only need to setup quadtree forest
636  this->setup_quadtree_forest();
637  }
638  };
639 
640 
641 } // namespace oomph
642 
643 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: rectangular_quadmesh.template.h:423
void set_boundary_coordinates(const Vector< double > &origin)
Definition: rectangular_quadmesh.template.h:510
Definition: rectangular_quadmesh.template.h:573
unsigned long nboundary_node(const unsigned &ibound) const
Return number of nodes on a particular boundary.
Definition: mesh.h:833
static Steady< 0 > Default_TimeStepper
The Steady Timestepper.
Definition: mesh.h:75
std::vector< bool > Boundary_coordinate_exists
Definition: mesh.h:190
unsigned long nnode() const
Return number of nodes in the mesh.
Definition: mesh.h:596
double & x(const unsigned &i)
Return the i-th nodal coordinate.
Definition: nodes.h:1060
virtual void set_coordinates_on_boundary(const unsigned &b, const unsigned &k, const Vector< double > &boundary_zeta)
Definition: nodes.cc:2394
Base class for quad meshes (meshes made of 2D quad elements).
Definition: quad_mesh.h:57
Definition: rectangular_quadmesh.template.h:59
unsigned Nx
Nx: number of elements in x-direction.
Definition: rectangular_quadmesh.template.h:63
const double y_min() const
Return the minimum value of y coordinate.
Definition: rectangular_quadmesh.template.h:252
RectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &lx, const double &ly, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:123
const double x_max() const
Return the maximum value of x coordinate.
Definition: rectangular_quadmesh.template.h:245
RectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &lx, const double &ly, const bool &periodic_in_x, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:174
unsigned Ny
Ny: number of elements in y-direction.
Definition: rectangular_quadmesh.template.h:65
const double y_max() const
Return the maximum value of y coordinate.
Definition: rectangular_quadmesh.template.h:259
bool Xperiodic
Definition: rectangular_quadmesh.template.h:81
const unsigned & ny() const
Return number of elements in y direction.
Definition: rectangular_quadmesh.template.h:231
unsigned Np
Np: number of (linear) points in the element.
Definition: rectangular_quadmesh.template.h:67
double Ymax
Maximum value of y coordinate.
Definition: rectangular_quadmesh.template.h:77
const double x_min() const
Return the minimum value of x coordinate.
Definition: rectangular_quadmesh.template.h:238
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
RectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &xmin, const double &xmax, const double &ymin, const double &ymax, const bool &periodic_in_x, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:199
virtual double x_spacing_function(unsigned xelement, unsigned xnode, unsigned yelement, unsigned ynode)
Definition: rectangular_quadmesh.template.h:279
double Ymin
Minimum value of y coordinate.
Definition: rectangular_quadmesh.template.h:75
virtual void element_reorder()
Definition: rectangular_quadmesh.template.cc:834
virtual double y_spacing_function(unsigned xelement, unsigned xnode, unsigned yelement, unsigned ynode)
Definition: rectangular_quadmesh.template.h:296
RectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &xmin, const double &xmax, const double &ymin, const double &ymax, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:146
RectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &xmin, const double &xmax, const double &ymin, const double &ymax, const bool &periodic_in_x, const bool &build, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:93
double Xmin
Minimum value of x coordinate.
Definition: rectangular_quadmesh.template.h:70
void build_mesh(TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Generic mesh construction function: contains all the hard work.
Definition: rectangular_quadmesh.template.cc:43
Definition: refineable_quad_mesh.h:53
void setup_quadtree_forest()
Definition: refineable_quad_mesh.h:88
Definition: rectangular_quadmesh.template.h:326
RefineableRectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &lx, const double &ly, const bool &periodic_in_x, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:350
RefineableRectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &lx, const double &ly, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:332
RefineableRectangularQuadMesh(const unsigned &nx, const unsigned &ny, const double &xmin, const double &xmax, const double &ymin, const double &ymax, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Definition: rectangular_quadmesh.template.h:368
Definition: mesh.h:2562
SolidNode * node_pt(const unsigned long &n)
Return a pointer to the n-th global SolidNode.
Definition: mesh.h:2594
void set_lagrangian_nodal_coordinates()
Definition: mesh.cc:9564
SolidNode * boundary_node_pt(const unsigned &b, const unsigned &n)
Return n-th SolidNodes on b-th boundary.
Definition: mesh.h:2612
double & xi(const unsigned &i)
Reference to i-th Lagrangian position.
Definition: nodes.h:1883
Definition: timesteppers.h:231
EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp< Eigen::internal::scalar_zeta_op< typename DerivedX::Scalar >, const DerivedX, const DerivedQ > zeta(const Eigen::ArrayBase< DerivedX > &x, const Eigen::ArrayBase< DerivedQ > &q)
Definition: SpecialFunctionsArrayAPI.h:152
const double ly
Definition: ConstraintElementsUnitTest.cpp:34
const double lx
Definition: ConstraintElementsUnitTest.cpp:33
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2