From 8e1164eeba283658db964456ca99aa639b7d75f6 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Wed, 13 Feb 2013 09:46:29 +0100 Subject: [PATCH] Adding CFL condtant to the Euler explicit ODE solver. --- src/implementation/mesh/tnlGrid2D_impl.h | 2 +- src/solvers/ode/tnlEulerSolver.h | 34 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/implementation/mesh/tnlGrid2D_impl.h b/src/implementation/mesh/tnlGrid2D_impl.h index 4977931659..f626a05f1e 100644 --- a/src/implementation/mesh/tnlGrid2D_impl.h +++ b/src/implementation/mesh/tnlGrid2D_impl.h @@ -250,7 +250,7 @@ bool tnlGrid< 2, Real, Device, Index> :: write( const MeshFunction& function, for( IndexType i = 0; i < getDimensions(). x(); i++ ) { const RealType x = this -> getLowerCorner(). x() + i * hx; - const RealType y = this -> getLowerCorner(). y() + i * hy; + const RealType y = this -> getLowerCorner(). y() + j * hy; file << x << " " << " " << y << " " << function[ this -> getNodeIndex( j, i ) ] << endl; } file << endl; diff --git a/src/solvers/ode/tnlEulerSolver.h b/src/solvers/ode/tnlEulerSolver.h index 2ae57afd7f..baf60a9467 100644 --- a/src/solvers/ode/tnlEulerSolver.h +++ b/src/solvers/ode/tnlEulerSolver.h @@ -37,6 +37,10 @@ class tnlEulerSolver : public tnlExplicitSolver< Problem > tnlString getType() const; + void setCFLCondition( const RealType& cfl ); + + const RealType& getCFLCondition() const; + bool solve( DofVectorType& u ); protected: @@ -46,11 +50,14 @@ class tnlEulerSolver : public tnlExplicitSolver< Problem > DofVectorType k1; + + RealType cflCondition; }; template< typename Problem > tnlEulerSolver< Problem > :: tnlEulerSolver() -: k1( "tnlEulerSolver:k1" ) +: k1( "tnlEulerSolver:k1" ), + cflCondition( 0.0 ) { }; @@ -62,6 +69,18 @@ tnlString tnlEulerSolver< Problem > :: getType() const tnlString( " >" ); }; +template< typename Problem > +void tnlEulerSolver< Problem > :: setCFLCondition( const RealType& cfl ) +{ + this -> cflCondition = cfl; +} + +template< typename Problem > +const typename Problem :: RealType& tnlEulerSolver< Problem > :: getCFLCondition() const +{ + return this -> cflCondition; +} + template< typename Problem > bool tnlEulerSolver< Problem > :: solve( DofVectorType& u ) { @@ -104,6 +123,16 @@ bool tnlEulerSolver< Problem > :: solve( DofVectorType& u ) this -> problem -> GetExplicitRHS( time, currentTau, u, k1 ); RealType lastResidue = residue; + RealType maxResidue( 0.0 ); + if( this -> cflCondition != 0.0 ) + { + maxResidue = k1. absMax(); + if( currentTau * maxResidue > this -> cflCondition ) + { + currentTau *= 0.9; + continue; + } + } computeNewTimeLevel( u, currentTau, residue ); /**** @@ -138,6 +167,9 @@ bool tnlEulerSolver< Problem > :: solve( DofVectorType& u ) return true; } if( iteration == this -> getMaxIterationsNumber() ) return false; + + if( this -> cflCondition != 0.0 ) + currentTau /= 0.95; } }; -- GitLab