diff --git a/src/implementation/solvers/pde/tnlSemiImplicitTimeStepper_impl.h b/src/implementation/solvers/pde/tnlSemiImplicitTimeStepper_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..6faf08f566bd1bebb9e1577787f5f9cb0dc53dcd --- /dev/null +++ b/src/implementation/solvers/pde/tnlSemiImplicitTimeStepper_impl.h @@ -0,0 +1,93 @@ +/*************************************************************************** + 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_ */ diff --git a/src/implementation/solvers/tnlSolverStarter_impl.h b/src/implementation/solvers/tnlSolverStarter_impl.h index 6e949cce2420af38d59e77170b0891a718f210fe..18a2708ac4fec7120d8be231bb8f11adf2d79774 100644 --- a/src/implementation/solvers/tnlSolverStarter_impl.h +++ b/src/implementation/solvers/tnlSolverStarter_impl.h @@ -44,6 +44,13 @@ template< typename Problem, bool enabled = tnlConfigTagExplicitSolver< ConfigTag, ExplicitSolver >::enabled > class tnlSolverStarterExplicitSolverSetter{}; +template< typename Problem, + typename SemiImplicitSolver, + typename ConfigTag, + bool enabled = tnlConfigTagSemiImplicitSolver< ConfigTag, SemiImplicitSolver >::enabled > +class tnlSolverStarterSemiImplicitSolverSetter{}; + + template< typename Problem, typename ExplicitSolver, typename TimeStepper, @@ -84,6 +91,10 @@ bool tnlSolverStarter< ConfigTag > :: run( const tnlParameterContainer& paramete return false; } +/**** + * Setting the time discretisation + */ + template< typename Problem, typename TimeDiscretisation, typename ConfigTag > @@ -130,8 +141,8 @@ class tnlSolverStarterTimeDiscretisationSetter< Problem, tnlSemiImplicitTimeDisc const tnlParameterContainer& parameters ) { const tnlString& discreteSolver = parameters. GetParameter< tnlString>( "discrete-solver" ); - //if( discreteSolver == "gmres" ) - // return tnlSolverStarterExplicitSolverSetter< Problem, tnlExplicitEulerSolverTag, ConfigTag >::run( problem, parameters ); + if( discreteSolver == "gmres" ) + return tnlSolverStarterExplicitSolverSetter< Problem, tnlSemiImplicitGMRESSolverTag, ConfigTag >::run( problem, parameters ); return false; } }; @@ -149,6 +160,10 @@ class tnlSolverStarterTimeDiscretisationSetter< Problem, tnlImplicitTimeDiscreti } }; +/**** + * Setting the explicit solver + */ + template< typename Problem, typename ExplicitSolver, typename ConfigTag > @@ -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, typename ExplicitSolver, typename TimeStepper, @@ -231,7 +283,9 @@ class tnlSolverStarterExplicitTimeStepperSetter }; }; - +/**** + * Setting the semi-implicit time stepper + */ diff --git a/src/solvers/pde/CMakeLists.txt b/src/solvers/pde/CMakeLists.txt index 3c3da45fef7d0f4aa2efe17df89e1333c26f945f..5ff8228aa90e6b62f8dd895d45ba78b9ffe02513 100755 --- a/src/solvers/pde/CMakeLists.txt +++ b/src/solvers/pde/CMakeLists.txt @@ -1,5 +1,6 @@ SET( headers tnlPDESolver.h tnlExplicitTimeStepper.h + tnlSemiImplicitTimeStepper.h tnlExplicitUpdater.h ) diff --git a/src/solvers/pde/tnlSemiImplicitTimeStepper.h b/src/solvers/pde/tnlSemiImplicitTimeStepper.h new file mode 100644 index 0000000000000000000000000000000000000000..8f6e1029412a3a78f736318439d4697567e90c84 --- /dev/null +++ b/src/solvers/pde/tnlSemiImplicitTimeStepper.h @@ -0,0 +1,67 @@ +/*************************************************************************** + 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_ */ diff --git a/src/solvers/tnlConfigTags.h b/src/solvers/tnlConfigTags.h index 5a9dfcf170cb0daa763607acbd2bea9074632bb3..7fab4b74e014e9653254c2a52c6460493339ea3e 100644 --- a/src/solvers/tnlConfigTags.h +++ b/src/solvers/tnlConfigTags.h @@ -84,5 +84,12 @@ class tnlExplicitMersonSolverTag{}; 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_ */