CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | List of all members
CppNoddy::OneD_TVDLF_Elt Class Reference

A Linear Element class. More...

#include <OneD_TVDLF_Elt.h>

Public Member Functions

 OneD_TVDLF_Elt (double a, double b, OneD_Hyperbolic_System *ptr, bool flag=false, int index=0)
 Construct a linear element. More...
 
 ~OneD_TVDLF_Elt ()
 An empty destructor. More...
 
void add_contribution (OneD_TVDLF_Elt *ptr, const DenseVector< double > &s_range, int index)
 Allow the connection of this element to another element. More...
 
void clear_contributions ()
 Clear the record of contributions to this element. More...
 
DenseVector< double > contributed_Q ()
 Find the integral contributions to this black/red element from the contributed red/black element. More...
 
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. More...
 
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. More...
 
double get_s (double x) const
 Convert a global coordinate into a local coordinate within this element If the global coordinate is outside the element, then we throw an exception. More...
 
double get_x (double s) const
 Get the global position of the local coordinate. More...
 
double get_dx () const
 Get the size of the element. More...
 
bool get_external_flag () const
 Get the external flag. More...
 
void set_external_flag (bool flag)
 Set the external flag. More...
 
int get_external_face_i () const
 Get the exterior boundary number. More...
 
void set_external_face_i (int i)
 Set the local coordinate of the external face. More...
 
DenseVector< double > get_Q (double s) const
 Get the value of the 'concentration' stored in this element. More...
 
DenseVector< double > get_int_Q (const double s0, const double s1)
 Get the integral of Q over a sub-element. More...
 
void set_Q_mid (const DenseVector< double > value)
 Set the value of the 'concentration' stored in this element. More...
 
void set_slope (const DenseVector< double > value)
 The concentration is approximated by a linear function in each element. More...
 
DenseVector< double > get_slope () const
 The concentration is approximated by a linear function in each element. More...
 
DenseVector< double > get_flux_fn (const double s) const
 Get the flux function evaluated for the concentration value stored in this elt. More...
 
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. More...
 
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. More...
 
double get_max_dt () const
 Get the maximum allowable time step for this element by using information about the size of the element and the maximum wave speed set in the conservative system. More...
 

Public Attributes

OneD_Hyperbolic_Systemsystem_ptr
 

Detailed Description

A Linear Element class.

Definition at line 15 of file OneD_TVDLF_Elt.h.

Constructor & Destructor Documentation

◆ OneD_TVDLF_Elt()

CppNoddy::OneD_TVDLF_Elt::OneD_TVDLF_Elt ( double  a,
double  b,
OneD_Hyperbolic_System ptr,
bool  flag = false,
int  index = 0 
)

Construct a linear element.

Parameters
aThe left hand edge
bThe right hand edge
ptrA pointer to the hyperbolic system for this element
flagA boolean indicator to specify an elt with an external face
indexIndex of the external face if flag=true

Definition at line 13 of file OneD_TVDLF_Elt.cpp.

15 {
16#ifdef DEBUG
17 std::cout << "DEBUG: Constructing a OneD_TVDLF_Elt object between "
18 << a << " and " << b << "\n";
19#endif
20 system_ptr = ptr;
21 LEFT = a;
22 RIGHT = b;
23 EXTERNAL = flag;
24 EXTERNAL_FACE_I = index;
25 SLOPE = DenseVector<double>(system_ptr -> get_order(), 0.0);
26 Q = DenseVector<double>(system_ptr -> get_order(), 0.0);
27 }
OneD_Hyperbolic_System * system_ptr

References system_ptr.

◆ ~OneD_TVDLF_Elt()

CppNoddy::OneD_TVDLF_Elt::~OneD_TVDLF_Elt ( )

An empty destructor.

Definition at line 29 of file OneD_TVDLF_Elt.cpp.

30 {}

Member Function Documentation

◆ add_contribution()

void CppNoddy::OneD_TVDLF_Elt::add_contribution ( OneD_TVDLF_Elt ptr,
const DenseVector< double > &  s_range,
int  index 
)

Allow the connection of this element to another element.

Parameters
ptrA pointer to another element of the same type
s_rangeA vector range of local coordinates (s_min,s_max) in this 1D case.
indexAn index to indicate which face of the current elt this contribution is associated with for flux computations -1=left, +1=right, 0=none

Definition at line 32 of file OneD_TVDLF_Elt.cpp.

32 {
33 contribution cont;
34 cont.elt_ptr = ptr;
35 cont.s = s_range;
36 cont.face_index = index;
37 // push the contribution data into a list
38 CONT_LIST.push_back(cont);
39 }

◆ clear_contributions()

void CppNoddy::OneD_TVDLF_Elt::clear_contributions ( )
inline

Clear the record of contributions to this element.

Definition at line 46 of file OneD_TVDLF_Elt.h.

46 {
47 CONT_LIST.clear();
48 }

◆ contributed_flux_in_left()

void CppNoddy::OneD_TVDLF_Elt::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.

Parameters
dtThe time step to compute the flux over
flux_in_leftA vector to return the flux components in
current_timeThe current mesh time level

Definition at line 54 of file OneD_TVDLF_Elt.cpp.

54 {
55 std::list< contribution >::iterator c = CONT_LIST.begin();
56 // loop over all contributing elements
57 while(c != CONT_LIST.end()) {
58 // find contributions to the left face
59 if(c -> face_index == -1) {
60 // which local coord in the contributing elt?
61 const double s = c -> s[ 0 ];
62 DenseVector<double> q_half_step(c -> elt_ptr -> get_Q(s));
63 // add half step correction
64 q_half_step += (c -> elt_ptr -> get_source_fn(s)
65 - c -> elt_ptr -> get_Jac_flux_fn(s).multiply(c -> elt_ptr -> SLOPE))
66 * 0.5 * dt;
67 //DenseVector<double> x( 1, 0.0 ); x[ 0 ] = c -> elt_ptr -> get_x( s );
68 double x(c -> elt_ptr -> get_x(s));
69 // evaluate the flux at this Q value
70 c -> elt_ptr -> system_ptr -> flux_fn(x, q_half_step, flux_in_left);
71 }
72 ++c;
73 }
74 // treat the user specified external faces separately
75 if(EXTERNAL) {
76 // we are in an external elt
77 c = CONT_LIST.begin();
78 while(c != CONT_LIST.end()) {
79 // external faces are external for the current elt *and* its contributions
80 if(c -> elt_ptr -> get_external_flag()) {
81 if(EXTERNAL_FACE_I < 0) {
82 // LH boundary
83 DenseVector<double> q_left(c -> elt_ptr -> get_Q(-1.0));
84 // convert x at boundary to a vector
85 //DenseVector<double> x_left( 1, 0.0 ); x_left[ 0 ] = c -> elt_ptr -> get_x( -1.0 );
86 double x_left(c -> elt_ptr -> get_x(-1.0));
87 DenseVector<double> q_left_half_step(q_left);
88 //compute flux at the half time step
89 q_left_half_step += (c -> elt_ptr -> get_source_fn(-1.0)
90 - c -> elt_ptr -> get_Jac_flux_fn(-1.0).multiply(c -> elt_ptr -> SLOPE))
91 * 0.5 * dt;
92 // get the edge values
93 system_ptr -> edge_values(-1, x_left, q_left_half_step, current_time + 0.5*dt);
94 // get the flux
95 system_ptr -> flux_fn(x_left, q_left_half_step, flux_in_left);
96 }
97 }
98 ++c;
99 }
100 }
101 }
DenseVector< _Type > multiply(const DenseVector< _Type > &x) const
Right multiply the matrix by a DENSE vector.
double get_x(double s) const
Get the global position of the local coordinate.
DenseVector< double > get_Q(double s) const
Get the value of the 'concentration' stored in this 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.
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.
bool get_external_flag() const
Get the external flag.
double s
relative rotation rate

References get_external_flag(), get_Jac_flux_fn(), get_Q(), get_source_fn(), get_x(), CppNoddy::DenseMatrix< _Type >::multiply(), and system_ptr.

◆ contributed_flux_out_right()

void CppNoddy::OneD_TVDLF_Elt::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.

Parameters
dtThe time step to compute the flux over
flux_out_rightA vector to return the flux components in
current_timeThe current mesh time level

Definition at line 103 of file OneD_TVDLF_Elt.cpp.

103 {
104 std::list< contribution >::iterator c = CONT_LIST.begin();
105 // loop over all contributing elements
106 while(c != CONT_LIST.end()) {
107 // find contributions to the right face
108 if(c -> face_index == 1) {
109 // which local coord in the contributing elt?
110 const double s = c -> s[ 1 ];
111 DenseVector<double> q_half_step(c -> elt_ptr -> get_Q(s));
112 // add half step correction
113 q_half_step += (c -> elt_ptr -> get_source_fn(s)
114 - c -> elt_ptr -> get_Jac_flux_fn(s).multiply(c -> elt_ptr -> SLOPE))
115 * 0.5 * dt;
116 //DenseVector<double> x( 1, 0.0 ); x[ 0 ] = c -> elt_ptr -> get_x( s );
117 double x(c -> elt_ptr -> get_x(s));
118 // evaluate the flux at this Q value
119 c -> elt_ptr -> system_ptr -> flux_fn(x, q_half_step, flux_out_right);
120 }
121 ++c;
122 }
123 // treat the user specified external faces separately
124 if(EXTERNAL) {
125 // we are in an external elt
126 c = CONT_LIST.begin();
127 while(c != CONT_LIST.end()) {
128 // external faces are external for the current elt *and* its contributions
129 if(c -> elt_ptr -> get_external_flag()) {
130 if(EXTERNAL_FACE_I > 0) {
131 // RH boundary
132 DenseVector<double> q_right(c -> elt_ptr -> get_Q(1.0));
133 // convert x at boundary to a vector
134 //DenseVector<double> x_right( 1, 0.0 ); x_right[ 0 ] = c -> elt_ptr -> get_x( 1.0 );
135 double x_right(c -> elt_ptr -> get_x(1.0));
136 DenseVector<double> q_right_half_step(q_right);
137 // compute flux at the half time step
138 q_right_half_step += (c -> elt_ptr -> get_source_fn(1.0)
139 - c -> elt_ptr -> get_Jac_flux_fn(1.0).multiply(c -> elt_ptr -> SLOPE))
140 * 0.5 * dt;
141 // get the edge values
142 system_ptr -> edge_values(1, x_right, q_right_half_step, current_time + 0.5*dt);
143 // get the flux
144 system_ptr -> flux_fn(x_right, q_right_half_step, flux_out_right);
145 }
146 }
147 ++c;
148 }
149 }
150 }

References get_external_flag(), get_Jac_flux_fn(), get_Q(), get_source_fn(), get_x(), CppNoddy::DenseMatrix< _Type >::multiply(), and system_ptr.

◆ contributed_Q()

DenseVector< double > CppNoddy::OneD_TVDLF_Elt::contributed_Q ( )

Find the integral contributions to this black/red element from the contributed red/black element.

Returns
The integrated value of all components

Definition at line 41 of file OneD_TVDLF_Elt.cpp.

41 {
42 std::list< contribution >::iterator c = CONT_LIST.begin();
43 // start with zero
44 DenseVector<double> sum(system_ptr -> get_order(), 0.0);
45 // loop over contributions
46 while(c != CONT_LIST.end()) {
47 // get integral of each
48 sum += c -> elt_ptr -> get_int_Q(c -> s[0], c -> s[1]);
49 ++c;
50 }
51 return sum;
52 }
DenseVector< double > get_int_Q(const double s0, const double s1)
Get the integral of Q over a sub-element.

References get_int_Q(), and system_ptr.

◆ get_dx()

double CppNoddy::OneD_TVDLF_Elt::get_dx ( ) const
inline

Get the size of the element.

Returns
The separation of the left and right faces

Definition at line 181 of file OneD_TVDLF_Elt.h.

181 {
182 return RIGHT - LEFT;
183 }

Referenced by get_int_Q(), get_max_dt(), and get_x().

◆ get_external_face_i()

int CppNoddy::OneD_TVDLF_Elt::get_external_face_i ( ) const
inline

Get the exterior boundary number.

Returns
An integer boundary indicator +1 for right, -1 for left.

Definition at line 193 of file OneD_TVDLF_Elt.h.

193 {
194 return EXTERNAL_FACE_I;
195 }

◆ get_external_flag()

bool CppNoddy::OneD_TVDLF_Elt::get_external_flag ( ) const
inline

Get the external flag.

Returns
The value of the flag (true if this is an elt with an external face)

Definition at line 189 of file OneD_TVDLF_Elt.h.

189 {
190 return EXTERNAL;
191 }

Referenced by contributed_flux_in_left(), and contributed_flux_out_right().

◆ get_flux_fn()

DenseVector< double > CppNoddy::OneD_TVDLF_Elt::get_flux_fn ( const double  s) const

Get the flux function evaluated for the concentration value stored in this elt.

Parameters
sThe local coordinate at which to evaluate
Returns
The flux function vector

Definition at line 152 of file OneD_TVDLF_Elt.cpp.

152 {
153 DenseVector<double> f(system_ptr -> get_order(), 0.0);
154 double x(get_x(s));
155 system_ptr -> flux_fn(x, get_Q(s), f);
156 return f;
157 }
@ f
Definition: BVPBerman.cpp:15

References f, get_Q(), get_x(), and system_ptr.

◆ get_int_Q()

DenseVector< double > CppNoddy::OneD_TVDLF_Elt::get_int_Q ( const double  s0,
const double  s1 
)
inline

Get the integral of Q over a sub-element.

Parameters
s0The left local coordinate
s1The right local coordinate
Returns
The integral of the concentration over the local range

Definition at line 201 of file OneD_TVDLF_Elt.h.

201 {
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 }
double get_dx() const
Get the size of the element.

References get_dx(), and get_Q().

Referenced by contributed_Q().

◆ get_Jac_flux_fn()

DenseMatrix< double > CppNoddy::OneD_TVDLF_Elt::get_Jac_flux_fn ( const double  s) const

Get the Jacobian of the flux function evaluated for the concentration value stored in this elt.

Parameters
sThe local coordinate at which to evaluate
Returns
The Jacobian matrix

Definition at line 159 of file OneD_TVDLF_Elt.cpp.

159 {
160 DenseMatrix<double> J(system_ptr -> get_order(), system_ptr -> get_order(), 0.0);
161 double x(get_x(s));
162 system_ptr -> Jac_flux_fn(x, get_Q(s), J);
163 return J;
164 }

References get_Q(), get_x(), and system_ptr.

Referenced by contributed_flux_in_left(), and contributed_flux_out_right().

◆ get_max_dt()

double CppNoddy::OneD_TVDLF_Elt::get_max_dt ( ) const

Get the maximum allowable time step for this element by using information about the size of the element and the maximum wave speed set in the conservative system.

The time step is guranteed to satisfy the CFL < 0.5 constraint.

Returns
The maximum time step.

Definition at line 173 of file OneD_TVDLF_Elt.cpp.

173 {
174 // left face & right face speeds
175 return get_dx() / std::max(std::abs(system_ptr -> max_charac_speed(get_Q(-1.0))),
176 std::abs(system_ptr -> max_charac_speed(get_Q(1.0))));
177 }

References get_dx(), get_Q(), and system_ptr.

◆ get_Q()

DenseVector< double > CppNoddy::OneD_TVDLF_Elt::get_Q ( double  s) const
inline

Get the value of the 'concentration' stored in this element.

Parameters
sThe local coordinate in the elt at which Q is requested
Returns
The concentration value of the elt for each component

Definition at line 197 of file OneD_TVDLF_Elt.h.

197 {
198 return Q + SLOPE * s * (RIGHT - LEFT) / 2;
199 }

Referenced by contributed_flux_in_left(), contributed_flux_out_right(), get_flux_fn(), get_int_Q(), get_Jac_flux_fn(), get_max_dt(), and get_source_fn().

◆ get_s()

double CppNoddy::OneD_TVDLF_Elt::get_s ( double  x) const
inline

Convert a global coordinate into a local coordinate within this element If the global coordinate is outside the element, then we throw an exception.

Parameters
xThe global coordinate to convert

Definition at line 72 of file OneD_TVDLF_Elt.h.

72 {
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 }

◆ get_slope()

DenseVector< double > CppNoddy::OneD_TVDLF_Elt::get_slope ( ) const
inline

The concentration is approximated by a linear function in each element.

The slope of this function is got through this method.

Returns
The value of the 'slope' member data

Definition at line 222 of file OneD_TVDLF_Elt.h.

222 {
223 return SLOPE;
224 }

Referenced by get_source_fn().

◆ get_source_fn()

DenseVector< double > CppNoddy::OneD_TVDLF_Elt::get_source_fn ( const double  s) const

Get the value of the source function term in this element at a given local coordinate.

Parameters
sThe local coordinate to evaluate at

Definition at line 166 of file OneD_TVDLF_Elt.cpp.

166 {
167 DenseVector<double> r(system_ptr -> get_order(), 0.0);
168 double x(get_x(s));
169 system_ptr -> source_fn(x, get_Q(s), get_slope(), r);
170 return r;
171 }
DenseVector< double > get_slope() const
The concentration is approximated by a linear function in each element.
double source_fn(const std::pair< double, double > &coord)

References get_Q(), get_slope(), get_x(), and system_ptr.

Referenced by contributed_flux_in_left(), and contributed_flux_out_right().

◆ get_x()

double CppNoddy::OneD_TVDLF_Elt::get_x ( double  s) const
inline

Get the global position of the local coordinate.

Parameters
sThe local coordinate
Returns
The global position

Definition at line 185 of file OneD_TVDLF_Elt.h.

185 {
186 return (LEFT + RIGHT + s * get_dx()) / 2;
187 }

References get_dx().

Referenced by contributed_flux_in_left(), contributed_flux_out_right(), get_flux_fn(), get_Jac_flux_fn(), and get_source_fn().

◆ set_external_face_i()

void CppNoddy::OneD_TVDLF_Elt::set_external_face_i ( int  i)
inline

Set the local coordinate of the external face.

Only one face can be external.

Parameters
iThe index of the external face -1=left, +1=right

Definition at line 210 of file OneD_TVDLF_Elt.h.

210 {
211 EXTERNAL_FACE_I = i;
212 }

◆ set_external_flag()

void CppNoddy::OneD_TVDLF_Elt::set_external_flag ( bool  flag)
inline

Set the external flag.

Parameters
flagis the value to set

Definition at line 206 of file OneD_TVDLF_Elt.h.

206 {
207 EXTERNAL = flag;
208 }

◆ set_Q_mid()

void CppNoddy::OneD_TVDLF_Elt::set_Q_mid ( const DenseVector< double >  value)
inline

Set the value of the 'concentration' stored in this element.

To second order, this is the value of the concentration at the mid-point of the element.

Parameters
valueThe value to be assigned to the concentration member data Q

Definition at line 214 of file OneD_TVDLF_Elt.h.

214 {
215 Q = value;
216 }

◆ set_slope()

void CppNoddy::OneD_TVDLF_Elt::set_slope ( const DenseVector< double >  value)
inline

The concentration is approximated by a linear function in each element.

The slope of this function is set through this method.

Parameters
valueThe value to be assigned to the member data 'slope'

Definition at line 218 of file OneD_TVDLF_Elt.h.

218 {
219 SLOPE = value;
220 }

Member Data Documentation

◆ system_ptr

OneD_Hyperbolic_System* CppNoddy::OneD_TVDLF_Elt::system_ptr

The documentation for this class was generated from the following files:

© 2012

R.E. Hewitt