CppNoddy  0.92
Loading...
Searching...
No Matches
TwoD_Hyperbolic_System.h
Go to the documentation of this file.
1/// \file TwoD_Hyperbolic_System.h
2
3#ifndef TWOD_HYPERBOLIC_SYSTEM_H
4#define TWOD_HYPERBOLIC_SYSTEM_H
5
6#include <Types.h>
7#include <Uncopyable.h>
8#include <Timer.h>
9
10namespace CppNoddy {
11 /// A class to represent a two-dimensional hyperbolic system of equations.
13
14 public:
15
16 /// \param order The order of the hyperbolic system
17 explicit TwoD_Hyperbolic_System(const unsigned& order) : ORDER_OF_SYSTEM(order)
18 {}
19
20 /// An empty destructor, virtual since we have virtual methods.
22 {}
23
24 /// A virtual flux function for the x-derivative
25 /// \param x The vector position
26 /// \param q The unknowns
27 /// \param f The flux function
28 virtual void flux_fn_x(const DenseVector<double> &x, const DenseVector<double> &q, DenseVector<double> &f) const {
29 std::string problem;
30 problem = "The Hyperbolic_Conservative_System::flux_fn_x method has not been implemented.\n";
31 problem += "You have to implement this method to define the system.\n";
32 throw ExceptionRuntime(problem);
33 }
34
35 /// A virtual flux function for the y-derivative
36 /// \param x The vector position
37 /// \param q The unknowns
38 /// \param f The flux function
39 virtual void flux_fn_y(const DenseVector<double> &x, const DenseVector<double> &q, DenseVector<double> &f) const {
40 std::string problem;
41 problem = "The Hyperbolic_Conservative_System::flux_fn_y method has not been implemented.\n";
42 problem += "You have to implement this method to define the system.\n";
43 throw ExceptionRuntime(problem);
44 }
45
46 /// A virtual function function to define the Jacobian of the
47 /// x-flux function. The default method uses first-order finite
48 /// differencing to compute the Jacobian if not otherwise specified
49 /// by the user.
50 /// \param x The vector position
51 /// \param q The unknowns
52 /// \param J The Jacobian of the flux function
53 virtual void Jac_flux_fn_x(const DenseVector<double> &x, const DenseVector<double> &q, DenseMatrix<double> &J) const {
54 /// cheap & nasty differencing
55 const double delta(1.e-8);
56 DenseVector<double> state(q);
59 flux_fn_x(x, state, temp1);
60 // default is to FD the Jacobian
61 for(std::size_t i = 0; i < ORDER_OF_SYSTEM; ++i) {
62 state[ i ] += delta;
63 flux_fn_x(x, state, temp2);
64 state[ i ] -= delta;
65 J.set_col(i, (temp2 - temp1) / delta);
66 }
67 }
68
69 /// A virtual function function to define the Jacobian of the
70 /// y-flux function. The default method uses first-order finite
71 /// differencing to compute the Jacobian if not otherwise specified
72 /// by the user.
73 /// \param x The vector position
74 /// \param q The unknowns
75 /// \param J The Jacobian of the flux function
76 virtual void Jac_flux_fn_y(const DenseVector<double> &x, const DenseVector<double> &q, DenseMatrix<double> &J) const {
77 /// cheap & nasty differencing
78 const double delta(1.e-8);
79 DenseVector<double> state(q);
82 flux_fn_y(x, state, temp1);
83 // default is to FD the Jacobian
84 for(std::size_t i = 0; i < ORDER_OF_SYSTEM; ++i) {
85 state[ i ] += delta;
86 flux_fn_y(x, state, temp2);
87 state[ i ] -= delta;
88 J.set_col(i, (temp2 - temp1) / delta);
89 }
90 }
91
92 /// A virtual method that is used to bound the characteristic speed in both directions.
93 /// It determines the time step in order that the CFL constraint holds. It is sometimes
94 /// required to specify a speed that is a function of position and to even specify the
95 /// two-directional speeds. eg. your mesh may actually be w.r.t. a polar coordinate
96 /// system in which the physical mesh size grows linearly with radius, so one of the
97 /// speeds should be scaled accordingly.
98 /// \param x The global coordinate
99 /// \param q The unknowns
100 /// \param c The speed
102 std::string problem;
103 problem = "The Hyperbolic_Conservative_System::max_charac_speed method has not\n";
104 problem += "been implemented. You have to implement this method to define the system.\n";
105 throw ExceptionRuntime(problem);
106 }
107
108 /// Define the edge boundary conditions.
109 /// \param face_index An index for the face:
110 /// 0,1,2,3 for S,E,N,W on the TwoD_TVDLF_Mesh
111 /// \param x The global position vector
112 /// \param q Specify the unknowns specified along the face
113 /// \return A vector that defines which components have been set as inflow
114 virtual std::vector<bool> edge_values(const int& face_index, const DenseVector<double>& x, DenseVector<double>& q) const {
115 return std::vector<bool>(ORDER_OF_SYSTEM, false);
116 }
117
118 /// Define the edge boundary condition slopes.
119 /// These default to zero unless otherwise over-ridden.
120 /// \param face_index An index for the face:
121 /// 0,1,2,3 for S,E,N,W on the TwoD_TVDLF_Mesh
122 /// \param x The global position vector
123 /// \param sigma_n Specify the slope normal to the face
124 virtual void edge_slopes(const int& face_index, const DenseVector<double>& x, DenseVector<double>& sigma_n) const {
125 }
126
127 virtual void source_fn(const DenseVector<double> &x, const DenseVector<double> &q, DenseVector<double>& r) const {
128 }
129
130 unsigned get_order() {
131 return ORDER_OF_SYSTEM;
132 }
133
134 protected:
135
136 /// The order of the system of equations
137 const unsigned ORDER_OF_SYSTEM;
138 }
139 ; // end class
140
141} // end namespace
142
143#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 two-dimensional hyperbolic system of equations.
TwoD_Hyperbolic_System(const unsigned &order)
virtual void flux_fn_y(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &f) const
A virtual flux function for the y-derivative.
virtual void max_charac_speed(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &c) const
A virtual method that is used to bound the characteristic speed in both directions.
virtual void flux_fn_x(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &f) const
A virtual flux function for the x-derivative.
const unsigned ORDER_OF_SYSTEM
The order of the system of equations.
virtual void Jac_flux_fn_y(const DenseVector< double > &x, const DenseVector< double > &q, DenseMatrix< double > &J) const
A virtual function function to define the Jacobian of the y-flux function.
virtual ~TwoD_Hyperbolic_System()
An empty destructor, virtual since we have virtual methods.
virtual void edge_slopes(const int &face_index, const DenseVector< double > &x, DenseVector< double > &sigma_n) const
Define the edge boundary condition slopes.
virtual void source_fn(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &r) const
virtual std::vector< bool > edge_values(const int &face_index, const DenseVector< double > &x, DenseVector< double > &q) const
Define the edge boundary conditions.
virtual void Jac_flux_fn_x(const DenseVector< double > &x, const DenseVector< double > &q, DenseMatrix< double > &J) const
A virtual function function to define the Jacobian of the x-flux function.
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