one_d_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// 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 #ifndef OOMPH_ONE_D_MESH_HEADER
27 #define OOMPH_ONE_D_MESH_HEADER
28 
29 // Config header generated by autoconfig
30 #ifdef HAVE_CONFIG_H
31 #include <oomph-lib-config.h>
32 #endif
33 
34 // oomph-lib headers
35 #include "../generic/line_mesh.h"
36 #include "../generic/refineable_line_mesh.h"
37 
38 namespace oomph
39 {
40  //====================================================================
41  /// 1D mesh consisting of N one-dimensional elements from the
42  /// QElement family.
43  /// \f[ x \in [Xmin,Xmax] \f]
44  /// The mesh has two boundaries:
45  /// - Boundary 0 is at \f$x=Xmin\f$.
46  /// - Boundary 1 is at \f$x=Xmax\f$.
47  /// .
48  /// There is one node on each of these boundaries.
49  //====================================================================
50  template<class ELEMENT>
51  class OneDMesh : public virtual LineMeshBase
52  {
53  public:
54  /// Constructor: Pass number of elements, n_element, length of
55  /// domain, length, and pointer to timestepper (defaults to a Steady
56  /// timestepper so we don't need to specify one in problems without
57  /// time-dependence).
58  OneDMesh(const unsigned& n_element,
59  const double& length,
60  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
61  : Xmin(0.0), Xmax(length), N(n_element)
62  {
63  check_1d();
64 
65  build_mesh(time_stepper_pt);
66  }
67 
68  /// Constructor: Pass number of elements, n_element, minimum
69  /// coordinate, xmin, maximum coordinate, xmax, and a pointer to a
70  /// timestepper.
71  OneDMesh(const unsigned& n_element,
72  const double& xmin,
73  const double& xmax,
74  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
75  : Xmin(xmin), Xmax(xmax), N(n_element)
76  {
77  check_1d();
78 
79  build_mesh(time_stepper_pt);
80  }
81 
82  protected:
83  /// Mesh can only be built with 1D elements (but can be either T or Q so
84  /// can't use the normal assert_geometric_element function.
85  void check_1d() const
86  {
87 #ifdef PARANOID
88  FiniteElement* el_pt = new ELEMENT;
89  if (el_pt->dim() != 1)
90  {
91  std::string err = "OneDMesh is only for 1D elements";
92  throw OomphLibError(
93  err, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
94  }
95  delete el_pt;
96  el_pt = 0;
97 #endif
98  }
99 
100  /// Minimum coordinate
101  double Xmin;
102 
103  /// Maximum coordinate
104  double Xmax;
105 
106  /// Length of the domain
107  double Length;
108 
109  /// Number of elements
110  unsigned N;
111 
112  /// Generic mesh constuction routine, called by all constructors
113  void build_mesh(TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper);
114  };
115 
116 
117  //====================================================================
118  /// Refineable version of the OneDMesh
119  //====================================================================
120  template<class ELEMENT>
121  class RefineableOneDMesh : public virtual OneDMesh<ELEMENT>,
122  public RefineableLineMesh<ELEMENT>
123  {
124  public:
125  /// Constructor: Pass number of elements, n_element, length of
126  /// domain, length, and pointer to timestepper (defaults to Steady)
128  const unsigned& n_element,
129  const double& length,
130  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
131  : OneDMesh<ELEMENT>(n_element, length, time_stepper_pt)
132  {
133  // Nodal positions etc. were created in constructor for OneDMesh<...>
134  // so only need to set up binary tree forest
135  this->setup_binary_tree_forest();
136  }
137 
138  /// Constructor that allows the specification of minimum and
139  /// maximum values of x coordinates. Also pass pointer to timestepper
140  /// (defaults to Steady).
142  const unsigned& n_element,
143  const double& xmin,
144  const double& xmax,
145  TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
146  : OneDMesh<ELEMENT>(n_element, xmin, xmax, time_stepper_pt)
147  {
148  // Nodal positions etc. were created in constructor for OneDMesh<...>
149  // so only need to set up binary tree forest
150  this->setup_binary_tree_forest();
151  }
152  };
153 
154 
155 } // namespace oomph
156 
157 #endif
1D mesh consisting of N one-dimensional elements from the QElement family.
OneDMesh(const unsigned &n_element, const double &xmin, const double &xmax, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Constructor: Pass number of elements, n_element, minimum coordinate, xmin, maximum coordinate,...
void build_mesh(TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Generic mesh constuction routine, called by all constructors.
unsigned N
Number of elements.
void check_1d() const
Mesh can only be built with 1D elements (but can be either T or Q so can't use the normal assert_geom...
double Length
Length of the domain.
double Xmin
Minimum coordinate.
double Xmax
Maximum coordinate.
OneDMesh(const unsigned &n_element, const double &length, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Constructor: Pass number of elements, n_element, length of domain, length, and pointer to timestepper...
Refineable version of the OneDMesh.
RefineableOneDMesh(const unsigned &n_element, const double &xmin, const double &xmax, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Constructor that allows the specification of minimum and maximum values of x coordinates....
RefineableOneDMesh(const unsigned &n_element, const double &length, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Constructor: Pass number of elements, n_element, length of domain, length, and pointer to timestepper...
////////////////////////////////////////////////////////////////////// //////////////////////////////...