1 #ifndef DUNE_FEM_SOLVER_RUNGEKUTTA_BASICROW_HH 2 #define DUNE_FEM_SOLVER_RUNGEKUTTA_BASICROW_HH 11 #include <dune/common/dynmatrix.hh> 12 #include <dune/common/dynvector.hh> 13 #include <dune/common/nullptr.hh> 28 bool operator() (
double time,
double timeStepSize,
int stage,
const T &u,
const std::vector< T * > &update, T &source )
34 void limit( T& update,
const double time ) {}
61 : keyPrefix_( keyPrefix ),
62 parameter_( parameter )
66 : keyPrefix_(
"fem.solver.row." ),
67 parameter_( parameter )
74 return parameter().getValue<
double >( keyPrefix_ +
"linabstol", 1e-6 );
79 return parameter().getValue<
double >( keyPrefix_ +
"linreduction", 1e-4 );
84 return parameter().getValue<
bool >( keyPrefix_ +
"verbose", false );
96 template<
class HelmholtzOperator,
class NonlinearSolver,
class TimeStepControl,
class SourceTerm = NoROWRungeKuttaSourceTerm >
126 template<
class ButcherTable >
128 TimeProviderType& timeProvider,
129 const ButcherTable &butcherTable,
130 const TimeStepControlType &timeStepControl,
131 const SourceTermType &sourceTerm,
132 const ParametersType& parameter,
133 const NonlinearSolverParametersType& nlsParam )
134 : helmholtzOp_( helmholtzOp ),
135 nonlinearSolver_( helmholtzOp_, nlsParam ),
136 timeStepControl_( timeStepControl ),
137 sourceTerm_( sourceTerm ),
138 stages_( butcherTable.stages() ),
139 alpha_( butcherTable.A() ),
140 alpha2_( butcherTable.B() ),
143 c_( butcherTable.c() ),
144 rhs_(
"RK rhs", helmholtzOp_.space() ),
145 temp_(
"RK temp", helmholtzOp_.space() ),
146 update_( stages(), nullptr ),
147 linAbsTol_( parameter.linAbsTolParameter( ) ),
148 linReduction_( parameter.linReductionParameter( ) ),
149 linVerbose_( parameter.linearSolverVerbose() ),
150 maxLinearIterations_( parameter.maxLinearIterationsParameter() ),
151 preconditioner_(helmholtzOp.spaceOperator().preconditioner())
153 setup( butcherTable );
156 template<
class ButcherTable >
158 TimeProviderType& timeProvider,
159 const ButcherTable &butcherTable,
160 const TimeStepControlType &timeStepControl,
161 const SourceTermType &sourceTerm,
163 :
BasicROWRungeKuttaSolver( helmholtzOp, timeProvider, butcherTable, timeStepControl, sourceTerm, ParametersType( parameter ),
164 NonlinearSolverParametersType( parameter ) )
173 template<
class ButcherTable >
175 TimeProviderType& timeProvider,
176 const ButcherTable &butcherTable,
177 const TimeStepControlType &timeStepControl,
178 const ParametersType& parameter,
179 const NonlinearSolverParametersType& nlsParam )
180 :
BasicROWRungeKuttaSolver( helmholtzOp, timeProvider, butcherTable, timeStepControl, SourceTermType(), parameter, nlsParam )
183 template<
class ButcherTable >
185 TimeProviderType& timeProvider,
186 const ButcherTable &butcherTable,
187 const TimeStepControlType &timeStepControl,
189 :
BasicROWRungeKuttaSolver( helmholtzOp, timeProvider, butcherTable, timeStepControl, SourceTermType(), ParametersType( parameter ),
190 NonlinearSolverParametersType( parameter ) )
198 template<
class ButcherTable >
200 TimeProviderType& timeProvider,
201 const ButcherTable &butcherTable,
202 const ParametersType& parameter,
203 const NonlinearSolverParametersType& nlsParam )
204 :
BasicROWRungeKuttaSolver( helmholtzOp, timeProvider, butcherTable, TimeStepControlType(), SourceTermType(), parameter, nlsParam )
207 template<
class ButcherTable >
209 TimeProviderType& timeProvider,
210 const ButcherTable &butcherTable,
212 :
BasicROWRungeKuttaSolver( helmholtzOp, timeProvider, butcherTable, TimeStepControlType(), SourceTermType(), ParametersType( parameter ),
213 NonlinearSolverParametersType( parameter ) )
216 template<
class ButcherTable >
217 void setup(
const ButcherTable& butcherTable )
219 std::cout <<
"ROW method of order=" << butcherTable.order() <<
" with " << stages_ <<
" stages" << std::endl;
221 for(
int i = 0; i < stages(); ++i )
223 std::ostringstream name;
224 name <<
"RK stage " << i;
225 update_[ i ] =
new DestinationType( name.str(), helmholtzOp_.space() );
229 for(
int i = 0; i < stages(); ++i )
230 gamma_[ i ] = alpha_[ i ][ i ];
233 alpha_.mtv( butcherTable.b(), beta_ );
234 alpha2_.rightmultiply( alpha_ );
240 for(
int i = 0; i < stages(); ++i )
247 const double time = timeStepControl_.time();
249 helmholtzOp_.setTime( time );
250 helmholtzOp_.initializeTimeStepSize( U0 );
251 const double helmholtzEstimate = helmholtzOp_.timeStepEstimate();
253 double sourceTermEstimate = sourceTerm_.initialTimeStepEstimate( time, U0 );
255 if( sourceTermEstimate < 0.0 ) sourceTermEstimate = helmholtzEstimate ;
257 timeStepControl_.initialTimeStepSize( helmholtzEstimate, sourceTermEstimate );
260 using BaseType::solve;
263 void solve ( DestinationType &U, MonitorType &monitor )
267 typename HelmholtzOperatorType::JacobianOperatorType jOp(
"jacobianOperator", U.space(), U.space() );
269 const double time = timeStepControl_.time();
270 const double timeStepSize = timeStepControl_.timeStepSize();
271 assert( timeStepSize > 0.0 );
273 for(
int s = 0; s < stages(); ++s )
276 DestinationType& updateStage = *update_[ s ];
279 for(
int k = 0; k < s; ++k )
280 rhs_.axpy( alpha2_[ s ][ k ], *update_[ k ] );
281 helmholtzOp_.spaceOperator()(rhs_,updateStage);
282 updateStage *= (gamma_[s]*timeStepSize);
283 for(
int k = 0; k < s; ++k )
284 updateStage.axpy( -gamma_[s]*alpha_[ s ][ k ], *update_[ k ] );
286 rhs_.assign( updateStage );
289 const double stageTime = time + c_[ s ]*timeStepSize;
290 helmholtzOp_.setTime( stageTime );
295 helmholtzOp_.setLambda( gamma_[ s ]*timeStepSize );
296 helmholtzOp_.jacobian( U, jOp );
298 const int remLinearIts = maxLinearIterations_;
301 typename NonlinearSolverType::LinearInverseOperatorType jInv( jOp, *preconditioner_, linReduction_, linAbsTol_, remLinearIts, linVerbose_ );
302 jInv( rhs_, updateStage );
303 monitor.linearSolverIterations_ += jInv.iterations();
307 typename NonlinearSolverType::LinearInverseOperatorType jInv( jOp, linReduction_, linAbsTol_, remLinearIts, linVerbose_ );
308 jInv( rhs_, updateStage );
309 monitor.linearSolverIterations_ += jInv.iterations();
314 if(0 && timeStepControl_.computeError() )
317 DestinationType Uerr( U );
321 for(
int s = 0; s < stages(); ++s )
322 U.axpy( beta_[ s ], *update_[ s ] );
325 Uerr.axpy( -1.0, U );
326 const double errorU = Uerr.scalarProductDofs( Uerr );
327 const double normU = U.scalarProductDofs( U );
329 if( normU > 0 && errorU > 0 )
333 std::cout << std::scientific <<
"Error in RK = " << error <<
" norm " << errorU <<
" " << normU << std::endl;
339 for(
int s = 0; s < stages(); ++s )
340 U.axpy( beta_[ s ], *update_[ s ] );
343 monitor.error_ = error;
346 timeStepControl_.timeStepEstimate( helmholtzOp_.timeStepEstimate(), sourceTerm_.timeStepEstimate(), monitor );
353 out <<
"Generic " << stages() <<
"-stage implicit Runge-Kutta solver.\\\\" << std::endl;
358 double infNorm(
const DestinationType& U,
const DestinationType& Uerr )
const 360 typedef typename DestinationType :: ConstDofIteratorType ConstDofIteratorType ;
361 const ConstDofIteratorType uend = U.dend();
363 for( ConstDofIteratorType u = U.dbegin(), uerr = Uerr.dbegin(); u != uend; ++u, ++uerr )
366 double uerrval = *uerr ;
369 double norm =
std::abs( uval - uerrval );
384 Dune::DynamicMatrix< double >
alpha_, alpha2_;
385 Dune::DynamicVector< double >
gamma_, beta_, c_;
399 #endif // #ifndef DUNE_FEM_SOLVER_RUNGEKUTTA_BASICROW_HH const Dune::Fem::ParameterReader & parameter() const
Definition: basicrow.hh:70
Dune::DynamicVector< double > gamma_
Definition: basicrow.hh:385
static double sqrt(const Double &v)
Definition: double.hh:870
SourceTerm SourceTermType
Definition: basicrow.hh:110
Interface class for ODE Solver.
Definition: odesolverinterface.hh:11
ROWSolverParameter(const std::string keyPrefix, const Dune::Fem::ParameterReader ¶meter=Dune::Fem::Parameter::container())
Definition: basicrow.hh:60
BasicROWRungeKuttaSolver(HelmholtzOperatorType &helmholtzOp, TimeProviderType &timeProvider, const ButcherTable &butcherTable, const TimeStepControlType &timeStepControl, const SourceTermType &sourceTerm, const Dune::Fem::ParameterReader ¶meter=Dune::Fem::Parameter::container())
Definition: basicrow.hh:157
DestinationType temp_
Definition: basicrow.hh:387
bool operator()(double time, double timeStepSize, int stage, const T &u, const std::vector< T * > &update, T &source)
Definition: basicrow.hh:28
virtual int maxLinearIterationsParameter() const
Definition: basicrow.hh:87
HelmholtzOperator HelmholtzOperatorType
Definition: basicrow.hh:107
static constexpr T max(T a)
Definition: utility.hh:65
BaseType::MonitorType MonitorType
Definition: basicrow.hh:104
void solve(DestinationType &U, MonitorType &monitor)
solve the system
Definition: basicrow.hh:263
Definition: basicrow.hh:50
ROWSolverParameter(const Dune::Fem::ParameterReader ¶meter=Dune::Fem::Parameter::container())
Definition: basicrow.hh:65
std::vector< DestinationType * > update_
Definition: basicrow.hh:388
Definition: multistep.hh:16
virtual bool linearSolverVerbose() const
Definition: basicrow.hh:82
virtual double linAbsTolParameter() const
Definition: basicrow.hh:72
double timeStepEstimate() const
Definition: basicrow.hh:43
BasicROWRungeKuttaSolver(HelmholtzOperatorType &helmholtzOp, TimeProviderType &timeProvider, const ButcherTable &butcherTable, const TimeStepControlType &timeStepControl, const ParametersType ¶meter, const NonlinearSolverParametersType &nlsParam)
constructor
Definition: basicrow.hh:174
const bool linVerbose_
Definition: basicrow.hh:391
TimeStepControl timeStepControl_
Definition: basicrow.hh:379
void limit(T &update, const double time)
Definition: basicrow.hh:34
Dune::DynamicMatrix< double > alpha_
Definition: basicrow.hh:384
ROWSolverParameter ParametersType
Definition: basicrow.hh:112
const std::string keyPrefix_
Definition: basicrow.hh:55
NonlinearSolverType nonlinearSolver_
Definition: basicrow.hh:378
general base for time providers
Definition: timeprovider.hh:35
Double abs(const Double &a)
Definition: double.hh:860
NonlinearSolver NonlinearSolverType
Definition: basicrow.hh:108
void initialize(const DestinationType &U0)
apply operator once to get dt estimate
Definition: basicrow.hh:245
HelmholtzOperator::SpaceOperatorType::PreconditionOperatorType PreconditionOperatorType
Definition: basicrow.hh:115
ROW RungeKutta ODE solver.
Definition: basicrow.hh:97
Definition: io/parameter.hh:549
const PreconditionOperatorType * preconditioner_
Definition: basicrow.hh:394
Dune::Fem::TimeProviderBase TimeProviderType
Definition: basicrow.hh:117
static ParameterContainer & container()
Definition: io/parameter.hh:190
virtual double linReductionParameter() const
Definition: basicrow.hh:77
int stages_
Definition: basicrow.hh:382
BaseType::DestinationType DestinationType
Definition: basicrow.hh:105
BasicROWRungeKuttaSolver(HelmholtzOperatorType &helmholtzOp, TimeProviderType &timeProvider, const ButcherTable &butcherTable, const ParametersType ¶meter, const NonlinearSolverParametersType &nlsParam)
constructor
Definition: basicrow.hh:199
BasicROWRungeKuttaSolver(HelmholtzOperatorType &helmholtzOp, TimeProviderType &timeProvider, const ButcherTable &butcherTable, const TimeStepControlType &timeStepControl, const SourceTermType &sourceTerm, const ParametersType ¶meter, const NonlinearSolverParametersType &nlsParam)
constructor
Definition: basicrow.hh:127
int stages() const
Definition: basicrow.hh:349
Dune::Fem::ParameterReader parameter_
Definition: basicrow.hh:57
Definition: odesolverinterface.hh:17
const double linReduction_
Definition: basicrow.hh:390
void setup(const ButcherTable &butcherTable)
Definition: basicrow.hh:217
NonlinearSolver::ParametersType NonlinearSolverParametersType
Definition: basicrow.hh:113
double initialTimeStepEstimate(double time, const T &u) const
Definition: basicrow.hh:37
SourceTerm sourceTerm_
Definition: basicrow.hh:380
double delta_
Definition: basicrow.hh:383
~BasicROWRungeKuttaSolver()
destructor
Definition: basicrow.hh:238
HelmholtzOperatorType & helmholtzOp_
Definition: basicrow.hh:377
BasicROWRungeKuttaSolver(HelmholtzOperatorType &helmholtzOp, TimeProviderType &timeProvider, const ButcherTable &butcherTable, const TimeStepControlType &timeStepControl, const Dune::Fem::ParameterReader ¶meter=Dune::Fem::Parameter::container())
Definition: basicrow.hh:184
Definition: basicrow.hh:25
BasicROWRungeKuttaSolver(HelmholtzOperatorType &helmholtzOp, TimeProviderType &timeProvider, const ButcherTable &butcherTable, const Dune::Fem::ParameterReader ¶meter=Dune::Fem::Parameter::container())
Definition: basicrow.hh:208
const int maxLinearIterations_
Definition: basicrow.hh:392
double infNorm(const DestinationType &U, const DestinationType &Uerr) const
Definition: basicrow.hh:358
void description(std::ostream &out) const
print description of ODE solver to out stream
Definition: basicrow.hh:351
TimeStepControl TimeStepControlType
Definition: basicrow.hh:109
DestinationImp DestinationType
type of destination
Definition: odesolverinterface.hh:53