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