22 cout <<
"=== OneD_Node_Mesh: wrapper =========================\n";
24 cout <<
" The test checks the convergence rate for an integral \n";
25 cout <<
" over an increasing number of mesh points. \n\n";
27 double error_trapezium = 1.0;
28 double error_Simpson = 1.0;
29 double error_remesh = 1.0;
30 double error_diffroot = 0.0;
33 double old_integral = 0.0;
34 double integral = 0.0;
36 const unsigned jmax = 8;
37 for (
unsigned j = 1; j <= jmax ; ++j )
46 for ( std::size_t i = 0; i < n; ++i )
49 Q( i, 0 ) = cos( Q.
coord( i ) );
53 integral = std::abs( Q.
integral2( 0 ) - sin( 1.0 ) );
57 cout <<
" n = " << n <<
" |Integral Error| = " << integral
58 <<
" Ratio = " << old_integral / integral <<
"\n";
60 old_integral = integral;
62 error_trapezium = integral;
65 cout <<
"\n Checking Simpson integration routine \n\n";
68 double old_integral = 0.0;
69 double integral = 0.0;
71 const unsigned jmax = 8;
72 for (
unsigned j = 1; j <= jmax ; ++j )
81 for ( std::size_t i = 0; i < n; ++i )
84 Q( i, 0 ) = cos( Q.
coord( i ) );
88 integral = std::abs( Q.
integral4( 0 ) - sin( 1.0 ) );
92 cout <<
" n = " << n <<
" |Integral Error| = " << integral
93 <<
" Ratio = " << old_integral / integral <<
"\n";
95 old_integral = integral;
97 error_Simpson = integral;
100 std::cout <<
"\n Checking the mesh linear interpolation. \n";
102 const std::size_t n = 501;
107 for ( std::size_t i = 0; i < n; ++i )
110 Q( i, 0 ) = std::cos( Q.
coord( i ) );
114 const double Inonuniform = std::abs( Q.
integral2( 0 ) );
122 const double Iuniform = std::abs( Q.
integral2( 0 ) );
123 error_remesh = std::abs( Inonuniform - Iuniform );
125 std::cout <<
" |error| = " << error_remesh <<
"\n";
129 std::cout <<
"\n Checking mesh root interpolation. \n";
131 const std::size_t n = 401;
135 for ( std::size_t i = 0; i < n; ++i )
138 F( i, 0 ) = std::sin( F.
coord( i ) );
145 for ( std::size_t i = 0; i < roots.
size(); ++i )
148 error_diffroot = std::max( std::abs( roots[ i ] - ( i + 1 ) * M_PI ) , error_diffroot );
154 if ( ( error_trapezium > 1.e-6 ) || ( error_Simpson > 1.e-12 )
155 || ( error_remesh > 1.e-6 ) || ( error_diffroot > 1.e-6 ) )
157 cout <<
"\033[1;31;48m * FAILED \033[0m\n";
162 cout <<
"\033[1;32;48m * PASSED \033[0m\n";
A specification for a one dimensional mesh object.
A spec for a collection of utility functions.
An DenseVector class – a dense vector object.
std::size_t size() const
A pass-thru definition to get the size of the vector.
A one dimensional mesh utility object.
const _Xtype & coord(const std::size_t &node) const
Access a nodal position.
_Type integral4(std::size_t var=0) const
Integrate over the domain with a Simpson rule.
DenseVector< double > find_roots1(const std::size_t &var, double value=0.0) const
Find a list of approximate locations at which a specified variable attains a given value.
_Type integral2(std::size_t var=0) const
Integrate over the domain.
void remesh1(const DenseVector< _Xtype > &z)
Interpolate this mesh data (linearly) into a new mesh with nodal points defined in the argument list.
DenseVector< double > power_node_vector(const double &lower, const double &upper, const std::size_t &N, const double &power)
Return a DENSE vector with the nodal points of a non-uniform mesh distributed between the upper/lower...
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...