8 #ifndef _EXAMPLES__VANDERPOL__VDP_SWEEPER_HPP_
9 #define _EXAMPLES__VANDERPOL__VDP_SWEEPER_HPP_
52 template<
typename time = pfasst::time_precision>
101 this->output_file.open(
"./vanderpol.txt", ios_base::out);
104 this->output_file << x0 <<
" " << y0 << endl;
112 ML_LOG(INFO,
"Number of implicit evaluations:" << this->n_f_impl_eval);
113 ML_LOG(INFO,
"Number of implicit solves: " << this->n_impl_solve);
114 this->output_file.close();
126 auto& qend = encap::as_vector<double, time>(this->get_end_state());
128 real_vector_type qex(qend.size());
134 double max_err =
max(abs(qend[0] - qex[0])/abs(qex[0]) , abs(qend[1]-qex[1])/abs(qex[1]) );
135 ML_LOG(INFO,
"error:" << max_err);
136 this->error = max_err;
138 this->output_file << qend[0] <<
" " << qend[1] << endl;
154 time
t = this->get_controller()->get_time();
155 time
dt = this->get_controller()->get_step_size();
156 this->echo_error(t + dt);
164 time
t = this->get_controller()->get_time();
165 time
dt = this->get_controller()->get_step_size();
166 this->echo_error(t + dt);
193 q[0] = this->y0*sin(t) + this->x0*cos(t);
194 q[1] = -this->x0*sin(t) + this->y0*cos(t);
205 void exact(shared_ptr<encap_type> q_encap, time
t)
207 auto& q = encap::as_vector<double, time>(q_encap);
215 shared_ptr<encap_type> q_encap, time
t)
override
218 auto& f = encap::as_vector<double, time>(f_encap);
219 auto& q = encap::as_vector<double, time>(q_encap);
224 f[1] = this->nu*(1.0-q[0]*q[0])*q[1] - q[0];
226 this->n_f_impl_eval++;
235 shared_ptr<encap_type> q_encap, time
t, time
dt,
236 shared_ptr<encap_type> rhs_encap)
override
239 auto& f = encap::as_vector<double, time>(f_encap);
240 auto& q = encap::as_vector<double, time>(q_encap);
241 auto& rhs = encap::as_vector<double, time>(rhs_encap);
271 double residual = this->newton_tol + 1.0;
281 double f0 = -( q[0] - dt*q[1] - rhs[0] );
282 double f1 = -( q[1] - dt*( this->nu*(1-q[0]*q[0])*q[1]-q[0]) - rhs[1] );
307 double a = dt * q[0] * q[0] - dt + 1.0;
308 double b = -2.0 * dt * this->nu * q[0] * q[1] -
dt;
309 double c = 2.0 * this->nu * q[0] * q[1] * dt * dt + dt * dt + dt * q[0] * q[0] - dt + 1.0;
312 f[0] = (1.0/c)*( a*f0 + dt*f1 );
313 f[1] = (1.0/c)*( b*f0 + f1 );
320 residual = fmax( abs(f[0]), abs(f[1]) ) / fmax( abs(q[0]), abs(q[1]) );
323 this->n_newton_iter++;
325 }
while ( (iter<this->newton_maxit) && (residual>this->newton_tol) );
329 if (residual >=this->newton_tol)
331 cout <<
"Newton failed to converge: res = " << scientific << residual <<
" -- n_iter = " << iter <<
" of maxit = " << this->newton_maxit << endl;
336 f[1] = this->nu*(1.0-q[0]*q[0])*q[1] - q[0];
338 this->n_impl_solve++;
345 #endif // _EXAMPLES__VANDERPOL__VDP_SWEEPER_HPP_
void echo_error(time t)
computes and prints out error, which is meaningful only for \( \nu=0 \).
void f_impl_eval(shared_ptr< encap_type > f_encap, shared_ptr< encap_type > q_encap, time t) override
Evaluate the implicit part of the right hand side.
size_t newton_maxit
Maximum number of iterations for the nonlinear Newton solver.
Sweeper for the van der Pol oscillator.
double get_errors()
returns error, but does not update it!
virtual ~VdpSweeper()
upon destruction, report final error and number of function calls and close output file...
void impl_solve(shared_ptr< encap_type > f_encap, shared_ptr< encap_type > q_encap, time t, time dt, shared_ptr< encap_type > rhs_encap) override
for given \( b \), solve \( \left( u - \Delta t f(u) \right) u = b \) for \( u \) and set f_encap to ...
double newton_tol
Tolerance for the nonlinear Newton iteration.
void exact(real_vector_type &q, time t)
if \( \nu=0 \), this computes the exact solution at time t.
#define ML_LOG(level, x)
same as LOG(level, x) from easylogging++
encap::Encapsulation< time > encap_type
double error
error: For \( \nu=0 \), vdP reduces to linear oscillator, otherwise no analytic solution is available...
VdpSweeper(double nu, double x0, double y0)
generic constructor; initialize all function call counters with zero.
encap::VectorEncapsulation< double > real_vector_type
Define a type for a complex PFASST vector encapsulation.
static precision max(const vector< precision > &data)
Data/solution encapsulation.
void post_predict() override
post prediction step, update error.
#define UNUSED(expr)
Denoting unused function parameters for omitting compiler warnings.
fstream output_file
Output file.
void post_sweep() override
post sweep, update error.
void exact(shared_ptr< encap_type > q_encap, time t)
double nu
Parameter \( \nu \) in the van-der-Pol oscillator.