30 const double eps( 2.0 );
32 double source(
const double& y,
const double& t )
34 return ( 1 + y +
eps * y * ( 1 - y ) * std::exp( -t ) ) *
eps * y * ( 1 - y ) * std::exp( -t )
35 - 2 *
eps * std::exp( - t ) /
Re;
67 m( 1, 0 ) = -
Re *
z[
U ];
72 h( 1,
U ) = -
Re * vec[ 0 ];
85 b[ 0 ] =
z[
U ] - 1.0;
96 b[ 0 ] =
z[
U ] - 2.0;
110 cout <<
"=== IBVP: Nonlinear advection diffusion =============\n";
124 unsigned max_steps = 4000;
126 double dt = 1.0 / ( max_steps - 1 );
135 for (
unsigned i = 0; i < ny; ++i )
137 double y = advection.
solution().coord( i );
138 advection.
solution()( i,
U ) = 1.0 + y + Example::eps * y * ( 1 - y );
143 std::string dirname(
"./DATA");
144 mkdir( dirname.c_str(), S_IRWXU );
145 TrackerFile my_file(
"./DATA/IBVP_NlinAdvection.dat" );
150 double max_err( 0.0 );
152 for (
unsigned i = 1; i < max_steps; ++i )
157 advection.
step2( dt );
159 catch (
const std::runtime_error &error )
161 cout <<
" \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
170 for (
unsigned i = 0; i < ny; ++i )
172 double y = advection.
solution().coord( i );
173 const double exact_solution = 1.0 + y + Example::eps * y * ( 1 - y ) * std::exp( -advection.
coord() );
174 max_err = std::max( max_err, std::abs( advection.
solution()( i, 0 ) - exact_solution ) );
178 if ( max_err > 1.e-6 )
180 cout <<
"\033[1;31;48m * FAILED \033[0m\n";
181 cout.precision( 14 );
182 cout << 1. / ( ny - 1 ) <<
" " << dt <<
" " << max_err <<
"\n";
187 cout <<
"\033[1;32;48m * PASSED \033[0m\n";
A shorter bundled include file for initial boundary value problems.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
An DenseVector class – a dense vector object.
An equation object base class used in the PDE_double_IBVP class.
void matrix0(const DenseVector< double > &z, DenseMatrix< double > &m) const
Define the derivative terms by providing the mass matrix – identity in this case.
void residual_fn(const DenseVector< double > &z, DenseVector< double > &f) const
Define a nonlinear advection diffusion problem.
void get_jacobian_of_matrix1_mult_vector(const DenseVector< double > &state, const DenseVector< double > &vec, DenseMatrix< double > &h) const
Return the product of the Jacobian-of-the-matrix and a vector 'vec' when the equation has a given 'st...
void matrix1(const DenseVector< double > &z, DenseMatrix< double > &m) const
Define the unsteady terms by providing the mass matrix.
void get_jacobian_of_matrix0_mult_vector(const DenseVector< double > &state, const DenseVector< double > &vec, DenseMatrix< double > &h) const
Nlin_adv_equation()
The problem is 2nd order and real.
void residual_fn(const DenseVector< double > &z, DenseVector< double > &b) const
void residual_fn(const DenseVector< double > &z, DenseVector< double > &b) const
A templated object for real/complex vector system of unsteady equations.
void step2(const double &dt)
A Crank-Nicolson 'time' stepper.
OneD_Node_Mesh< _Type > & solution()
double & coord()
Return a reference to the current value of the 'timelike/parabolic' coordinate.
A base class to be inherited by objects that define residuals.
_Xtype & coord(const unsigned &i)
General handle access to the coordinates.
void push_ptr(double *scalar, std::string desc="")
double Re
Globally define the Reynolds number and wavenumber.
double source(const double &x, const double &y, const double &t)
DenseVector< double > uniform_node_vector(const double &lower, const double &upper, const std::size_t &N)
Return a DENSE vector with the nodal points of a uniform mesh distributed between the upper/lower bou...
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...