14 #ifndef _EXAMPLES__SCALAR__SCALAR_SWEEPER_HPP_
15 #define _EXAMPLES__SCALAR__SCALAR_SWEEPER_HPP_
50 template<
typename time = pfasst::time_precision>
61 complex<double> lambda,
u0;
64 const complex<double> i_complex = complex<double>(0, 1);
93 ML_LOG(INFO,
"Final error: " << this->error);
94 ML_LOG(INFO,
"Number of explicit evaluations:" << this->n_f_expl_eval);
95 ML_LOG(INFO,
"Number of implicit evaluations:" << this->n_f_impl_eval);
96 ML_LOG(INFO,
"Number of implicit solves: " << this->n_impl_solve);
106 auto& qend = encap::as_vector<complex<double>, time>(this->get_end_state());
108 complex_vector_type qex(qend.size());
111 double max_err = abs(qend[0] - qex[0]) / abs(qex[0]);
112 ML_LOG(INFO,
"err:" << max_err);
113 this->error = max_err;
129 time
t = this->get_controller()->get_time();
130 time
dt = this->get_controller()->get_step_size();
131 this->echo_error(t + dt);
139 time
t = this->get_controller()->get_time();
140 time
dt = this->get_controller()->get_step_size();
141 this->echo_error(t + dt);
149 void exact(complex_vector_type& q, time
t)
151 q[0] = this->u0 * exp(this->lambda * t);
154 void exact(shared_ptr<encap_type> q_encap, time
t)
156 auto& q = encap::as_vector<complex<double>, time>(q_encap);
164 shared_ptr<encap_type> q_encap, time
t)
override
167 auto& f = encap::as_vector<complex<double>, time>(f_encap);
168 auto& q = encap::as_vector<complex<double>, time>(q_encap);
171 f[0] = this->i_complex * imag(this->lambda) * q[0];
173 this->n_f_expl_eval++;
180 shared_ptr<encap_type> q_encap, time
t)
override
183 auto& f = encap::as_vector<complex<double>, time>(f_encap);
184 auto& q = encap::as_vector<complex<double>, time>(q_encap);
187 f[0] = real(this->lambda) * q[0];
189 this->n_f_impl_eval++;
198 shared_ptr<encap_type> q_encap, time
t, time
dt,
199 shared_ptr<encap_type> rhs_encap)
override
202 auto& f = encap::as_vector<complex<double>, time>(f_encap);
203 auto& q = encap::as_vector<complex<double>, time>(q_encap);
204 auto& rhs = encap::as_vector<complex<double>, time>(rhs_encap);
207 double inv = 1.0 / (1.0 - double(dt) * real(this->lambda));
211 f[0] = real(this->lambda) * q[0];
213 this->n_impl_solve++;
220 #endif // _EXAMPLES__SCALAR__SCALAR_SWEEPER_HPP_
Semi-implicit IMEX sweeper.
void post_sweep() override
post sweep, update error.
void echo_error(time t)
compute error between last state and exact solution at time tand print it to cout ...
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: Multiply with \( \text{real}(\lambda) \) ...
double error
error at the final time. For the scalar example, an analytical solution is known. ...
double get_errors()
returns error, but does not update it!
encap::Encapsulation< time > encap_type
#define ML_LOG(level, x)
same as LOG(level, x) from easylogging++
virtual ~ScalarSweeper()
upon destruction, report final error and number of function calls
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( \mathbb{I}_d - \Delta t \text{real}(\lambda) \right) u = b \) for ...
void exact(complex_vector_type &q, time t)
computes the exact solution \( u_0 \exp \left( \lambda*t \right) \) at a given time t...
void exact(shared_ptr< encap_type > q_encap, time t)
void f_expl_eval(shared_ptr< encap_type > f_encap, shared_ptr< encap_type > q_encap, time t) override
evaluate the explicit part of the right hand side: Multiply with \( \text{imag}(\lambda) \) ...
ScalarSweeper(const complex< double > &lambda, const complex< double > &u0)
generic constructor; initialize all function call counters with zero.
Data/solution encapsulation.
#define UNUSED(expr)
Denoting unused function parameters for omitting compiler warnings.
encap::VectorEncapsulation< complex< double > > complex_vector_type
define a type for a complex PFASST vector encapsulation.
void post_predict() override
post prediction step, update of error.
Sweeper for scalar test equation.