Skip to content
Snippets Groups Projects
Commit ba925308 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Adding the semi-implicit time stepper.

parent dac34ebc
No related branches found
No related tags found
No related merge requests found
/***************************************************************************
tnlSemiImplicitTimeStepper_impl.h - description
-------------------
begin : Oct 4, 2014
copyright : (C) 2014 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef TNLSEMIIMPLICITTIMESTEPPER_IMPL_H_
#define TNLSEMIIMPLICITTIMESTEPPER_IMPL_H_
template< typename Problem,
typename MatrixSolver >
tnlSemiImplicitTimeStepper< Problem, MatrixSolver >::
tnlSemiImplicitTimeStepper()
: problem( 0 )
{
};
template< typename Problem,
typename MatrixSolver >
void
tnlSemiImplicitTimeStepper< Problem, MatrixSolver >::
configSetup( tnlConfigDescription& config,
const tnlString& prefix )
{
config.addEntry< double >( "tau", "Time step for the time discretisation.", 1.0 );
}
template< typename Problem,
typename MatrixSolver >
bool
tnlSemiImplicitTimeStepper< Problem, MatrixSolver >::
init( const tnlParameterContainer& parameters,
const tnlString& prefix )
{
this->setTau( parameters.GetParameter< double >( "tau") );
return true;
}
template< typename Problem,
typename MatrixSolver >
void tnlSemiImplicitTimeStepper< Problem, MatrixSolver >::setProblem( ProblemType& problem )
{
this -> problem = &problem;
};
template< typename Problem,
typename MatrixSolver >
Problem* tnlSemiImplicitTimeStepper< Problem, MatrixSolver >::getProblem() const
{
return this -> problem;
};
template< typename Problem,
typename MatrixSolver >
bool tnlSemiImplicitTimeStepper< Problem, MatrixSolver >::setTau( const RealType& tau )
{
if( tau <= 0.0 )
{
cerr << "Tau for tnlSemiImplicitTimeStepper must be positive. " << endl;
return false;
}
this -> tau = tau;
};
template< typename Problem,
typename MatrixSolver >
bool tnlSemiImplicitTimeStepper< Problem, MatrixSolver >::solve( const RealType& time,
const RealType& stopTime,
const MeshType& mesh,
DofVectorType& dofVector )
{
tnlAssert( this->problem != 0, );
RealType t = time;
while( t < stopTime )
{
Real currentTau = tnlMin( this->tau, stopTime - t );
this->problem->assemblyLinearSystem( t, tau, mesh, dofVector, matrix, b );
}
}
#endif /* TNLSEMIIMPLICITTIMESTEPPER_IMPL_H_ */
...@@ -44,6 +44,13 @@ template< typename Problem, ...@@ -44,6 +44,13 @@ template< typename Problem,
bool enabled = tnlConfigTagExplicitSolver< ConfigTag, ExplicitSolver >::enabled > bool enabled = tnlConfigTagExplicitSolver< ConfigTag, ExplicitSolver >::enabled >
class tnlSolverStarterExplicitSolverSetter{}; class tnlSolverStarterExplicitSolverSetter{};
template< typename Problem,
typename SemiImplicitSolver,
typename ConfigTag,
bool enabled = tnlConfigTagSemiImplicitSolver< ConfigTag, SemiImplicitSolver >::enabled >
class tnlSolverStarterSemiImplicitSolverSetter{};
template< typename Problem, template< typename Problem,
typename ExplicitSolver, typename ExplicitSolver,
typename TimeStepper, typename TimeStepper,
...@@ -84,6 +91,10 @@ bool tnlSolverStarter< ConfigTag > :: run( const tnlParameterContainer& paramete ...@@ -84,6 +91,10 @@ bool tnlSolverStarter< ConfigTag > :: run( const tnlParameterContainer& paramete
return false; return false;
} }
/****
* Setting the time discretisation
*/
template< typename Problem, template< typename Problem,
typename TimeDiscretisation, typename TimeDiscretisation,
typename ConfigTag > typename ConfigTag >
...@@ -130,8 +141,8 @@ class tnlSolverStarterTimeDiscretisationSetter< Problem, tnlSemiImplicitTimeDisc ...@@ -130,8 +141,8 @@ class tnlSolverStarterTimeDiscretisationSetter< Problem, tnlSemiImplicitTimeDisc
const tnlParameterContainer& parameters ) const tnlParameterContainer& parameters )
{ {
const tnlString& discreteSolver = parameters. GetParameter< tnlString>( "discrete-solver" ); const tnlString& discreteSolver = parameters. GetParameter< tnlString>( "discrete-solver" );
//if( discreteSolver == "gmres" ) if( discreteSolver == "gmres" )
// return tnlSolverStarterExplicitSolverSetter< Problem, tnlExplicitEulerSolverTag, ConfigTag >::run( problem, parameters ); return tnlSolverStarterExplicitSolverSetter< Problem, tnlSemiImplicitGMRESSolverTag, ConfigTag >::run( problem, parameters );
return false; return false;
} }
}; };
...@@ -149,6 +160,10 @@ class tnlSolverStarterTimeDiscretisationSetter< Problem, tnlImplicitTimeDiscreti ...@@ -149,6 +160,10 @@ class tnlSolverStarterTimeDiscretisationSetter< Problem, tnlImplicitTimeDiscreti
} }
}; };
/****
* Setting the explicit solver
*/
template< typename Problem, template< typename Problem,
typename ExplicitSolver, typename ExplicitSolver,
typename ConfigTag > typename ConfigTag >
...@@ -197,6 +212,43 @@ class tnlSolverStarterExplicitSolverSetter< Problem, tnlExplicitMersonSolverTag, ...@@ -197,6 +212,43 @@ class tnlSolverStarterExplicitSolverSetter< Problem, tnlExplicitMersonSolverTag,
} }
}; };
/****
* Setting the semi-implicit solver
*/
template< typename Problem,
typename SemiImplicitSolver,
typename ConfigTag >
class tnlSolverStarterSemiImplicitSolverSetter< Problem, SemiImplicitSolver, ConfigTag, false >
{
public:
static bool run( Problem& problem,
const tnlParameterContainer& parameters )
{
cerr << "The semi-implicit solver " << parameters.GetParameter< tnlString >( "discrete-solver" ) << " is not supported." << endl;
return false;
}
};
template< typename Problem,
typename ConfigTag >
class tnlSolverStarterSemiImplicitSolverSetter< Problem, tnlSemiImplicitGMRESSolverTag, ConfigTag, true >
{
public:
static bool run( Problem& problem,
const tnlParameterContainer& parameters )
{
typedef tnlSemiImplicitTimeStepper< Problem, tnlGMRESSolver > TimeStepper;
return tnlSolverStarterSemiImplicitTimeStepperSetter< Problem,
TimeStepper,
ConfigTag >::run( problem, parameters );
}
};
/****
* Setting the explcicit time stepper
*/
template< typename Problem, template< typename Problem,
typename ExplicitSolver, typename ExplicitSolver,
typename TimeStepper, typename TimeStepper,
...@@ -231,7 +283,9 @@ class tnlSolverStarterExplicitTimeStepperSetter ...@@ -231,7 +283,9 @@ class tnlSolverStarterExplicitTimeStepperSetter
}; };
}; };
/****
* Setting the semi-implicit time stepper
*/
......
SET( headers tnlPDESolver.h SET( headers tnlPDESolver.h
tnlExplicitTimeStepper.h tnlExplicitTimeStepper.h
tnlSemiImplicitTimeStepper.h
tnlExplicitUpdater.h tnlExplicitUpdater.h
) )
......
/***************************************************************************
tnlSemiImplicitTimeStepper.h - description
-------------------
begin : Oct 4, 2014
copyright : (C) 2014 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef TNLSEMIIMPLICITTIMESTEPPER_H_
#define TNLSEMIIMPLICITTIMESTEPPER_H_
template< typename Problem,
typename MatrixSolver >
class tnlSemiImplicitTimeStepper
{
public:
typedef Problem ProblemType;
typedef typename Problem::RealType RealType;
typedef typename Problem::DeviceType DeviceType;
typedef typename Problem::IndexType IndexType;
typedef typename Problem::MeshType MeshType;
typedef typename ProblemType::DofVectorType DofVectorType;
typedef MatrixSolver MatrixSolverType;
tnlSemiImplicitTimeStepper();
static void configSetup( tnlConfigDescription& config,
const tnlString& prefix = "" );
bool init( const tnlParameterContainer& parameters,
const tnlString& prefix = "" );
void setProblem( ProblemType& problem );
ProblemType* getProblem() const;
bool setTau( const RealType& tau );
const RealType& getTau() const;
bool solve( const RealType& time,
const RealType& stopTime,
const MeshType& mesh,
DofVectorType& dofVector );
protected:
MatrixSolver matrixSolver;
Problem* problem;
RealType tau;
};
#include <implementation/solvers/pde/tnlSemiImplicitTimeStepper_impl.h>
#endif /* TNLSEMIIMPLICITTIMESTEPPER_H_ */
...@@ -84,5 +84,12 @@ class tnlExplicitMersonSolverTag{}; ...@@ -84,5 +84,12 @@ class tnlExplicitMersonSolverTag{};
template< typename ConfigTag, typename ExplicitSolver > struct tnlConfigTagExplicitSolver{ enum { enabled = true }; }; template< typename ConfigTag, typename ExplicitSolver > struct tnlConfigTagExplicitSolver{ enum { enabled = true }; };
/****
* All semi-implicit solvers are enabled by default
*/
class tnlSemiImplicitGMRESSolverTag{};
template< typename ConfigTag, typename SemiImplicitSolver > struct tnlConfigTagSemiImplicitSolver{ enum { enabled = true }; };
#endif /* TNLCONFIGTAGS_H_ */ #endif /* TNLCONFIGTAGS_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment