78{
79 cout << "\n";
80 cout << "=== BVP: finite-difference solution of Harmonic eqn =\n";
81 cout << "\n";
82
83 Example::Harmonic_equation<double, double> real_problem;
84 Example::Harmonic_left_BC <double> real_BC_left;
85 Example::Harmonic_right_BC<double> real_BC_right;
86 Example::Harmonic_equation<D_complex, D_complex> complex_problem;
87 Example::Harmonic_left_BC <D_complex> complex_BC_left;
88 Example::Harmonic_right_BC<D_complex> complex_BC_right;
89
90 double left = 0.0;
91 double right = 1.0;
92
93 unsigned N = 21;
94
96
100
101 const double tol = 1.e-4;
102
103
104 ODE_BVP<double> real_ode( &real_problem, real_nodes, &real_BC_left, &real_BC_right );
105
107 complex_ode.set_monitor_det( false );
108
109
110 for ( unsigned i = 0; i < N; ++i )
111 {
112 double y = real_ode.solution().coord( i );
113
114 real_ode.solution()( i,
f ) = y;
115 complex_ode.solution()( i,
f ) = y;
116
117 real_ode.solution()( i,
fd ) = 1;
118 complex_ode.solution()( i,
fd ) = 1;
119 }
120
121
122 try
123 {
124 real_ode.solve2();
125 complex_ode.solve2();
126 }
127 catch ( const std::runtime_error &error )
128 {
129 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
130 return 1;
131 }
132
133
134 double real_diff = 0;
135 double complex_diff = 0;
136 for ( unsigned i = 0; i < N; ++i )
137 {
138 real_diff = std::max( std::abs( real_ode.solution()( i,
f ) - sin( real_ode.solution().coord( i ) ) / sin( 1 ) ), real_diff );
139 complex_diff = std::max( std::abs( complex_ode.solution()( i,
f ) - sin( complex_ode.solution().coord( i ) ) / sin( eye ) ), complex_diff );
140 }
141
142
143 if ( real_diff > tol || complex_diff > tol )
144 {
145 cout << "\033[1;31;48m * FAILED \033[0m\n";
146 cout << "Real problem error " << real_diff << "\n";
147 cout << "Complex problem error " << complex_diff << "\n";
148 return 1;
149 }
150 else
151 {
152 cout << "\033[1;32;48m * PASSED \033[0m\n";
153 return 0;
154 }
155}
An DenseVector class – a dense vector object.
A templated object for real/complex vector system of first-order ordinary differential equations.
const D_complex eye(0., 1.0)
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...
std::complex< double > D_complex
A complex double precision number using std::complex.