CppNoddy  0.92
Loading...
Searching...
No Matches
OneD_TVDLF_Elt.h
Go to the documentation of this file.
1/// \file OneD_TVDLF_Elt.h
2/// Specification of a one dimensional linear element for
3/// use in a TVD Lax-Friedrichs scheme.
4
5#ifndef ONED_TVDLF_ELT_H
6#define ONED_TVDLF_ELT_H
7
8#include <list>
9
11
12namespace CppNoddy {
13
14 /// A Linear Element class.
16
17 struct contribution {
18 OneD_TVDLF_Elt* elt_ptr;
20 int face_index;
21 };
22
23 public:
24
25 /// Construct a linear element
26 /// \param a The left hand edge
27 /// \param b The right hand edge
28 /// \param ptr A pointer to the hyperbolic system for this element
29 /// \param flag A boolean indicator to specify an elt with an external face
30 /// \param index Index of the external face if flag=true
31 OneD_TVDLF_Elt(double a, double b, OneD_Hyperbolic_System* ptr,
32 bool flag = false, int index = 0);
33
34 /// An empty destructor
36
37 /// Allow the connection of this element to another element
38 /// \param ptr A pointer to another element of the same type
39 /// \param s_range A vector range of local coordinates (s_min,s_max) in
40 /// this 1D case.
41 /// \param index An index to indicate which face of the current elt
42 /// this contribution is associated with for flux computations -1=left, +1=right, 0=none
43 void add_contribution(OneD_TVDLF_Elt* ptr, const DenseVector<double>& s_range, int index);
44
45 /// Clear the record of contributions to this element.
47 CONT_LIST.clear();
48 }
49
50 /// Find the integral contributions to this black/red element from the
51 /// contributed red/black element.
52 /// \return The integrated value of all components
54
55 /// Compute the flux into this element through the left face over a given
56 /// time step.
57 /// \param dt The time step to compute the flux over
58 /// \param flux_in_left A vector to return the flux components in
59 /// \param current_time The current mesh time level
60 void contributed_flux_in_left(const double &dt, DenseVector<double> &flux_in_left, const double &current_time);
61
62 /// Compute the flux out of this element through the right face over a given
63 /// time step.
64 /// \param dt The time step to compute the flux over
65 /// \param flux_out_right A vector to return the flux components in
66 /// \param current_time The current mesh time level
67 void contributed_flux_out_right(const double &dt, DenseVector<double> &flux_out_right, const double &current_time);
68
69 /// Convert a global coordinate into a local coordinate within this element
70 /// If the global coordinate is outside the element, then we throw an exception.
71 /// \param x The global coordinate to convert
72 double get_s(double x) const {
73#ifdef PARANOID
74 if((x < LEFT) || (x > RIGHT)) {
75 std::string problem;
76 problem = " The OneD_TVDLF_Elt::get_s method has been called for an element \n";
77 problem += " whose range does not bracket the given global coordinate.\n";
78 throw ExceptionRuntime(problem);
79 }
80#endif
81 return -1.0 + 2 * (x - LEFT) / (RIGHT - LEFT);
82 }
83
84 /// Get the global position of the local coordinate
85 /// \param s The local coordinate
86 /// \return The global position
87 double get_x(double s) const;
88
89 /// Get the size of the element
90 /// \return The separation of the left and right faces
91 double get_dx() const;
92
93 /// Get the external flag.
94 /// \return The value of the flag (true if this is an elt with an external face)
95 bool get_external_flag() const;
96
97 /// Set the external flag.
98 /// \param flag is the value to set
99 void set_external_flag(bool flag);
100
101 /// Get the exterior boundary number
102 /// \return An integer boundary indicator +1 for right, -1 for left.
103 int get_external_face_i() const;
104
105 /// Set the local coordinate of the external face.
106 /// Only one face can be external.
107 /// \param i The index of the external face -1=left, +1=right
108 void set_external_face_i(int i);
109
110 /// Get the value of the 'concentration' stored in this
111 /// element.
112 /// \param s The local coordinate in the elt at which Q is requested
113 /// \return The concentration value of the elt for each component
114 DenseVector<double> get_Q(double s) const;
115
116 /// Get the integral of Q over a sub-element
117 /// \param s0 The left local coordinate
118 /// \param s1 The right local coordinate
119 /// \return The integral of the concentration over the local range
120 DenseVector<double> get_int_Q(const double s0, const double s1);
121
122 /// Set the value of the 'concentration' stored in this
123 /// element. To second order, this is the value of the
124 /// concentration at the mid-point of the element.
125 /// \param value The value to be assigned to the
126 /// concentration member data Q
127 void set_Q_mid(const DenseVector<double> value);
128
129 /// The concentration is approximated by a linear function
130 /// in each element. The slope of this function is set
131 /// through this method.
132 /// \param value The value to be assigned to the member data 'slope'
133 void set_slope(const DenseVector<double> value);
134
135 /// The concentration is approximated by a linear function
136 /// in each element. The slope of this function is got
137 /// through this method.
138 /// \return The value of the 'slope' member data
140
141 /// Get the flux function evaluated for the concentration
142 /// value stored in this elt.
143 /// \param s The local coordinate at which to evaluate
144 /// \return The flux function vector
145 DenseVector<double> get_flux_fn(const double s) const;
146
147 /// Get the Jacobian of the flux function evaluated for the
148 /// concentration value stored in this elt.
149 /// \param s The local coordinate at which to evaluate
150 /// \return The Jacobian matrix
151 DenseMatrix<double> get_Jac_flux_fn(const double s) const;
152
153 /// Get the value of the source function term in this element at
154 /// a given local coordinate.
155 /// \param s The local coordinate to evaluate at
156 DenseVector<double> get_source_fn(const double s) const;
157
158 /// Get the maximum allowable time step for this element by using
159 /// information about the size of the element and the maximum wave
160 /// speed set in the conservative system. The time step is guranteed
161 /// to satisfy the CFL < 0.5 constraint.
162 /// \return The maximum time step.
163 double get_max_dt() const;
164
166
167 private:
168
169 std::list< contribution > CONT_LIST;
170
173 double LEFT, RIGHT;
174 int EXTERNAL_FACE_I;
175
176 bool EXTERNAL;
177
178 };
179
180
181 inline double OneD_TVDLF_Elt::get_dx() const {
182 return RIGHT - LEFT;
183 }
184
185 inline double OneD_TVDLF_Elt::get_x(double s) const {
186 return (LEFT + RIGHT + s * get_dx()) / 2;
187 }
188
190 return EXTERNAL;
191 }
192
194 return EXTERNAL_FACE_I;
195 }
196
198 return Q + SLOPE * s * (RIGHT - LEFT) / 2;
199 }
200
201 inline DenseVector<double> OneD_TVDLF_Elt::get_int_Q(const double s0, const double s1) {
202 // linear elt so integral is 0.5 * dx * ( f(s0) + f(s1) )
203 return (get_Q(s0) + get_Q(s1)) * 0.5 * ((s1 - s0) * get_dx() / 2);
204 }
205
206 inline void OneD_TVDLF_Elt::set_external_flag(bool flag) {
207 EXTERNAL = flag;
208 }
209
211 EXTERNAL_FACE_I = i;
212 }
213
215 Q = value;
216 }
217
219 SLOPE = value;
220 }
221
223 return SLOPE;
224 }
225
226} // CppNoddy namespace
227
228#endif // OneD_TVDLF_Elt_H
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
Definition: DenseMatrix.h:25
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A generic runtime exception.
Definition: Exceptions.h:158
A class to represent a one dimensional hyperbolic system of equations.
A Linear Element class.
void add_contribution(OneD_TVDLF_Elt *ptr, const DenseVector< double > &s_range, int index)
Allow the connection of this element to another element.
OneD_Hyperbolic_System * system_ptr
double get_x(double s) const
Get the global position of the local coordinate.
void set_slope(const DenseVector< double > value)
The concentration is approximated by a linear function in each element.
void clear_contributions()
Clear the record of contributions to this element.
void set_external_flag(bool flag)
Set the external flag.
DenseVector< double > contributed_Q()
Find the integral contributions to this black/red element from the contributed red/black element.
void set_Q_mid(const DenseVector< double > value)
Set the value of the 'concentration' stored in this element.
void contributed_flux_in_left(const double &dt, DenseVector< double > &flux_in_left, const double &current_time)
Compute the flux into this element through the left face over a given time step.
~OneD_TVDLF_Elt()
An empty destructor.
DenseVector< double > get_Q(double s) const
Get the value of the 'concentration' stored in this element.
double get_dx() const
Get the size of the element.
DenseMatrix< double > get_Jac_flux_fn(const double s) const
Get the Jacobian of the flux function evaluated for the concentration value stored in this elt.
int get_external_face_i() const
Get the exterior boundary number.
DenseVector< double > get_source_fn(const double s) const
Get the value of the source function term in this element at a given local coordinate.
DenseVector< double > get_slope() const
The concentration is approximated by a linear function in each element.
double get_s(double x) const
Convert a global coordinate into a local coordinate within this element If the global coordinate is o...
bool get_external_flag() const
Get the external flag.
DenseVector< double > get_flux_fn(const double s) const
Get the flux function evaluated for the concentration value stored in this elt.
void contributed_flux_out_right(const double &dt, DenseVector< double > &flux_out_right, const double &current_time)
Compute the flux out of this element through the right face over a given time step.
DenseVector< double > get_int_Q(const double s0, const double s1)
Get the integral of Q over a sub-element.
double get_max_dt() const
Get the maximum allowable time step for this element by using information about the size of the eleme...
void set_external_face_i(int i)
Set the local coordinate of the external face.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt