4#ifndef DUNE_PDELAB_INSTATIONARY_EXPLICITONESTEP_HH
5#define DUNE_PDELAB_INSTATIONARY_EXPLICITONESTEP_HH
11#include <dune/pdelab/common/logtag.hh>
12#include <dune/pdelab/instationary/onestepparameter.hh>
63 template<
class R,
class IGOS>
69 CFLTimeController (R cfl_,
const IGOS& igos_) : cfl(cfl_), target(1e100), igos(igos_)
72 CFLTimeController (R cfl_, R target_,
const IGOS& igos_) : cfl(cfl_), target(target_), igos(igos_)
75 void setTarget (R target_)
84 RealType suggested = cfl*igos.suggestTimestep(givendt);
85 if (time+2.0*suggested<target)
87 if (time+suggested<target)
88 return 0.5*(target-time);
108 template<
class T,
class IGOS,
class LS,
class TrlV,
class TstV = TrlV,
class TC = SimpleTimeController<T> >
111 typedef typename TrlV::ElementType Real;
112 typedef typename IGOS::template MatrixContainer<Real>::Type M;
128 : method(&method_), igos(igos_), ls(ls_), verbosityLevel(1), step(1), D(igos),
133 if (igos.trialGridFunctionSpace().gridView().comm().rank()>0)
150 : method(&method_), igos(igos_), ls(ls_), verbosityLevel(1), step(1), D(igos),
151 tc(&tc_), allocated(false)
159 if (allocated)
delete tc;
165 if (igos.trialGridFunctionSpace().gridView().comm().rank()>0)
168 verbosityLevel = level;
196 T
apply (T time, T dt, TrlV& xold, TrlV& xnew)
198 DefaultLimiter limiter;
199 return apply(time,dt,xold,xnew,limiter);
210 template<
typename Limiter>
211 T
apply (T time, T dt, TrlV& xold, TrlV& xnew, Limiter& limiter)
216 mytag <<
"ExplicitOneStepMethod::apply(): ";
218 std::vector<TrlV*> x(1);
220 if(verbosityLevel>=4)
221 std::cout << mytag <<
"Creating residual vectors alpha and beta..."
223 TstV alpha(igos.testGridFunctionSpace()), beta(igos.testGridFunctionSpace());
224 if(verbosityLevel>=4)
226 <<
"Creating residual vectors alpha and beta... done."
229 if (verbosityLevel>=1){
230 std::ios_base::fmtflags oldflags = std::cout.flags();
231 std::cout <<
"TIME STEP [" << method->
name() <<
"] "
232 << std::setw(6) << step
234 << std::setw(12) << std::setprecision(4) << std::scientific
237 << std::setw(12) << std::setprecision(4) << std::scientific
240 << std::setw(12) << std::setprecision(4) << std::scientific
243 std::cout.flags(oldflags);
247 if(verbosityLevel>=4)
248 std::cout << mytag <<
"Preparing assembler..." << std::endl;
249 igos.preStep(*method,time,dt);
250 if(verbosityLevel>=4)
251 std::cout << mytag <<
"Preparing assembler... done." << std::endl;
254 for(
unsigned r=1; r<=method->
s(); ++r)
257 stagetag <<
"stage " << r <<
": ";
258 if (verbosityLevel>=4)
259 std::cout << stagetag <<
"Start." << std::endl;
261 if (verbosityLevel>=2){
262 std::ios_base::fmtflags oldflags = std::cout.flags();
263 std::cout <<
"STAGE "
266 << std::setw(12) << std::setprecision(4) << std::scientific
267 << time+method->
d(r)*dt
269 std::cout.flags(oldflags);
277 if (r>1) xnew = *(x[r-1]);
282 x.push_back(
new TrlV(igos.trialGridFunctionSpace()));
290 if (verbosityLevel>=4) std::cout <<
"assembling D, alpha, beta ..." << std::endl;
296 limiter.prestage(*x[r-1]);
298 if(verbosityLevel>=4)
299 std::cout << stagetag <<
"Assembling residual..." << std::endl;
300 igos.explicit_jacobian_residual(r,x,D,alpha,beta);
301 if(verbosityLevel>=4)
302 std::cout << stagetag <<
"Assembling residual... done."
311 if (verbosityLevel>=4){
312 std::ios_base::fmtflags oldflags = std::cout.flags();
313 std::cout << stagetag
315 << std::setw(12) << std::setprecision(4) << std::scientific
318 << std::setw(12) << std::setprecision(4) << std::scientific
321 std::cout.flags(oldflags);
324 if (verbosityLevel>=2 && newdt!=dt)
326 std::ios_base::fmtflags oldflags = std::cout.flags();
327 std::cout <<
"changed dt to "
328 << std::setw(12) << std::setprecision(4) << std::scientific
331 std::cout.flags(oldflags);
337 if (verbosityLevel>=4)
338 std::cout << stagetag
339 <<
"Combining residuals with selected dt..."
342 if (verbosityLevel>=4)
343 std::cout << stagetag
344 <<
"Combining residuals with selected dt... done."
348 if (verbosityLevel>=4)
349 std::cout << stagetag <<
"Solving diagonal system..."
351 ls.apply(D,*x[r],alpha,0.99);
352 if (verbosityLevel>=4)
353 std::cout << stagetag <<
"Solving diagonal system... done."
357 limiter.poststage(*x[r]);
360 if (verbosityLevel>=4)
361 std::cout << stagetag <<
"Cleanup..." << std::endl;
363 if (verbosityLevel>=4)
364 std::cout << stagetag <<
"Cleanup... done" << std::endl;
366 if (verbosityLevel>=4)
367 std::cout << stagetag <<
"Finished." << std::endl;
371 for(
unsigned i=1; i<method->
s(); ++i)
delete x[i];
374 if (verbosityLevel>=4)
375 std::cout << mytag <<
"Cleanup..." << std::endl;
377 if (verbosityLevel>=4)
378 std::cout << mytag <<
"Cleanup... done." << std::endl;
392 template <
typename F>
393 T
apply (T time, T dt, TrlV& xold, F& f, TrlV& xnew)
395 DefaultLimiter limiter;
396 return apply(time,dt,xold,f,xnew,limiter);
408 template<
typename F,
typename Limiter>
409 T
apply (T time, T dt, TrlV& xold, F&f, TrlV& xnew, Limiter& limiter)
414 mytag <<
"ExplicitOneStepMethod::apply(): ";
416 std::vector<TrlV*> x(1);
418 if(verbosityLevel>=4)
419 std::cout << mytag <<
"Creating residual vectors alpha and beta..."
421 TstV alpha(igos.testGridFunctionSpace()), beta(igos.testGridFunctionSpace());
422 if(verbosityLevel>=4)
424 <<
"Creating residual vectors alpha and beta... done."
431 if(verbosityLevel>=4)
432 std::cout << mytag <<
"Creating residual vector and update for residual formulation of linear problem per stage"
434 TrlV residual(igos.testGridFunctionSpace());
435 TrlV update(igos.testGridFunctionSpace());
436 if(verbosityLevel>=4)
437 std::cout << mytag <<
"Creating residual vector and update for residual... done."
441 if (verbosityLevel>=1){
442 std::ios_base::fmtflags oldflags = std::cout.flags();
443 std::cout <<
"TIME STEP [" << method->
name() <<
"] "
444 << std::setw(6) << step
446 << std::setw(12) << std::setprecision(4) << std::scientific
449 << std::setw(12) << std::setprecision(4) << std::scientific
452 << std::setw(12) << std::setprecision(4) << std::scientific
455 std::cout.flags(oldflags);
459 if(verbosityLevel>=4)
460 std::cout << mytag <<
"Preparing assembler..." << std::endl;
461 igos.preStep(*method,time,dt);
462 if(verbosityLevel>=4)
463 std::cout << mytag <<
"Preparing assembler... done." << std::endl;
466 for(
unsigned r=1; r<=method->
s(); ++r)
469 stagetag <<
"stage " << r <<
": ";
470 if (verbosityLevel>=4)
471 std::cout << stagetag <<
"Start." << std::endl;
473 if (verbosityLevel>=2){
474 std::ios_base::fmtflags oldflags = std::cout.flags();
475 std::cout <<
"STAGE "
478 << std::setw(12) << std::setprecision(4) << std::scientific
479 << time+method->
d(r)*dt
481 std::cout.flags(oldflags);
489 if (r>1) xnew = *(x[r-1]);
494 x.push_back(
new TrlV(igos.trialGridFunctionSpace()));
502 if (verbosityLevel>=4) std::cout <<
"assembling D, alpha, beta ..." << std::endl;
508 igos.interpolate(r,*x[r-1],f,*x[r]);
511 limiter.prestage(*x[r-1]);
513 if(verbosityLevel>=4)
514 std::cout << stagetag <<
"Assembling residual..." << std::endl;
515 igos.explicit_jacobian_residual(r,x,D,alpha,beta);
516 if(verbosityLevel>=4)
517 std::cout << stagetag <<
"Assembling residual... done."
526 if (verbosityLevel>=4){
527 std::ios_base::fmtflags oldflags = std::cout.flags();
528 std::cout << stagetag
530 << std::setw(12) << std::setprecision(4) << std::scientific
533 << std::setw(12) << std::setprecision(4) << std::scientific
536 std::cout.flags(oldflags);
539 if (verbosityLevel>=2 && newdt!=dt)
541 std::ios_base::fmtflags oldflags = std::cout.flags();
542 std::cout <<
"changed dt to "
543 << std::setw(12) << std::setprecision(4) << std::scientific
546 std::cout.flags(oldflags);
552 if (verbosityLevel>=4)
553 std::cout << stagetag
554 <<
"Combining residuals with selected dt..."
557 if (verbosityLevel>=4)
558 std::cout << stagetag
559 <<
"Combining residuals with selected dt... done."
566 using Backend::native;
567 native(D).mv(native(*x[r]), native(residual));
569 auto cc = igos.trialConstraints();
571 if (verbosityLevel>=4)
572 std::cout << stagetag <<
"Solving diagonal system..."
574 ls.apply(D, update, residual, 0.99);
575 if (verbosityLevel>=4)
576 std::cout << stagetag <<
"Solving diagonal system... done."
581 limiter.poststage(*x[r]);
584 if (verbosityLevel>=4)
585 std::cout << stagetag <<
"Cleanup..." << std::endl;
587 if (verbosityLevel>=4)
588 std::cout << stagetag <<
"Cleanup... done" << std::endl;
590 if (verbosityLevel>=4)
591 std::cout << stagetag <<
"Finished." << std::endl;
595 for(
unsigned i=1; i<method->
s(); ++i)
delete x[i];
598 if (verbosityLevel>=4)
599 std::cout << mytag <<
"Cleanup..." << std::endl;
601 if (verbosityLevel>=4)
602 std::cout << mytag <<
"Cleanup... done." << std::endl;
623 const TimeSteppingParameterInterface<T> *method;
629 TimeControllerInterface<T> *tc;
limit time step to maximum dt * CFL number
Definition: explicitonestep.hh:65
virtual RealType suggestTimestep(RealType time, RealType givendt) override
Return name of the scheme.
Definition: explicitonestep.hh:82
Base class for all PDELab exceptions.
Definition: exceptions.hh:19
Do one step of an explicit time-stepping scheme.
Definition: explicitonestep.hh:110
T apply(T time, T dt, TrlV &xold, F &f, TrlV &xnew, Limiter &limiter)
do one step;
Definition: explicitonestep.hh:409
ExplicitOneStepMethod(const TimeSteppingParameterInterface< T > &method_, IGOS &igos_, LS &ls_, TC &tc_)
construct a new one step scheme
Definition: explicitonestep.hh:149
T apply(T time, T dt, TrlV &xold, F &f, TrlV &xnew)
do one step;
Definition: explicitonestep.hh:393
T apply(T time, T dt, TrlV &xold, TrlV &xnew)
do one step;
Definition: explicitonestep.hh:196
T apply(T time, T dt, TrlV &xold, TrlV &xnew, Limiter &limiter)
do one step;
Definition: explicitonestep.hh:211
void setMethod(const TimeSteppingParameterInterface< T > &method_)
redefine the method to be used; can be done before every step
Definition: explicitonestep.hh:182
void setVerbosityLevel(int level)
change verbosity level; 0 means completely quiet
Definition: explicitonestep.hh:163
void setStepNumber(int newstep)
change number of current step
Definition: explicitonestep.hh:172
ExplicitOneStepMethod(const TimeSteppingParameterInterface< T > &method_, IGOS &igos_, LS &ls_)
construct a new one step scheme
Definition: explicitonestep.hh:127
Insert standard boilerplate into log messages.
Definition: logtag.hh:172
Default time controller; just returns given dt.
Definition: explicitonestep.hh:45
virtual RealType suggestTimestep(RealType time, RealType givendt) override
Return name of the scheme.
Definition: explicitonestep.hh:51
Controller interface for adaptive time stepping.
Definition: explicitonestep.hh:27
virtual ~TimeControllerInterface()
every abstract base class has a virtual destructor
Definition: explicitonestep.hh:36
virtual RealType suggestTimestep(RealType time, RealType givendt)=0
Return name of the scheme.
Utility class for storing and resetting stream attributes.
Definition: ios_state.hh:32
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
void set_constrained_dofs(const CG &cg, typename XG::ElementType x, XG &xg)
construct constraints from given boundary condition function
Definition: constraints.hh:796
virtual bool implicit() const =0
Return true if method is implicit.
virtual std::string name() const =0
Return name of the scheme.
virtual R d(int r) const =0
Return entries of the d Vector.
virtual unsigned s() const =0
Return number of stages of the method.
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
Utility class for storing and resetting stream attributes.
Dune namespace.
Definition: alignedallocator.hh:14