101{
102 cout << "\n";
103 cout << "=== IBVP: A nonlinear diffusion problem ============\n";
104 cout << "\n";
105
106
107 Example::Diffusion_equations problem;
108
109 Example::Diffusion_left_BC BC_left;
110 Example::Diffusion_right_BC BC_right;
111
112
113 double left = 0.0;
114 double right = 1.0;
115
116 unsigned ny = 400;
117
118 double dt = 0.005;
119
120 unsigned max_steps = ( unsigned ) ( 2.0 / dt );
121
122
124
125 for ( unsigned i = 0; i < ny; ++i )
126 {
127 double y( diffusion.solution().coord(i) );
128 diffusion.solution()( i,
U ) = (1+y) + Example::A*sin(M_PI*y);
129 diffusion.solution()( i,
Ud ) = 1 + Example::A*M_PI*cos(M_PI*y);
130 }
131
132
133 std::string dirname("./DATA");
134 mkdir( dirname.c_str(), S_IRWXU );
135 TrackerFile metric(
"./DATA/IBVP_diffusion_metric.dat" );
136 metric.push_ptr( &diffusion.coord(), "time" );
137 metric.push_ptr( &diffusion.solution()( 0,
Ud ),
"y=0 derivative" );
138 metric.header();
139 TrackerFile profs(
"./DATA/IBVP_diffusion_profs.dat" );
140 profs.push_ptr( &diffusion.coord(), "time" );
141 profs.push_ptr( &diffusion.solution(), "solution" );
142 profs.header();
143
146
147 double max_error( 0.0 );
148
149 for ( unsigned i = 1; i < max_steps; ++i )
150 {
151
152 try
153 {
154 diffusion.step2( dt );
155 }
156 catch (const std::runtime_error &error )
157 {
158 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
159 return 1;
160 }
161 if ( i % 20 == 0 )
162 {
163 cout << diffusion.coord() << "\n";
164 profs.update();
165 profs.newline();
166 }
168 metric.update();
169
170 double yy( 0.5 );
171 double Uexact = 1 + yy + Example::A*exp(-diffusion.coord())*sin(M_PI*yy);
172 double error = diffusion.solution().get_interpolated_vars( 0.5 )[
U ] - Uexact;
173 max_error = std::max( std::abs( error ), max_error );
174
175
176 }
179
180 const double tol( 1.e-4 );
181
182 if ( max_error > tol )
183 {
184 cout << "\033[1;31;48m * FAILED \033[0m\n";
185 cout << " Max difference over time steps = " << max_error << "\n";
186 return 1;
187 }
188 else
189 {
190 cout << "\033[1;32;48m * PASSED \033[0m\n";
191 return 0;
192 }
193
194}
A templated object for real/complex vector system of unsteady equations.
A simple CPU-clock-tick timer for timing metods.
void start()
Start the timer & reset stored time to zero.
int & counter()
Increment an internal discrete counter.
void print() const
Write a string to cout stating the time taken.
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
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...