CppNoddy  0.92
Loading...
Searching...
No Matches
OneD_Hyperbolic_System.h
Go to the documentation of this file.
1/// \file OneD_Hyperbolic_System.h
2
3#ifndef ONED_HYPERBOLIC_SYSTEM_H
4#define ONED_HYPERBOLIC_SYSTEM_H
5
6#include <Types.h>
7#include <Uncopyable.h>
8#include <Timer.h>
9
10namespace CppNoddy {
11
12 /// A class to represent a one dimensional hyperbolic system of equations.
14
15 typedef std::vector<bool> bool_vec;
16
17 public:
18
19 /// \param order The order of the hyperbolic system
20 explicit OneD_Hyperbolic_System(const unsigned& order) : ORDER_OF_SYSTEM(order) {
21 }
22
23 /// An empty destructor, virtual since we have virtual methods.
25 {}
26
27 /// A virtual flux function
28 /// \param x The spatial coordinate
29 /// \param q The unknowns
30 /// \param f The flux function
31 virtual void flux_fn(const double &x, const DenseVector<double> &q, DenseVector<double> &f) const {
32 std::string problem;
33 problem = "The Hyperbolic_Conservative_System::flux_fn method has not been implemented.\n";
34 problem += "You have to implement this method to define the system.\n";
35 throw ExceptionRuntime(problem);
36 }
37
38 /// A virtual function function to define the Jacobian of the
39 /// flux function. The default method uses first-order finite
40 /// differencing to compute the Jacobian if not otherwise specified
41 /// by the user.
42 /// \param x The position
43 /// \param q The unknowns
44 /// \param J The Jacobian of the flux function
45 virtual void Jac_flux_fn(const double &x, const DenseVector<double> &q, DenseMatrix<double> &J) const {
46 /// first order differencing is the default unless overloaded
47 double delta(1.e-8);
48 DenseVector<double> state(q);
51 flux_fn(x, q, temp1);
52 // default is to FD the Jacobian
53 for(std::size_t i = 0; i < ORDER_OF_SYSTEM; ++i) {
54 state[ i ] += delta;
55 flux_fn(x, state, temp2);
56 state[ i ] -= delta;
57 J.set_col(i, (temp2 - temp1) / delta);
58 }
59 }
60
61 /// A virtual method that is used to bound the shock speed and
62 /// must be implemented by the user.
63 /// \param q The unknowns
64 /// \return A bound on the maximum wave speed
65 virtual double max_charac_speed(const DenseVector<double> &q) const {
66 std::string problem;
67 problem = "The Hyperbolic_Conservative_System::max_shock_speed method has not\n";
68 problem += "been implemented. You have to implement this method to define the system.\n";
69 throw ExceptionRuntime(problem);
70 }
71
72 /// Define the edge boundary conditions.
73 /// \param face_index An index for the face:
74 /// -1=left +1=right for OneD_TVDLF_Mesh
75 /// \param x The position vector along the face
76 /// \param q The unknowns specified along the face
77 /// \param t A time for unsteady edge conditions
78 virtual bool_vec edge_values(const int face_index, const double& x, DenseVector<double>& q, const double &t = 0.0) const {
79 return std::vector<bool>(ORDER_OF_SYSTEM, false);
80 }
81
82 virtual void source_fn(const double &x, const DenseVector<double> &q, const DenseVector<double> &slope, DenseVector<double>& r) const {
83 }
84
85 unsigned get_order() {
86 return ORDER_OF_SYSTEM;
87 }
88
89 protected:
90
91 /// The order of the system of equations
92 const std::size_t ORDER_OF_SYSTEM;
93 }
94 ; // end class
95
96} // end namespace
97
98#endif
@ f
Definition: BVPBerman.cpp:15
A spec for the CppNoddy Timer object.
Some standard typedefs.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
Definition: DenseMatrix.h:25
void set_col(const std::size_t &col, const DenseVector< _Type > &x)
Set a column of the matrix.
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.
virtual ~OneD_Hyperbolic_System()
An empty destructor, virtual since we have virtual methods.
virtual void source_fn(const double &x, const DenseVector< double > &q, const DenseVector< double > &slope, DenseVector< double > &r) const
virtual void flux_fn(const double &x, const DenseVector< double > &q, DenseVector< double > &f) const
A virtual flux function.
const std::size_t ORDER_OF_SYSTEM
The order of the system of equations.
virtual double max_charac_speed(const DenseVector< double > &q) const
A virtual method that is used to bound the shock speed and must be implemented by the user.
OneD_Hyperbolic_System(const unsigned &order)
virtual void Jac_flux_fn(const double &x, const DenseVector< double > &q, DenseMatrix< double > &J) const
A virtual function function to define the Jacobian of the flux function.
virtual bool_vec edge_values(const int face_index, const double &x, DenseVector< double > &q, const double &t=0.0) const
Define the edge boundary conditions.
An object to block copying.
Definition: Uncopyable.h:8
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt