CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
IBVPNonlinearSlower.cpp File Reference

Solving the nonlinear problem. More...

#include <IBVP_double_bundle.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Classes

class  CppNoddy::Example::nonlinear
 
class  CppNoddy::Example::BC_lower
 
class  CppNoddy::Example::BC_upper
 

Namespaces

namespace  CppNoddy
 A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechanics.
 
namespace  CppNoddy::Example
 

Enumerations

enum  { U , Ud }
 

Functions

double CppNoddy::Example::source (const double &x, const double &y, const double &t)
 
int main ()
 

Detailed Description

Solving the nonlinear problem.

\[ -u u_x - u_t + u_{yy} = y^2 t^2 e^{-2x} - y e^{-x}\,, \]

subject to $ u(x=0,y,t) = ty $, $ u(x,t=0,y) = 0 $ and $ f(x, y = 0,t ) = 0 $, $ f(x, y = 1,t ) = t $. The solution is computed over a range of $ t $ for $ (x,y) \in [0,10]\times [0,1] $ and the maximum deviation away from the exact solution $ u = yte^{-x} $ is found. The test fails if this deviation is larger than a set tolerance $ \tau $. The example is solved using the PDE_double_IBVP for problems that are parabolic in 2 coordinates $ (x,t) $ with a BVP in $ y $.

Definition in file IBVPNonlinearSlower.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
Ud 

Definition at line 18 of file IBVPNonlinearSlower.cpp.

18{ U, Ud };

Function Documentation

◆ main()

int main ( )

Definition at line 100 of file IBVPNonlinearSlower.cpp.

101{
102 cout << "\n";
103 cout << "=== double_IBVP: non-constant mass matrix example ===\n";
104 cout << "\n";
105
106 // instantiate the problem
107 Example::nonlinear problem;
108 Example::BC_lower BC_bottom;
109 Example::BC_upper BC_top;
110
111 // domain definition
112 double top = 1.0;
113 double bottom = 0.0;
114 double left = 0.0;
115 double right = 10.0;
116 // number of (spatial) nodal points
117 unsigned ny = 11;
118 unsigned nx = 1001;
119 // time and time step
120 double t_end = 1.;
121 double dt = 0.01;
122
123 // construct our IBVP
124 PDE_double_IBVP<double> nlin( &problem,
125 Utility::uniform_node_vector( left, right, nx ),
126 Utility::uniform_node_vector( bottom, top, ny ),
127 &BC_bottom, &BC_top );
128
129 // initial conditions
130 for ( unsigned i = 0; i < nx; ++i )
131 {
132 for ( unsigned j = 0; j < ny; ++j )
133 {
134 nlin.solution()( i, j, U ) = 0.0;
135 nlin.solution()( i, j, Ud ) = 0.0;
136 }
137 }
138
139 double max_error( 0.0 );
140 int counter( 0 );
141 do
142 {
143 // inlet profile is time dependent, so we set it here for the next time level
144 nlin.update_previous_solution();
145 // now we can alter the solution stored in the double_IBVP class to define
146 // the desired x=0 'initial' conditions at the next time step
147 double t_next = nlin.t() + dt;
148 for ( unsigned j = 0; j < ny; ++j )
149 {
150 double y = nlin.solution().coord( 0, j ).second;
151 nlin.solution()( 0, j, U ) = t_next * y;
152 nlin.solution()( 0, j, Ud ) = t_next;
153 }
154 nlin.step2( dt );
155 for ( unsigned i = 0; i < nx; ++i )
156 {
157 for ( unsigned j = 0; j < ny; ++j )
158 {
159 double x = nlin.solution().coord( i, j ).first;
160 double y = nlin.solution().coord( i, j ).second;
161 double exact_u = y * nlin.t() * exp( - x );
162 max_error = max( max_error, abs( exact_u - nlin.solution()( i, j, U ) ) );
163 }
164 }
165 ++counter;
166 }
167 while ( nlin.t() < t_end );
168
169 const double tol( 1.e-4 );
170 // check the error from the exact solution
171 if ( max_error > tol )
172 {
173 cout << "\033[1;31;48m * FAILED \033[0m\n";
174 cout << " Difference = " << max_error << "\n";
175 return 1;
176 }
177 else
178 {
179 cout << "\033[1;32;48m * PASSED \033[0m\n";
180 return 0;
181 }
182
183}
A templated object for real/complex vector system of unsteady equations.
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...
Definition: Utility.cpp:113

References CppNoddy::PDE_double_IBVP< _Type >::solution(), CppNoddy::PDE_double_IBVP< _Type >::step2(), CppNoddy::PDE_double_IBVP< _Type >::t(), U, Ud, CppNoddy::Utility::uniform_node_vector(), and CppNoddy::PDE_double_IBVP< _Type >::update_previous_solution().

© 2012

R.E. Hewitt