84{
85 cout << "\n";
86 cout << "=== IBVP: An unsteady diffusion eqn =================\n";
87 cout << "\n";
88
89
90 Example::Diff_equation problem;
91
92 Example::Diff_both_BC BC_both;
93
94
95 double left = 0.0;
96 double right = 1.0;
97
98 unsigned ny = 201;
99
100 double dt = 0.005;
101
102 unsigned max_steps = ( unsigned ) ( 3.0 / dt );
103
104 double tol = 1.e-4;
105
106
108
109 for ( unsigned i = 0; i < ny; ++i )
110 {
111 double y = heat.solution().coord( i );
112 heat.solution()( i,
f ) = y * ( 1 - y );
113 heat.solution()( i,
fd ) = 1 - 2 * y;
114 }
115
116
117 double max_diff( 0.0 );
118
119 for ( unsigned i = 1; i < max_steps; ++i )
120 {
121
122 try
123 {
124 heat.step2( dt );
125 }
126 catch (const std::runtime_error &error )
127 {
128 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
129 return 1;
130 }
131
132
133 unsigned mid = ( ny - 1 ) / 2;
134 double y = left + mid * ( right - left ) / ( ny - 1 );
136 int en( -1 );
137 double correction( 0.0 );
138 do
139 {
140 en += 2;
141 correction = 8 / ( std::pow( en * M_PI, 3 ) )
142 * std::exp( -std::pow( en * M_PI, 2 ) * heat.coord() ) * std::sin( en * M_PI * y );
144 }
145 while ( std::abs( correction ) > tol / 10. );
146
147 max_diff = std::max( max_diff, std::abs(
u - heat.solution()( mid,
f ) ) );
148 }
149
151 if ( abs( max_diff ) < tol )
152 {
154 }
155
156 if ( failed )
157 {
158 cout << "\033[1;31;48m * FAILED \033[0m\n";
159 return 1;
160 }
161 else
162 {
163 cout << "\033[1;32;48m * PASSED \033[0m\n";
164 return 0;
165 }
166
167}
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...