From 8df22a6de288652d4fdc67573700a1acf8052b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4fer?= <schafjan@fjfi.cvut.cz> Date: Mon, 20 Nov 2017 13:28:59 +0100 Subject: [PATCH] added navier-stokes, euler in 2d works, added riemann initial condition choice --- examples/CMakeLists.txt | 2 +- examples/flow/CMakeLists.txt | 23 + .../flow/CompressibleConservativeVariables.h | 147 ++ examples/flow/LaxFridrichs.h | 148 ++ examples/flow/LaxFridrichsContinuity.h | 290 ++++ examples/flow/LaxFridrichsContinuityEuler.h | 290 ++++ examples/flow/LaxFridrichsEnergy.h | 509 ++++++ examples/flow/LaxFridrichsEnergyEuler.h | 309 ++++ examples/flow/LaxFridrichsEuler.h | 141 ++ examples/flow/LaxFridrichsMomentumBase.h | 73 + examples/flow/LaxFridrichsMomentumBaseEuler.h | 68 + examples/flow/LaxFridrichsMomentumX.h | 374 +++++ examples/flow/LaxFridrichsMomentumXEuler.h | 276 ++++ examples/flow/LaxFridrichsMomentumY.h | 358 +++++ examples/flow/LaxFridrichsMomentumYEuler.h | 260 +++ examples/flow/LaxFridrichsMomentumZ.h | 303 ++++ examples/flow/LaxFridrichsMomentumZEuler.h | 240 +++ examples/flow/PhysicalVariablesGetter.h | 116 ++ .../flow/RiemannProblemInitialCondition.h | 1417 +++++++++++++++++ examples/flow/navierStokes.cpp | 1 + examples/flow/navierStokes.cu | 1 + examples/flow/navierStokes.h | 117 ++ examples/flow/navierStokesBuildConfigTag.h | 51 + examples/flow/navierStokesProblem.h | 130 ++ examples/flow/navierStokesProblem_impl.h | 416 +++++ examples/flow/navierStokesRhs.h | 35 + examples/flow/run-euler | 25 + .../inviscid-flow/LaxFridrichsContinuity.h | 15 +- examples/inviscid-flow/LaxFridrichsEnergy.h | 20 +- .../inviscid-flow/LaxFridrichsMomentumX.h | 18 +- .../inviscid-flow/LaxFridrichsMomentumY.h | 12 +- .../inviscid-flow/LaxFridrichsMomentumZ.h | 6 +- .../RiemannProblemInitialCondition.h | 188 ++- examples/inviscid-flow/eulerBuildConfigTag.h | 2 +- src/TNL/Functions/VectorField.h | 7 +- 35 files changed, 6289 insertions(+), 99 deletions(-) create mode 100644 examples/flow/CMakeLists.txt create mode 100644 examples/flow/CompressibleConservativeVariables.h create mode 100644 examples/flow/LaxFridrichs.h create mode 100644 examples/flow/LaxFridrichsContinuity.h create mode 100644 examples/flow/LaxFridrichsContinuityEuler.h create mode 100644 examples/flow/LaxFridrichsEnergy.h create mode 100644 examples/flow/LaxFridrichsEnergyEuler.h create mode 100644 examples/flow/LaxFridrichsEuler.h create mode 100644 examples/flow/LaxFridrichsMomentumBase.h create mode 100644 examples/flow/LaxFridrichsMomentumBaseEuler.h create mode 100644 examples/flow/LaxFridrichsMomentumX.h create mode 100644 examples/flow/LaxFridrichsMomentumXEuler.h create mode 100644 examples/flow/LaxFridrichsMomentumY.h create mode 100644 examples/flow/LaxFridrichsMomentumYEuler.h create mode 100644 examples/flow/LaxFridrichsMomentumZ.h create mode 100644 examples/flow/LaxFridrichsMomentumZEuler.h create mode 100644 examples/flow/PhysicalVariablesGetter.h create mode 100644 examples/flow/RiemannProblemInitialCondition.h create mode 100644 examples/flow/navierStokes.cpp create mode 100644 examples/flow/navierStokes.cu create mode 100644 examples/flow/navierStokes.h create mode 100644 examples/flow/navierStokesBuildConfigTag.h create mode 100644 examples/flow/navierStokesProblem.h create mode 100644 examples/flow/navierStokesProblem_impl.h create mode 100644 examples/flow/navierStokesRhs.h create mode 100644 examples/flow/run-euler diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index dca68ee58a..82533c83ad 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,4 +12,4 @@ add_subdirectory( navier-stokes ) add_subdirectory( inviscid-flow ) #add_subdirectory( mean-curvature-flow ) - +add_subdirectory( flow ) diff --git a/examples/flow/CMakeLists.txt b/examples/flow/CMakeLists.txt new file mode 100644 index 0000000000..1a7e5ded8f --- /dev/null +++ b/examples/flow/CMakeLists.txt @@ -0,0 +1,23 @@ +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokes.cpp + navierStokes.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes${debugExt} navierStokes.cu) + target_link_libraries (tnl-navier-stokes${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes${debugExt} navierStokes.cpp) + target_link_libraries (tnl-navier-stokes${debugExt} tnl${debugExt}-${tnlVersion} ) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes${debugExt} + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes + ${tnl_inviscid_flow_SOURCES} + DESTINATION share/tnl-${tnlVersion}/examples/flow ) diff --git a/examples/flow/CompressibleConservativeVariables.h b/examples/flow/CompressibleConservativeVariables.h new file mode 100644 index 0000000000..a3afc84536 --- /dev/null +++ b/examples/flow/CompressibleConservativeVariables.h @@ -0,0 +1,147 @@ +/*************************************************************************** + CompressibleConservativeVariables.h - description + ------------------- + begin : Feb 12, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/MeshFunction.h> +#include <TNL/Functions/VectorField.h> +#include <TNL/SharedPointer.h> + +namespace TNL { + +template< typename Mesh > +class CompressibleConservativeVariables +{ + public: + typedef Mesh MeshType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef typename MeshType::RealType RealType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::IndexType IndexType; + typedef Functions::MeshFunction< Mesh > MeshFunctionType; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< MeshType > MeshPointer; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef SharedPointer< VelocityFieldType > MomentumFieldPointer; + + CompressibleConservativeVariables(){}; + + CompressibleConservativeVariables( const MeshPointer& meshPointer ) + : density( meshPointer ), + momentum( meshPointer ), + //pressure( meshPointer ), + energy( meshPointer ){}; + + void setMesh( const MeshPointer& meshPointer ) + { + this->density->setMesh( meshPointer ); + this->momentum->setMesh( meshPointer ); + //this->pressure.setMesh( meshPointer ); + this->energy->setMesh( meshPointer ); + } + + template< typename Vector > + void bind( const MeshPointer& meshPointer, + const Vector& data, + IndexType offset = 0 ) + { + IndexType currentOffset( offset ); + this->density->bind( meshPointer, data, currentOffset ); + currentOffset += this->density->getDofs( meshPointer ); + for( IndexType i = 0; i < Dimensions; i++ ) + { + ( *this->momentum )[ i ]->bind( meshPointer, data, currentOffset ); + currentOffset += ( *this->momentum )[ i ]->getDofs( meshPointer ); + } + this->energy->bind( meshPointer, data, currentOffset ); + } + + IndexType getDofs( const MeshPointer& meshPointer ) const + { + return this->density->getDofs( meshPointer ) + + this->momentum->getDofs( meshPointer ) + + this->energy->getDofs( meshPointer ); + } + + MeshFunctionPointer& getDensity() + { + return this->density; + } + + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /*MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + const MeshFunctionPointer& getEnergy() const + { + return this->energy; + } + + void setEnergy( MeshFunctionPointer& energy ) + { + this->energy = energy; + } + + void getVelocityField( VelocityFieldType& velocityField ) + { + + } + + protected: + + MeshFunctionPointer density; + MomentumFieldPointer momentum; + MeshFunctionPointer energy; + +}; + +} // namespace TN \ No newline at end of file diff --git a/examples/flow/LaxFridrichs.h b/examples/flow/LaxFridrichs.h new file mode 100644 index 0000000000..7c2230f339 --- /dev/null +++ b/examples/flow/LaxFridrichs.h @@ -0,0 +1,148 @@ +/*************************************************************************** + LaxFridrichs.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include <TNL/Functions/VectorField.h> + +#include "LaxFridrichsContinuity.h" +#include "LaxFridrichsEnergy.h" +#include "LaxFridrichsMomentumX.h" +#include "LaxFridrichsMomentumY.h" +#include "LaxFridrichsMomentumZ.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichs +{ + public: + typedef Mesh MeshType; + typedef Real RealType; + typedef typename Mesh::DeviceType DeviceType; + typedef Index IndexType; + typedef Functions::MeshFunction< Mesh > MeshFunctionType; + static const int Dimensions = Mesh::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef LaxFridrichsContinuity< Mesh, Real, Index > ContinuityOperatorType; + typedef LaxFridrichsMomentumX< Mesh, Real, Index > MomentumXOperatorType; + typedef LaxFridrichsMomentumY< Mesh, Real, Index > MomentumYOperatorType; + typedef LaxFridrichsMomentumZ< Mesh, Real, Index > MomentumZOperatorType; + typedef LaxFridrichsEnergy< Mesh, Real, Index > EnergyOperatorType; + + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef SharedPointer< VectorFieldType > VectorFieldPointer; + typedef SharedPointer< MeshType > MeshPointer; + + typedef SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "numerical-viscosity", "Value of artificial (numerical) viscosity in the Lax-Fridrichs scheme", 1.0 ); + config.addEntry< double >( prefix + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); + } + + LaxFridrichs() + : artificialViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( artificialViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( artificialViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( artificialViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( artificialViscosity ); + this->artificialViscosity = parameters.getParameter< double >( prefix + "numerical-viscosity" ); + this->continuityOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->momentumXOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->momentumYOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->momentumZOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->energyOperatorPointer->setArtificialViscosity( artificialViscosity ); + + return true; + } + + void setTau( const RealType& tau ) + { + this->continuityOperatorPointer->setTau( tau ); + this->momentumXOperatorPointer->setTau( tau ); + this->momentumYOperatorPointer->setTau( tau ); + this->momentumZOperatorPointer->setTau( tau ); + this->energyOperatorPointer->setTau( tau ); + } + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->momentumXOperatorPointer->setPressure( pressure ); + this->momentumYOperatorPointer->setPressure( pressure ); + this->momentumZOperatorPointer->setPressure( pressure ); + this->energyOperatorPointer->setPressure( pressure ); + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + this->continuityOperatorPointer->setVelocity( velocity ); + this->momentumXOperatorPointer->setVelocity( velocity ); + this->momentumYOperatorPointer->setVelocity( velocity ); + this->momentumZOperatorPointer->setVelocity( velocity ); + this->energyOperatorPointer->setVelocity( velocity ); + } + + const ContinuityOperatorPointer& getContinuityOperator() const + { + return this->continuityOperatorPointer; + } + + const MomentumXOperatorPointer& getMomentumXOperator() const + { + return this->momentumXOperatorPointer; + } + + const MomentumYOperatorPointer& getMomentumYOperator() const + { + return this->momentumYOperatorPointer; + } + + const MomentumZOperatorPointer& getMomentumZOperator() const + { + return this->momentumZOperatorPointer; + } + + const EnergyOperatorPointer& getEnergyOperator() const + { + return this->energyOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + + RealType artificialViscosity; + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsContinuity.h b/examples/flow/LaxFridrichsContinuity.h new file mode 100644 index 0000000000..d821224f11 --- /dev/null +++ b/examples/flow/LaxFridrichsContinuity.h @@ -0,0 +1,290 @@ +/*************************************************************************** + LaxFridrichsContinuity.h - description + ------------------- + begin : Feb 17, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include <TNL/Functions/VectorField.h> +#include <TNL/SharedPointer.h> + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsContinuityBase +{ + public: + + typedef Real RealType; + typedef Index IndexType; + typedef Mesh MeshType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + + LaxFridrichsContinuityBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + //rho + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) + - 0.5 * ( ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + //rho + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( u[ west ] + u[ east ] + u[ south ] + u[ north ] + u[ up ] + u[ down ]- 6.0 * u[ center ] ) + - 0.5 * ( ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse + + ( u[ up ] * velocity_z_up - u[ down ] * velocity_z_down ) * hzInverse ); + + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsContinuityEuler.h b/examples/flow/LaxFridrichsContinuityEuler.h new file mode 100644 index 0000000000..d821224f11 --- /dev/null +++ b/examples/flow/LaxFridrichsContinuityEuler.h @@ -0,0 +1,290 @@ +/*************************************************************************** + LaxFridrichsContinuity.h - description + ------------------- + begin : Feb 17, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include <TNL/Functions/VectorField.h> +#include <TNL/SharedPointer.h> + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsContinuityBase +{ + public: + + typedef Real RealType; + typedef Index IndexType; + typedef Mesh MeshType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + + LaxFridrichsContinuityBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + //rho + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) + - 0.5 * ( ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + //rho + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( u[ west ] + u[ east ] + u[ south ] + u[ north ] + u[ up ] + u[ down ]- 6.0 * u[ center ] ) + - 0.5 * ( ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse + + ( u[ up ] * velocity_z_up - u[ down ] * velocity_z_down ) * hzInverse ); + + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsEnergy.h b/examples/flow/LaxFridrichsEnergy.h new file mode 100644 index 0000000000..546c41b1dc --- /dev/null +++ b/examples/flow/LaxFridrichsEnergy.h @@ -0,0 +1,509 @@ +/*************************************************************************** + LaxFridrichsEnergy.h - description + ------------------- + begin : Feb 17, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsEnergyBase +{ + public: + + typedef Real RealType; + typedef Index IndexType; + typedef Mesh MeshType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + + LaxFridrichsEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( e[ west ] - 2.0 * e[ center ] + e[ east ] ) + - 0.5 * ( ( e[ east ] + pressure_east ) * velocity_x_east + - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse +// 1D uT_11_x + - 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west + - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( e[ west ] + e[ east ] + e[ south ] + e[ north ] - 4.0 * e[ center ] ) + - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) + -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse + + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ) +// 2D uT_11_x + - ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west + - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east - velocity_y_southEast * velocity_x_east + - velocity_y_northWest * velocity_x_west + velocity_y_southWest * velocity_x_west + ) * hxInverse * hyInverse + ) * this->dynamicalViscosity +// vT_21_x + - ( ( velocity_y_northEast * velocity_y_east - velocity_y_southEast * velocity_y_east + - velocity_y_northWest * velocity_y_west + velocity_y_southWest * velocity_y_west + ) * hxInverse * hyInverse + + ( velocity_x_east * velocity_y_center - velocity_x_center * velocity_y_west + - velocity_x_center * velocity_y_center + velocity_x_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_12_y + - ( ( velocity_x_northEast * velocity_x_north - velocity_x_southEast * velocity_x_south + - velocity_x_northWest * velocity_x_north + velocity_x_southWest * velocity_x_south + ) * hxInverse * hyInverse + + ( velocity_y_north * velocity_x_center - velocity_y_center * velocity_x_south + - velocity_y_center * velocity_x_center + velocity_y_south * velocity_x_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// 2D vT_22_y + - ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center - velocity_y_center * velocity_y_south + - velocity_y_center * velocity_y_center + velocity_y_south * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_north + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse + ) * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; + const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( e[ west ] + e[ east ] + e[ south ] + e[ north ] + e[ up ] + e[ down ] - 6.0 * e[ center ] ) + - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) + -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse + + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse + + ( ( ( e[ up ] + pressure_up ) * velocity_z_up ) + -( ( e[ down ] + pressure_down ) * velocity_z_down ) ) * hzInverse ) +// 3D uT_11_x + - ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west + - velocity_x_center * velocity_x_center - velocity_x_west * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east - velocity_y_southEast * velocity_x_east + - velocity_y_northWest * velocity_x_west + velocity_y_southWest * velocity_x_west + ) * hxInverse * hyInverse + - 2.0 / 3.0 * ( velocity_z_upEast * velocity_x_east - velocity_z_downEast * velocity_x_east + - velocity_z_upWest * velocity_x_west + velocity_z_downWest * velocity_x_west + ) * hxInverse * hzInverse + ) * this->dynamicalViscosity +// vT_21_x + - ( ( velocity_y_northEast * velocity_y_east - velocity_y_southEast * velocity_y_east + - velocity_y_northWest * velocity_y_west + velocity_y_southWest * velocity_y_west + ) * hxInverse * hyInverse + + ( velocity_x_east * velocity_y_center - velocity_x_center * velocity_y_west + - velocity_x_center * velocity_y_center - velocity_x_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// wT_31_x + - ( ( velocity_z_upEast * velocity_z_east - velocity_z_downEast * velocity_z_east + - velocity_z_upWest * velocity_z_west + velocity_z_downWest * velocity_z_west + ) * hxInverse * hzInverse + + ( velocity_x_east * velocity_z_center - velocity_x_center * velocity_z_east + - velocity_x_center * velocity_z_center - velocity_x_west * velocity_z_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_12_y + - ( ( velocity_x_northEast * velocity_x_north - velocity_x_southEast * velocity_x_south + - velocity_x_northWest * velocity_x_north + velocity_x_southWest * velocity_x_south + ) * hxInverse * hyInverse + + ( velocity_y_north * velocity_x_center - velocity_y_center * velocity_x_south + + velocity_y_center * velocity_x_center + velocity_y_south * velocity_x_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// 3D vT_22_y + - ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center - velocity_y_center * velocity_y_south + - velocity_y_center * velocity_y_center + velocity_y_south * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north - velocity_x_southEast * velocity_y_south + - velocity_x_northWest * velocity_y_north + velocity_x_southWest * velocity_y_south + ) * hxInverse * hyInverse + - 2.0 / 3.0 * ( velocity_z_upNorth * velocity_y_north - velocity_z_downNorth * velocity_y_north + - velocity_z_upSouth * velocity_y_south + velocity_z_downSouth * velocity_y_south + ) * hyInverse * hzInverse + ) * this->dynamicalViscosity +// wT_32_y + - ( ( velocity_z_upNorth * velocity_z_north - velocity_z_downNorth * velocity_y_north + - velocity_z_upSouth * velocity_z_south + velocity_z_downSouth * velocity_z_south + ) * hyInverse * hzInverse + + ( velocity_y_north * velocity_z_center - velocity_y_center * velocity_z_south + - velocity_y_center * velocity_z_center + velocity_y_south * velocity_z_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// uT_13_z + - ( ( velocity_z_up * velocity_x_center - velocity_z_center * velocity_x_center + - velocity_z_center * velocity_x_down + velocity_z_down * velocity_x_down + ) * hzSquareInverse + + ( velocity_x_upEast * velocity_x_up - velocity_x_downEast * velocity_x_down + - velocity_x_upWest * velocity_x_up + velocity_x_downWest * velocity_x_down + ) * hxInverse * hzInverse + ) * this->dynamicalViscosity +// T_23_z + - ( ( velocity_y_upNorth * velocity_y_up - velocity_y_downNorth * velocity_y_down + - velocity_y_upSouth * velocity_y_up + velocity_y_downSouth * velocity_y_down + ) * hyInverse * hzInverse + + ( velocity_z_up * velocity_y_center - velocity_z_center * velocity_y_down + - velocity_z_center * velocity_y_center + velocity_z_down * velocity_y_down + ) * hzSquareInverse + ) * this->dynamicalViscosity +// 3D T_33_z + - ( 4.0 / 3.0 * ( velocity_z_up * velocity_z_center - velocity_z_center * velocity_z_center + - velocity_z_center * velocity_z_center + velocity_z_down * velocity_z_down + ) * hzSquareInverse + - 2.0 / 3.0 * ( velocity_y_upNorth * velocity_z_up - velocity_y_downNorth * velocity_z_down + - velocity_y_upSouth * velocity_z_up + velocity_y_downSouth * velocity_z_down + ) * hyInverse * hzInverse + - 2.0 / 3.0 * ( velocity_x_upEast * velocity_z_up - velocity_x_downEast * velocity_z_down + - velocity_x_upWest * velocity_z_up + velocity_x_downWest * velocity_z_down + ) * hxInverse * hzInverse + ) * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsEnergyEuler.h b/examples/flow/LaxFridrichsEnergyEuler.h new file mode 100644 index 0000000000..7e326bef1b --- /dev/null +++ b/examples/flow/LaxFridrichsEnergyEuler.h @@ -0,0 +1,309 @@ +/*************************************************************************** + LaxFridrichsEnergy.h - description + ------------------- + begin : Feb 17, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsEnergyBase +{ + public: + + typedef Real RealType; + typedef Index IndexType; + typedef Mesh MeshType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + + LaxFridrichsEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + RealType artificialViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( e[ west ] - 2.0 * e[ center ] + e[ east ] ) + - 0.5 * ( ( e[ east ] + pressure_east ) * velocity_x_east + - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse; + + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( e[ west ] + e[ east ] + e[ south ] + e[ north ] - 4.0 * e[ center ] ) + - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) + -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse + + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; + const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( e[ west ] + e[ east ] + e[ south ] + e[ north ] + e[ up ] + e[ down ] - 6.0 * e[ center ] ) + - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) + -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse + + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse + + ( ( ( e[ up ] + pressure_up ) * velocity_z_up ) + -( ( e[ down ] + pressure_down ) * velocity_z_down ) ) * hzInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsEuler.h b/examples/flow/LaxFridrichsEuler.h new file mode 100644 index 0000000000..cdf32899f6 --- /dev/null +++ b/examples/flow/LaxFridrichsEuler.h @@ -0,0 +1,141 @@ +/*************************************************************************** + LaxFridrichs.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include <TNL/Functions/VectorField.h> + +#include "LaxFridrichsContinuity.h" +#include "LaxFridrichsEnergy.h" +#include "LaxFridrichsMomentumX.h" +#include "LaxFridrichsMomentumY.h" +#include "LaxFridrichsMomentumZ.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichs +{ + public: + typedef Mesh MeshType; + typedef Real RealType; + typedef typename Mesh::DeviceType DeviceType; + typedef Index IndexType; + typedef Functions::MeshFunction< Mesh > MeshFunctionType; + static const int Dimensions = Mesh::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef LaxFridrichsContinuity< Mesh, Real, Index > ContinuityOperatorType; + typedef LaxFridrichsMomentumX< Mesh, Real, Index > MomentumXOperatorType; + typedef LaxFridrichsMomentumY< Mesh, Real, Index > MomentumYOperatorType; + typedef LaxFridrichsMomentumZ< Mesh, Real, Index > MomentumZOperatorType; + typedef LaxFridrichsEnergy< Mesh, Real, Index > EnergyOperatorType; + + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef SharedPointer< VectorFieldType > VectorFieldPointer; + typedef SharedPointer< MeshType > MeshPointer; + + typedef SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "numerical-viscosity", "Value of artificial (numerical) viscosity in the Lax-Fridrichs scheme", 1.0 ); + } + + LaxFridrichs() + : artificialViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->artificialViscosity = parameters.getParameter< double >( prefix + "numerical-viscosity" ); + this->continuityOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->momentumXOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->momentumYOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->momentumZOperatorPointer->setArtificialViscosity( artificialViscosity ); + this->energyOperatorPointer->setArtificialViscosity( artificialViscosity ); + + return true; + } + + void setTau( const RealType& tau ) + { + this->continuityOperatorPointer->setTau( tau ); + this->momentumXOperatorPointer->setTau( tau ); + this->momentumYOperatorPointer->setTau( tau ); + this->momentumZOperatorPointer->setTau( tau ); + this->energyOperatorPointer->setTau( tau ); + } + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->momentumXOperatorPointer->setPressure( pressure ); + this->momentumYOperatorPointer->setPressure( pressure ); + this->momentumZOperatorPointer->setPressure( pressure ); + this->energyOperatorPointer->setPressure( pressure ); + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + this->continuityOperatorPointer->setVelocity( velocity ); + this->momentumXOperatorPointer->setVelocity( velocity ); + this->momentumYOperatorPointer->setVelocity( velocity ); + this->momentumZOperatorPointer->setVelocity( velocity ); + this->energyOperatorPointer->setVelocity( velocity ); + } + + const ContinuityOperatorPointer& getContinuityOperator() const + { + return this->continuityOperatorPointer; + } + + const MomentumXOperatorPointer& getMomentumXOperator() const + { + return this->momentumXOperatorPointer; + } + + const MomentumYOperatorPointer& getMomentumYOperator() const + { + return this->momentumYOperatorPointer; + } + + const MomentumZOperatorPointer& getMomentumZOperator() const + { + return this->momentumZOperatorPointer; + } + + const EnergyOperatorPointer& getEnergyOperator() const + { + return this->energyOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + + RealType artificialViscosity; +}; + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsMomentumBase.h b/examples/flow/LaxFridrichsMomentumBase.h new file mode 100644 index 0000000000..5f02acfe2c --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumBase.h @@ -0,0 +1,73 @@ +/*************************************************************************** + LaxFridrichsMomentumBase.h - description + ------------------- + begin : Feb 17, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumBase +{ + public: + + typedef Real RealType; + typedef Index IndexType; + typedef Mesh MeshType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + + LaxFridrichsMomentumBase() + : artificialViscosity( 1.0 ){}; + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; +}; + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsMomentumBaseEuler.h b/examples/flow/LaxFridrichsMomentumBaseEuler.h new file mode 100644 index 0000000000..67dae9fdf8 --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumBaseEuler.h @@ -0,0 +1,68 @@ +/*************************************************************************** + LaxFridrichsMomentumBase.h - description + ------------------- + begin : Feb 17, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumBase +{ + public: + + typedef Real RealType; + typedef Index IndexType; + typedef Mesh MeshType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + + LaxFridrichsMomentumBase() + : artificialViscosity( 1.0 ){}; + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + RealType artificialViscosity; +}; + +} //namespace TNL diff --git a/examples/flow/LaxFridrichsMomentumX.h b/examples/flow/LaxFridrichsMomentumX.h new file mode 100644 index 0000000000..d24b427f94 --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumX.h @@ -0,0 +1,374 @@ +/*************************************************************************** + LaxFridrichsMomentumX.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] - 2.0 * rho_u[ center ] ) + - 0.5 * ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse +// 1D T_11_x + - 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] - 4.0 * rho_u[ center ] ) + - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + - ( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse + + ( ( rho_u[ north ] * velocity_y_north ) + - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ) +// 2D T_11_x + - ( 4.0 / 3.0 * ( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + ) * hxInverse * hyInverse + ) * this->dynamicalViscosity +// T_21_x + - ( ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + ) * hxInverse * hyInverse + + ( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxInverse * hyInverse + ) * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + //const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + //const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + //const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; + //const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] + rho_u[ up ] + rho_u[ down ] - 6.0 * rho_u[ center ] ) + - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + - ( rho_u[ west ] * velocity_x_west + pressure_west ) )* hxInverse + + ( ( rho_u[ north ] * velocity_y_north ) + - ( rho_u[ south ] * velocity_y_south ) )* hyInverse + + ( ( rho_u[ up ] * velocity_z_up ) + - ( rho_u[ down ] * velocity_z_down ) )* hzInverse ) +// 3D T_11_x + - ( 4.0 / 3.0 * ( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + ) * hxInverse * hyInverse + - 2.0 / 3.0 * ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse + ) * this->dynamicalViscosity +// T_21_x + - ( ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + ) * hxInverse * hyInverse + + ( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxInverse * hyInverse + ) * this->dynamicalViscosity +// T_31_x + - ( ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse + + ( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxInverse * hyInverse + ) * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} // namespace TNL + diff --git a/examples/flow/LaxFridrichsMomentumXEuler.h b/examples/flow/LaxFridrichsMomentumXEuler.h new file mode 100644 index 0000000000..63def12d31 --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumXEuler.h @@ -0,0 +1,276 @@ +/*************************************************************************** + LaxFridrichsMomentumX.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] - 2.0 * rho_u[ center ] ) + - 0.5 * ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] - 4.0 * rho_u[ center ] ) + - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + - ( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse + + ( ( rho_u[ north ] * velocity_y_north ) + - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + //const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + //const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + //const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; + //const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] + rho_u[ up ] + rho_u[ down ] - 6.0 * rho_u[ center ] ) + - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + - ( rho_u[ west ] * velocity_x_west + pressure_west ) )* hxInverse + + ( ( rho_u[ north ] * velocity_y_north ) + - ( rho_u[ south ] * velocity_y_south ) )* hyInverse + + ( ( rho_u[ up ] * velocity_z_up ) + - ( rho_u[ down ] * velocity_z_down ) )* hzInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} // namespace TNL + diff --git a/examples/flow/LaxFridrichsMomentumY.h b/examples/flow/LaxFridrichsMomentumY.h new file mode 100644 index 0000000000..4c5c5f4b88 --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumY.h @@ -0,0 +1,358 @@ +/*************************************************************************** + LaxFridrichsMomentumY.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + //const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + return 0.0; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] - 4.0 * rho_v[ center ] ) + - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) + - ( rho_v[ west ] * velocity_x_west ) )* hxInverse + + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) + - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ) +// 2D T_22_y + - ( 4.0 / 3.0 * ( velocity_y_north - 2 * velocity_y_center + velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse + ) * this->dynamicalViscosity +// T_12_y + - ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse + + ( velocity_y_north - 2 * velocity_y_center + velocity_y_south + ) * hySquareInverse + ) * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; + const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] + rho_v[ up ] + rho_v[ down ] - 6.0 * rho_v[ center ] ) + - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) + - ( rho_v[ west ] * velocity_x_west ) ) * hxInverse + + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) + - ( rho_v[ south ] * velocity_y_south + pressure_south ) ) * hyInverse + + ( ( rho_v[ up ] * velocity_z_up ) + - ( rho_v[ down ] * velocity_z_down ) ) * hzInverse ) +// T_12_y + - ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse + + ( velocity_y_north - 2 * velocity_y_center + velocity_y_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// 3D T_22_y + - ( 4.0 / 3.0 * ( velocity_y_north - 2 * velocity_y_center + velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse + - 2.0 / 3.0 * ( velocity_z_upNorth - velocity_z_downNorth - velocity_z_upSouth + velocity_z_downSouth + ) * hyInverse * hzInverse + ) * this->dynamicalViscosity +// T_32_y + - ( ( velocity_z_upNorth - velocity_z_downNorth - velocity_z_upSouth + velocity_z_downSouth + ) * hyInverse * hzInverse + + ( velocity_y_north - 2 * velocity_y_center + velocity_y_south + ) * hySquareInverse + ) * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} // namespace TNL + diff --git a/examples/flow/LaxFridrichsMomentumYEuler.h b/examples/flow/LaxFridrichsMomentumYEuler.h new file mode 100644 index 0000000000..8ce42282dd --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumYEuler.h @@ -0,0 +1,260 @@ +/*************************************************************************** + LaxFridrichsMomentumY.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + //const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + return 0.0; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] - 4.0 * rho_v[ center ] ) + - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) + - ( rho_v[ west ] * velocity_x_west ) )* hxInverse + + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) + - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] + rho_v[ up ] + rho_v[ down ] - 6.0 * rho_v[ center ] ) + - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) + - ( rho_v[ west ] * velocity_x_west ) ) * hxInverse + + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) + - ( rho_v[ south ] * velocity_y_south + pressure_south ) ) * hyInverse + + ( ( rho_v[ up ] * velocity_z_up ) + - ( rho_v[ down ] * velocity_z_down ) ) * hzInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} // namespace TNL + diff --git a/examples/flow/LaxFridrichsMomentumZ.h b/examples/flow/LaxFridrichsMomentumZ.h new file mode 100644 index 0000000000..0ae1e6f357 --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumZ.h @@ -0,0 +1,303 @@ +/*************************************************************************** + LaxFridrichsMomentumZ.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + //const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + return 0.0; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + //const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + return 0.0; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; + const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( rho_w[ west ] + rho_w[ east ] + rho_w[ south ] + rho_w[ north ] + rho_w[ up ] + rho_w[ down ] - 6.0 * rho_w[ center ] ) + -0.5 * ( ( ( rho_w[ east ] * velocity_x_east ) + - ( rho_w[ west ] * velocity_x_west ) )* hxInverse + + ( ( rho_w[ north ] * velocity_y_north ) + - ( rho_w[ south ] * velocity_y_south ) )* hyInverse + + ( ( rho_w[ up ] * velocity_z_up + pressure_up ) + - ( rho_w[ down ] * velocity_z_down + pressure_down ) )* hzInverse ) +// T_13_z + - ( ( velocity_z_up - 2 * velocity_z_center + velocity_z_down ) * hzSquareInverse + + ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) * hxInverse * hzInverse ) + * this->dynamicalViscosity +// T_23_z + - ( ( velocity_y_upNorth - velocity_y_downNorth - velocity_y_upSouth + velocity_y_downSouth ) * hyInverse * hzInverse + + ( velocity_z_up - 2 * velocity_z_center + velocity_z_down ) * hzSquareInverse ) + * this->dynamicalViscosity +// 3D T_33_z + - ( 4.0 / 3.0 * ( velocity_z_up - 2 * velocity_z_center + velocity_z_down ) * hzSquareInverse + - 2.0 / 3.0 * ( velocity_y_upNorth - velocity_y_downNorth - velocity_y_upSouth + velocity_y_downSouth ) * hyInverse * hzInverse + - 2.0 / 3.0 * ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) * hxInverse * hzInverse ) + * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} // namespace TNL + diff --git a/examples/flow/LaxFridrichsMomentumZEuler.h b/examples/flow/LaxFridrichsMomentumZEuler.h new file mode 100644 index 0000000000..a67e862cef --- /dev/null +++ b/examples/flow/LaxFridrichsMomentumZEuler.h @@ -0,0 +1,240 @@ +/*************************************************************************** + LaxFridrichsMomentumZ.h - description + ------------------- + begin : Feb 18, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Containers/Vector.h> +#include <TNL/Meshes/Grid.h> +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + //const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + return 0.0; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + //const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + return 0.0; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + + const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; + const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * + ( rho_w[ west ] + rho_w[ east ] + rho_w[ south ] + rho_w[ north ] + rho_w[ up ] + rho_w[ down ] - 6.0 * rho_w[ center ] ) + -0.5 * ( ( ( rho_w[ east ] * velocity_x_east ) + - ( rho_w[ west ] * velocity_x_west ) )* hxInverse + + ( ( rho_w[ north ] * velocity_y_north ) + - ( rho_w[ south ] * velocity_y_south ) )* hyInverse + + ( ( rho_w[ up ] * velocity_z_up + pressure_up ) + - ( rho_w[ down ] * velocity_z_down + pressure_down ) )* hzInverse ); + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + + +} // namespace TNL + diff --git a/examples/flow/PhysicalVariablesGetter.h b/examples/flow/PhysicalVariablesGetter.h new file mode 100644 index 0000000000..58fd5df7a5 --- /dev/null +++ b/examples/flow/PhysicalVariablesGetter.h @@ -0,0 +1,116 @@ +/*************************************************************************** + CompressibleConservativeVariables.h - description + ------------------- + begin : Feb 12, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/SharedPointer.h> +#include <TNL/Functions/MeshFunction.h> +#include <TNL/Functions/VectorField.h> +#include <TNL/Functions/MeshFunctionEvaluator.h> +#include "CompressibleConservativeVariables.h" + +namespace TNL { + +template< typename Mesh > +class PhysicalVariablesGetter +{ + public: + + typedef Mesh MeshType; + typedef typename MeshType::RealType RealType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::IndexType IndexType; + static const int Dimensions = MeshType::getMeshDimension(); + + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + + class VelocityGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + VelocityGetter( MeshFunctionPointer density, + MeshFunctionPointer momentum ) + : density( density ), momentum( momentum ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + return momentum.template getData< DeviceType >()( meshEntity ) / + density.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer density, momentum; + }; + + class PressureGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + PressureGetter( MeshFunctionPointer density, + MeshFunctionPointer energy, + VelocityFieldPointer momentum, + const RealType& gamma ) + : density( density ), energy( energy ), momentum( momentum ), gamma( gamma ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + const RealType e = energy.template getData< DeviceType >()( meshEntity ); + const RealType rho = density.template getData< DeviceType >()( meshEntity ); + const RealType momentumNorm = momentum.template getData< DeviceType >().getVector( meshEntity ).lpNorm( 2.0 ); + return ( gamma - 1.0 ) * ( e - 0.5 * momentumNorm * momentumNorm / rho ); + } + + protected: + const MeshFunctionPointer density, energy; + const VelocityFieldPointer momentum; + const RealType gamma; + }; + + + void getVelocity( const ConservativeVariablesPointer& conservativeVariables, + VelocityFieldPointer& velocity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, VelocityGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + SharedPointer< VelocityGetter, DeviceType > velocityGetter( conservativeVariables->getDensity(), + ( *conservativeVariables->getMomentum() )[ i ] ); + evaluator.evaluate( ( *velocity )[ i ], velocityGetter ); + } + } + + void getPressure( const ConservativeVariablesPointer& conservativeVariables, + const RealType& gamma, + MeshFunctionPointer& pressure ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, PressureGetter > evaluator; + SharedPointer< PressureGetter, DeviceType > pressureGetter( conservativeVariables->getDensity(), + conservativeVariables->getEnergy(), + conservativeVariables->getMomentum(), + gamma ); + evaluator.evaluate( pressure, pressureGetter ); + } + +}; + +} //namespace TNL diff --git a/examples/flow/RiemannProblemInitialCondition.h b/examples/flow/RiemannProblemInitialCondition.h new file mode 100644 index 0000000000..664d93ea32 --- /dev/null +++ b/examples/flow/RiemannProblemInitialCondition.h @@ -0,0 +1,1417 @@ +/*************************************************************************** + RiemannProblemInitialCondition.h - description + ------------------- + begin : Feb 13, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Containers/StaticVector.h> +#include <TNL/Operators/Analytic/Sign.h> +#include <TNL/Functions/MeshFunctionEvaluator.h> +#include <TNL/Operators/Analytic/Sign.h> +#include <TNL/Meshes/Grid.h> +#include "CompressibleConservativeVariables.h" + +namespace TNL { +template <typename Mesh> +class RiemannProblemInitialConditionSetter +{ + +}; + +template <typename MeshReal, + typename Device, + typename MeshIndex> +class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, MeshIndex > > +{ + public: + + typedef Meshes::Grid< 1,MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::RealType RealType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::IndexType IndexType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Containers::StaticVector< Dimensions, RealType > PointType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Functions::VectorField< Dimensions, MeshType > VectorFieldType; +// for cyklus i = 0 to mesh.getDimensions().x() j pro .y() a k pro .z() +// typedef typename MeshType::Cell CellType +// typedef typename MeshType::CoordinatesType CoordinatesType +// Celltype cell(mesh, CoordinatesType(i,j)) +// p59stup do density setElement(mesh.template getEntityIndex< CellType >(cell), hodnota, kterou budu zapisovat) +// pomocn8 t59da, kterou budu specialiyovat p5es r;zn0 dimenze gridu + + void setDiscontinuity(PointType discontinuityPlacement) + { + this->discontinuityPlacement = discontinuityPlacement; + }; + void setDensity(RealType NWUDensity, + RealType NEUDensity, + RealType SWUDensity, + RealType SEUDensity, + RealType NWDDensity, + RealType NEDDensity, + RealType SWDDensity, + RealType SEDDensity) + { + this->NWUDensity = NWUDensity; + this->NEUDensity = NEUDensity; + this->SWUDensity = SWUDensity; + this->SEUDensity = SEUDensity; + this->NWDDensity = NWDDensity; + this->NEDDensity = NEDDensity; + this->SWDDensity = SWDDensity; + this->SEDDensity = SEDDensity; + }; + + void setMomentum(PointType NWUMomentum, + PointType NEUMomentum, + PointType SWUMomentum, + PointType SEUMomentum, + PointType NWDMomentum, + PointType NEDMomentum, + PointType SWDMomentum, + PointType SEDMomentum) + { + this->NWUMomentum = NWUMomentum; + this->NEUMomentum = NEUMomentum; + this->SWUMomentum = SWUMomentum; + this->SEUMomentum = SEUMomentum; + this->NWDMomentum = NWDMomentum; + this->NEDMomentum = NEDMomentum; + this->SWDMomentum = SWDMomentum; + this->SEDMomentum = SEDMomentum; + }; + + void setEnergy(RealType NWUEnergy, + RealType NEUEnergy, + RealType SWUEnergy, + RealType SEUEnergy, + RealType NWDEnergy, + RealType NEDEnergy, + RealType SWDEnergy, + RealType SEDEnergy) + { + this->NWUEnergy = NWUEnergy; + this->NEUEnergy = NEUEnergy; + this->SWUEnergy = SWUEnergy; + this->SEUEnergy = SEUEnergy; + this->NWDEnergy = NWDEnergy; + this->NEDEnergy = NEDEnergy; + this->SWDEnergy = SWDEnergy; + this->SEDEnergy = SEDEnergy; + }; + + void setGamma(RealType gamma) + { + this->gamma = gamma; + }; + + void placeDensity(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + if ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SWDDensity); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SEDDensity); + } + }; + + void placeMomentum(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + if ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWDMomentum[ 0 ]); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEDMomentum[ 0 ]); + } + }; + + void placeEnergy(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + if ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SWDEnergy); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SEDEnergy); + } + }; + + PointType discontinuityPlacement; + RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; + RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; + RealType gamma; +}; + + +template <typename MeshReal, + typename Device, + typename MeshIndex> +class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, MeshIndex > > +{ + public: + + typedef Meshes::Grid< 2,MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::RealType RealType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::IndexType IndexType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Containers::StaticVector< Dimensions, RealType > PointType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Functions::VectorField< Dimensions, MeshType > VectorFieldType; +// for cyklus i = 0 to mesh.getDimensions().x() j pro .y() a k pro .z() +// typedef typename MeshType::Cell CellType +// typedef typename MeshType::CoordinatesType CoordinatesType +// Celltype cell(mesh, CoordinatesType(i,j)) +// p59stup do density setElement(mesh.template getEntityIndex< CellType >(cell), hodnota, kterou budu zapisovat) +// pomocn8 t59da, kterou budu specialiyovat p5es r;zn0 dimenze gridu + + void setDiscontinuity(PointType discontinuityPlacement) + { + this->discontinuityPlacement = discontinuityPlacement; + }; + void setDensity(RealType NWUDensity, + RealType NEUDensity, + RealType SWUDensity, + RealType SEUDensity, + RealType NWDDensity, + RealType NEDDensity, + RealType SWDDensity, + RealType SEDDensity) + { + this->NWUDensity = NWUDensity; + this->NEUDensity = NEUDensity; + this->SWUDensity = SWUDensity; + this->SEUDensity = SEUDensity; + this->NWDDensity = NWDDensity; + this->NEDDensity = NEDDensity; + this->SWDDensity = SWDDensity; + this->SEDDensity = SEDDensity; + }; + + void setMomentum(PointType NWUMomentum, + PointType NEUMomentum, + PointType SWUMomentum, + PointType SEUMomentum, + PointType NWDMomentum, + PointType NEDMomentum, + PointType SWDMomentum, + PointType SEDMomentum) + { + this->NWUMomentum = NWUMomentum; + this->NEUMomentum = NEUMomentum; + this->SWUMomentum = SWUMomentum; + this->SEUMomentum = SEUMomentum; + this->NWDMomentum = NWDMomentum; + this->NEDMomentum = NEDMomentum; + this->SWDMomentum = SWDMomentum; + this->SEDMomentum = SEDMomentum; + }; + + void setEnergy(RealType NWUEnergy, + RealType NEUEnergy, + RealType SWUEnergy, + RealType SEUEnergy, + RealType NWDEnergy, + RealType NEDEnergy, + RealType SWDEnergy, + RealType SEDEnergy) + { + this->NWUEnergy = NWUEnergy; + this->NEUEnergy = NEUEnergy; + this->SWUEnergy = SWUEnergy; + this->SEUEnergy = SEUEnergy; + this->NWDEnergy = NWDEnergy; + this->NEDEnergy = NEDEnergy; + this->SWDEnergy = SWDEnergy; + this->SEDEnergy = SEDEnergy; + }; + + void setGamma(RealType gamma) + { + this->gamma = gamma; + }; + + void placeDensity(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + for( int j = 0; j < mesh.getDimensions().y(); j++) + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SWDDensity); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SEDDensity); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->NWDDensity); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->NEDDensity); + } + }; + + void placeMomentum(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + for( int j = 0; j < mesh.getDimensions().y(); j++) + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWDMomentum[ 1 ]); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEDMomentum[ 1 ]); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NWDMomentum[ 1 ]); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NEDMomentum[ 1 ]); + } + }; + + void placeEnergy(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + for( int j = 0; j < mesh.getDimensions().y(); j++) + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SWDEnergy); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SEDEnergy); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->NWDEnergy); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) + { + CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->NEDEnergy); + } + }; + + PointType discontinuityPlacement; + RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; + RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; + RealType gamma; +}; + +template <typename MeshReal, + typename Device, + typename MeshIndex> +class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, MeshIndex > > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::RealType RealType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::IndexType IndexType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Containers::StaticVector< Dimensions, RealType > PointType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Functions::VectorField< Dimensions, MeshType > VectorFieldType; +// for cyklus i = 0 to mesh.getDimensions().x() j pro .y() a k pro .z() +// typedef typename MeshType::Cell CellType +// typedef typename MeshType::CoordinatesType CoordinatesType +// Celltype cell(mesh, CoordinatesType(i,j)) +// p59stup do density setElement(mesh.template getEntityIndex< CellType >(cell), hodnota, kterou budu zapisovat) +// pomocn8 t59da, kterou budu specialiyovat p5es r;zn0 dimenze gridu + + void setDiscontinuity(PointType discontinuityPlacement) + { + this->discontinuityPlacement = discontinuityPlacement; + }; + void setDensity(RealType NWUDensity, + RealType NEUDensity, + RealType SWUDensity, + RealType SEUDensity, + RealType NWDDensity, + RealType NEDDensity, + RealType SWDDensity, + RealType SEDDensity) + { + this->NWUDensity = NWUDensity; + this->NEUDensity = NEUDensity; + this->SWUDensity = SWUDensity; + this->SEUDensity = SEUDensity; + this->NWDDensity = NWDDensity; + this->NEDDensity = NEDDensity; + this->SWDDensity = SWDDensity; + this->SEDDensity = SEDDensity; + }; + + void setMomentum(PointType NWUMomentum, + PointType NEUMomentum, + PointType SWUMomentum, + PointType SEUMomentum, + PointType NWDMomentum, + PointType NEDMomentum, + PointType SWDMomentum, + PointType SEDMomentum) + { + this->NWUMomentum = NWUMomentum; + this->NEUMomentum = NEUMomentum; + this->SWUMomentum = SWUMomentum; + this->SEUMomentum = SEUMomentum; + this->NWDMomentum = NWDMomentum; + this->NEDMomentum = NEDMomentum; + this->SWDMomentum = SWDMomentum; + this->SEDMomentum = SEDMomentum; + }; + + void setEnergy(RealType NWUEnergy, + RealType NEUEnergy, + RealType SWUEnergy, + RealType SEUEnergy, + RealType NWDEnergy, + RealType NEDEnergy, + RealType SWDEnergy, + RealType SEDEnergy) + { + this->NWUEnergy = NWUEnergy; + this->NEUEnergy = NEUEnergy; + this->SWUEnergy = SWUEnergy; + this->SEUEnergy = SEUEnergy; + this->NWDEnergy = NWDEnergy; + this->NEDEnergy = NEDEnergy; + this->SWDEnergy = SWDEnergy; + this->SEDEnergy = SEDEnergy; + }; + + void setGamma(RealType gamma) + { + this->gamma = gamma; + }; + + void placeDensity(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + for( int j = 0; j < mesh.getDimensions().y(); j++) + for ( int k = 0; k < mesh.getDimensions().z(); k++) + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SWDDensity); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SEDDensity); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->NWDDensity); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->NEDDensity); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SWUDensity); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SEUDensity); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SWUDensity); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SEUDensity); + } + }; + + void placeMomentum(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + for( int j = 0; j < mesh.getDimensions().y(); j++) + for ( int k = 0; k < mesh.getDimensions().z(); k++) + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SWDMomentum[ 2 ]); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SEDMomentum[ 2 ]); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NWDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->NWDMomentum[ 2 ]); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NEDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->NEDMomentum[ 2 ]); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SWUMomentum[ 2 ]); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SEUMomentum[ 2 ]); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SWUMomentum[ 2 ]); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SEUMomentum[ 2 ]); + } + }; + + void placeEnergy(CompressibleConservativeVariables< MeshType >& conservativeVariables) + { + typedef typename MeshType::Cell CellType; + typedef typename MeshType::CoordinatesType CoordinatesType; + MeshType mesh = (* conservativeVariables.getDensity()).getMesh(); + for( int i = 0; i < mesh.getDimensions().x(); i++) + for( int j = 0; j < mesh.getDimensions().y(); j++) + for ( int k = 0; k < mesh.getDimensions().z(); k++) + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SWDEnergy); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SEDEnergy); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->NWDEnergy); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->NEDEnergy); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SWUEnergy); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SEUEnergy); + } + else + if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SWUEnergy); + } + else + if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) + && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) + && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) + { + CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SEUEnergy); + } + }; + + PointType discontinuityPlacement; + RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; + RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; + RealType gamma; +}; + +template< typename Mesh > +class RiemannProblemInitialCondition +{ + public: + + typedef Mesh MeshType; + typedef typename MeshType::RealType RealType; + typedef typename MeshType::DeviceType DeviceType; + typedef typename MeshType::IndexType IndexType; + static const int Dimensions = MeshType::getMeshDimension(); + typedef Containers::StaticVector< Dimensions, RealType > PointType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Functions::VectorField< Dimensions, MeshType > VectorFieldType; + + RiemannProblemInitialCondition() + : discontinuityPlacement( 0.5 ), + leftDensity( 1.0 ), rightDensity( 1.0 ), + leftVelocity( -2.0 ), rightVelocity( 2.0 ), + leftPressure( 0.4 ), rightPressure( 0.4 ), + gamma( 1.67 ){} + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "discontinuity-placement-0", "x-coordinate of the discontinuity placement.", 0.5 ); + config.addEntry< double >( prefix + "discontinuity-placement-1", "y-coordinate of the discontinuity placement.", 0.5 ); + config.addEntry< double >( prefix + "discontinuity-placement-2", "z-coordinate of the discontinuity placement.", 0.5 ); +/* + config.addEntry< double >( prefix + "left-density", "Density on the left side of the discontinuity.", 1.0 ); + config.addEntry< double >( prefix + "right-density", "Density on the right side of the discontinuity.", 0.0 ); + config.addEntry< double >( prefix + "left-velocity-0", "x-coordinate of the velocity on the left side of the discontinuity.", 1.0 ); + config.addEntry< double >( prefix + "left-velocity-1", "y-coordinate of the velocity on the left side of the discontinuity.", 1.0 ); + config.addEntry< double >( prefix + "left-velocity-2", "z-coordinate of the velocity on the left side of the discontinuity.", 1.0 ); + config.addEntry< double >( prefix + "right-velocity-0", "x-coordinate of the velocity on the right side of the discontinuity.", 0.0 ); + config.addEntry< double >( prefix + "right-velocity-1", "y-coordinate of the velocity on the right side of the discontinuity.", 0.0 ); + config.addEntry< double >( prefix + "right-velocity-2", "z-coordinate of the velocity on the right side of the discontinuity.", 0.0 ); + config.addEntry< double >( prefix + "left-pressure", "Pressure on the left side of the discontinuity.", 1.0 ); + config.addEntry< double >( prefix + "right-pressure", "Pressure on the right side of the discontinuity.", 0.0 ); +*/ + config.addEntry< double >( prefix + "NWU-density", "This sets a value of northwest up density.", 1.0 ); + config.addEntry< double >( prefix + "NWU-velocity-0", "This sets a value of northwest up x velocity.", 1.0 ); + config.addEntry< double >( prefix + "NWU-velocity-1", "This sets a value of northwest up y velocity.", 1.0 ); + config.addEntry< double >( prefix + "NWU-velocity-2", "This sets a value of northwest up z velocity.", 1.0 ); + config.addEntry< double >( prefix + "NWU-pressure", "This sets a value of northwest up pressure.", 1.0 ); + config.addEntry< double >( prefix + "SWU-density", "This sets a value of southwest up density.", 1.0 ); + config.addEntry< double >( prefix + "SWU-velocity-0", "This sets a value of southwest up x velocity.", 1.0 ); + config.addEntry< double >( prefix + "SWU-velocity-1", "This sets a value of southwest up y velocity.", 1.0 ); + config.addEntry< double >( prefix + "SWU-velocity-2", "This sets a value of southwest up z velocity.", 1.0 ); + config.addEntry< double >( prefix + "SWU-pressure", "This sets a value of southwest up pressure.", 1.0 ); + config.addEntry< double >( prefix + "NWD-density", "This sets a value of northwest down density.", 1.0 ); + config.addEntry< double >( prefix + "NWD-velocity-0", "This sets a value of northwest down x velocity.", 1.0 ); + config.addEntry< double >( prefix + "NWD-velocity-1", "This sets a value of northwest down y velocity.", 1.0 ); + config.addEntry< double >( prefix + "NWD-velocity-2", "This sets a value of northwest down z velocity.", 1.0 ); + config.addEntry< double >( prefix + "NWD-pressure", "This sets a value of northwest down pressure.", 1.0 ); + config.addEntry< double >( prefix + "SWD-density", "This sets a value of southwest down density.", 1.0 ); + config.addEntry< double >( prefix + "SWD-velocity-0", "This sets a value of southwest down x velocity.", 1.0 ); + config.addEntry< double >( prefix + "SWD-velocity-1", "This sets a value of southwest down y velocity.", 1.0 ); + config.addEntry< double >( prefix + "SWD-velocity-2", "This sets a value of southwest down z velocity.", 1.0 ); + config.addEntry< double >( prefix + "SWD-pressure", "This sets a value of southwest down pressure.", 1.0 ); + config.addEntry< double >( prefix + "NEU-density", "This sets a value of northeast up density.", 1.0 ); + config.addEntry< double >( prefix + "NEU-velocity-0", "This sets a value of northeast up x velocity.", 1.0 ); + config.addEntry< double >( prefix + "NEU-velocity-1", "This sets a value of northeast up y velocity.", 1.0 ); + config.addEntry< double >( prefix + "NEU-velocity-2", "This sets a value of northeast up z velocity.", 1.0 ); + config.addEntry< double >( prefix + "NEU-pressure", "This sets a value of northeast up pressure.", 1.0 ); + config.addEntry< double >( prefix + "SEU-density", "This sets a value of southeast up density.", 1.0 ); + config.addEntry< double >( prefix + "SEU-velocity-0", "This sets a value of southeast up x velocity.", 1.0 ); + config.addEntry< double >( prefix + "SEU-velocity-1", "This sets a value of southeast up y velocity.", 1.0 ); + config.addEntry< double >( prefix + "SEU-velocity-2", "This sets a value of southeast up z velocity.", 1.0 ); + config.addEntry< double >( prefix + "SEU-pressure", "This sets a value of southeast up pressure.", 1.0 ); + config.addEntry< double >( prefix + "NED-density", "This sets a value of northeast down density.", 1.0 ); + config.addEntry< double >( prefix + "NED-velocity-0", "This sets a value of northeast down x velocity.", 1.0 ); + config.addEntry< double >( prefix + "NED-velocity-1", "This sets a value of northeast down y velocity.", 1.0 ); + config.addEntry< double >( prefix + "NED-velocity-2", "This sets a value of northeast down z velocity.", 1.0 ); + config.addEntry< double >( prefix + "NED-pressure", "This sets a value of northeast down pressure.", 1.0 ); + config.addEntry< double >( prefix + "SED-density", "This sets a value of southeast down density.", 1.0 ); + config.addEntry< double >( prefix + "SED-velocity-0", "This sets a value of southeast down x velocity.", 1.0 ); + config.addEntry< double >( prefix + "SED-velocity-1", "This sets a value of southeast down y velocity.", 1.0 ); + config.addEntry< double >( prefix + "SED-velocity-2", "This sets a value of southeast down z velocity.", 1.0 ); + config.addEntry< double >( prefix + "SED-pressure", "This sets a value of southeast down pressure.", 1.0 ); + config.addEntry< double >( prefix + "gamma", "Gamma in the ideal gas state equation.", 1.4 ); + + config.addEntry< String >( prefix + "initial", " One of predefined initial condition.", "none"); + config.addEntryEnum< String >( "none" ); + config.addEntryEnum< String >( "1D_2" ); + config.addEntryEnum< String >( "1D_3a" ); + config.addEntryEnum< String >( "1D_4" ); + config.addEntryEnum< String >( "1D_5" ); + config.addEntryEnum< String >( "1D_6" ); + config.addEntryEnum< String >( "1D_Noh" ); + config.addEntryEnum< String >( "1D_peak" ); + config.addEntryEnum< String >( "2D_3" ); + config.addEntryEnum< String >( "2D_4" ); + config.addEntryEnum< String >( "2D_6" ); + config.addEntryEnum< String >( "2D_12" ); + config.addEntryEnum< String >( "2D_15" ); + config.addEntryEnum< String >( "2D_17" ); + } + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + String initial = parameters.getParameter< String >( prefix + "initial" ); + if(initial == prefix + "none") + { + this->discontinuityPlacement.setup( parameters, prefix + "discontinuity-placement-" ); + this->gamma = parameters.getParameter< double >( prefix + "gamma" ); +/* + this->leftVelocity.setup( parameters, prefix + "left-velocity-" ); + this->rightVelocity.setup( parameters, prefix + "right-velocity-" ); + this->leftDensity = parameters.getParameter< double >( prefix + "left-density" ); + this->rightDensity = parameters.getParameter< double >( prefix + "right-density" ); + this->leftPressure = parameters.getParameter< double >( prefix + "left-pressure" ); + this->rightPressure = parameters.getParameter< double >( prefix + "right-pressure" ); +*/ + + this->NWUDensity = parameters.getParameter< RealType >( prefix + "NWU-density" ); + this->NWUVelocity.setup( parameters, prefix + "NWU-velocity-" ); + this->NWUPressure = parameters.getParameter< RealType >( prefix + "NWU-pressure" ); + this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); + this->NWUMomentum = NWUVelocity * NWUDensity; + + this->SWUDensity = parameters.getParameter< RealType >( prefix + "SWU-density" ); + this->SWUVelocity.setup( parameters, prefix + "SWU-velocity-" ); + this->SWUPressure = parameters.getParameter< RealType >( prefix + "SWU-pressure" ); + this->SWUEnergy = Energy( SWUDensity, SWUPressure, gamma, SWUVelocity); + this->SWUMomentum = SWUVelocity * SWUDensity; + + this->NWDDensity = parameters.getParameter< RealType >( prefix + "NWD-density" ); + this->NWDVelocity.setup( parameters, prefix + "NWD-velocity-" ); + this->NWDPressure = parameters.getParameter< RealType >( prefix + "NWD-pressure" ); + this->SWUEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); + this->NWDMomentum = NWDVelocity * NWDDensity; + + this->SWDDensity = parameters.getParameter< RealType >( prefix + "SWD-density" ); + this->SWDVelocity.setup( parameters, prefix + "SWD-velocity-" ); + this->SWDPressure = parameters.getParameter< RealType >( prefix + "SWD-pressure" ); + this->SWDEnergy = Energy( SWDDensity, SWDPressure, gamma, SWDVelocity); + this->SWDMomentum = SWDVelocity * SWDDensity; + + this->NEUDensity = parameters.getParameter< RealType >( prefix + "NEU-density" ); + this->NEUVelocity.setup( parameters, prefix + "NEU-velocity-" ); + this->NEUPressure = parameters.getParameter< RealType >( prefix + "NEU-pressure" ); + this->NEUEnergy = Energy( NEUDensity, NEUPressure, gamma, NEUVelocity); + this->NEUMomentum = NEUVelocity * NEUDensity; + + this->SEUDensity = parameters.getParameter< RealType >( prefix + "SEU-density" ); + this->SEUVelocity.setup( parameters, prefix + "SEU-velocity-" ); + this->SEUPressure = parameters.getParameter< RealType >( prefix + "SEU-pressure" ); + this->SEUEnergy = Energy( SEUDensity, SEUPressure, gamma, SEUVelocity); + this->SEUMomentum = SEUVelocity * SEUDensity; + + this->NEDDensity = parameters.getParameter< RealType >( prefix + "NED-density" ); + this->NEDVelocity.setup(parameters, prefix + "NED-velocity-" ); + this->NEDPressure = parameters.getParameter< RealType >( prefix + "NED-pressure" ); + this->NEDEnergy = Energy( NEDDensity, NEDPressure, gamma, NEDVelocity); + this->NEDMomentum = NEDVelocity * NEDDensity; + + this->SEDDensity = parameters.getParameter< RealType >( prefix + "SED-density" ); + this->SEDVelocity.setup( parameters, prefix + "SED-velocity-" ); + this->SEDPressure = parameters.getParameter< RealType >( prefix + "SED-pressure" ); + this->SEDEnergy = Energy( SEDDensity, SEDPressure, gamma, SEDVelocity); + this->SEDMomentum = SEDVelocity * SEDDensity; + + } + if(initial == prefix + "1D_2") + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 0.4, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + -2.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 2.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_3a") + predefinedInitialCondition( 1.4, 0.8, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 1000.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 0.01, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + -19.59745, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + -19.57945, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_4") + predefinedInitialCondition( 1.666, 0.4, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 5.99924, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 5.99242, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 460.894, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 46.095, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 19.5975, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + -6.19633, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_5") + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 1.4, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_6") + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 1.4, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 0.1, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 0.1, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 1.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_Noh") + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 0.000001, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 0.000001, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 1.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + -1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_peak") + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 0.12612, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 6.5915, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 782.929, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 3.15449, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 8.90470, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 2.26542, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_3") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.5323, 0.138, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.5, 0.5323, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.3, 0.029, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.5, 0.3, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 1.206, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 1.206, 1.206, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 1.206, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_4") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.5065, 1.1, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.1, 0.5065, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.35, 1.1, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.1, 0.35, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.8939, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.8939, 0.8939, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 0.8939, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + + if(initial == prefix + "2D_6") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 2.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.0, 3.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 1.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.0, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.75, 0.5, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + -0.75, 0.5, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.75, -0.5, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + -0.75, -0.5, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_12") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 1.0, 0.8, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.5313, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 1.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.4, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.7276, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 0.7276, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + + if(initial == prefix + "2D_15") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.5197, 0.8, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.0, 0.5313, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.4, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.0, 0.4, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + -0.6259, -0.3, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.1, -0.3, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.1, -0.3, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.1, 0.4276, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_17") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 2.0, 1.0625, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.0, 0.5197, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 1.0, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.0, 0.4, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, -0.3, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.0, 0.2145, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, -0.4, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 1.1259, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + return true; + } + + void setDiscontinuityPlacement( const PointType& v ) + { + this->discontinuityPlacement = v; + } + + const PointType& getDiscontinuityPlasement() const + { + return this->discontinuityPlacement; + } + + void setLeftDensity( const RealType& leftDensity ) + { + this->leftDensity = leftDensity; + } + + const RealType& getLeftDensity() const + { + return this->leftDensity; + } + + void setRightDensity( const RealType& rightDensity ) + { + this->rightDensity = rightDensity; + } + + const RealType& getRightDensity() const + { + return this->rightDensity; + } + + void setLeftVelocity( const PointType& leftVelocity ) + { + this->leftVelocity = leftVelocity; + } + + const PointType& getLeftVelocity() const + { + return this->leftVelocity; + } + + void setRightVelocity( const RealType& rightVelocity ) + { + this->rightVelocity = rightVelocity; + } + + const PointType& getRightVelocity() const + { + return this->rightVelocity; + } + + void setLeftPressure( const RealType& leftPressure ) + { + this->leftPressure = leftPressure; + } + + const RealType& getLeftPressure() const + { + return this->leftPressure; + } + + void setRightPressure( const RealType& rightPressure ) + { + this->rightPressure = rightPressure; + } + + const RealType& getRightPressure() const + { + return this->rightPressure; + } + + + void predefinedInitialCondition( double preGamma, double preDiscX, double preDiscY, double preDiscZ, + double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ) + + { + this->discontinuityPlacement = PointLoad(preDiscX, preDiscY, preDiscZ); + this->gamma = preGamma; + + this->NWUDensity = preNWUDensity; + this->NWUVelocity = PointLoad(preNWUVelocityX, preNWUVelocityY, preNWUVelocityZ); + this->NWUPressure = preNWUPressure; + this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); + this->NWUMomentum = NWUVelocity * NWUDensity; + + this->SWUDensity = preNWUDensity; + this->SWUVelocity = PointLoad(preSWUVelocityX, preSWUVelocityY, preSWUVelocityZ); + this->SWUPressure = preSWUPressure; + this->SWUEnergy = Energy( SWUDensity, SWUPressure, gamma, SWUVelocity); + this->SWUMomentum = SWUVelocity * SWUDensity; + + this->NWDDensity = preNWDDensity; + this->NWDVelocity = PointLoad(preNWDVelocityX, preNWDVelocityY, preNWDVelocityZ); + this->NWDPressure = preNWDPressure; + this->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); + this->NWDMomentum = NWDVelocity * NWDDensity; + + this->SWDDensity = preSWDDensity; + this->SWDVelocity = PointLoad(preSWDVelocityX, preSWDVelocityY, preSWDVelocityZ); + this->SWDPressure = preSWDPressure; + this->SWDEnergy = Energy( SWDDensity, SWDPressure, gamma, SWDVelocity); + this->SWDMomentum = SWDVelocity * SWDDensity; + + this->NEUDensity = preNEUDensity; + this->NEUVelocity = PointLoad(preNEUVelocityX, preNEUVelocityY, preNEUVelocityZ); + this->NEUPressure = preNEUPressure; + this->NEUEnergy = Energy( NEUDensity, NEUPressure, gamma, NEUVelocity); + this->NEUMomentum = NEUVelocity * NEUDensity; + + this->SEUDensity = preSEUDensity; + this->SEUVelocity = PointLoad(preSEUVelocityX, preSEUVelocityY, preSEUVelocityZ); + this->SEUPressure = preSEUPressure; + this->SEUEnergy = Energy( SEUDensity, SEUPressure, gamma, SEUVelocity); + this->SEUMomentum = SEUVelocity * SEUDensity; + + this->NEDDensity = preNEDDensity; + this->NEDVelocity = PointLoad(preNEDVelocityX, preNEDVelocityY, preNEDVelocityZ); + this->NEDPressure = preNEDPressure; + this->NEDEnergy = Energy( NEDDensity, NEDPressure, gamma, NEDVelocity); + this->NEDMomentum = NEDVelocity * NEDDensity; + + this->SEDDensity = preSEDDensity; + this->SEDVelocity = PointLoad(preSEDVelocityX, preSEDVelocityY, preSEDVelocityZ); + this->SEDPressure = preSEDPressure; + this->SEDEnergy = Energy( SEDDensity, SEDPressure, gamma, SEDVelocity); + this->SEDMomentum = SEDVelocity * SEDDensity; + + std::cout << this->SEDEnergy; + std::cout << this->SWDEnergy; + + } + + PointType PointLoad( RealType ValueX, RealType ValueY, RealType ValueZ) + { + PointType point; + switch (Dimensions) + { + case 1: point[ 0 ] = ValueX; + break; + case 2: point[ 0 ] = ValueX; + point[ 1 ] = ValueY; + break; + case 3: point[ 0 ] = ValueX; + point[ 1 ] = ValueY; + point[ 2 ] = ValueZ; + break; + } + return point; + } + + RealType Energy( RealType Density, RealType Pressure, RealType gamma, PointType Velocity) + { + RealType energy; + switch (Dimensions) + { + case 1: energy = (Pressure / (gamma -1.0) + 0.5 * Density * (std::pow(Velocity[ 0 ], 2 ))); + break; + case 2: energy = (Pressure / (gamma -1.0) + 0.5 * Density * (std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ))); + break; + case 3: energy = (Pressure / (gamma -1.0) + 0.5 * Density * (std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 3 ], 2 ))); + break; // druhou mocninu ps8t jako sou4in + } + return energy; + } + + void setInitialCondition( CompressibleConservativeVariables< MeshType >& conservativeVariables, + const PointType& center = PointType( 0.0 ) ) + { + RiemannProblemInitialConditionSetter<MeshType>* variablesSetter = new RiemannProblemInitialConditionSetter<MeshType>; + variablesSetter->setGamma(this->gamma); + variablesSetter->setDensity(this->NWUDensity, + this->NEUDensity, + this->SWUDensity, + this->SEUDensity, + this->NWDDensity, + this->NEDDensity, + this->SWDDensity, + this->SEDDensity); + variablesSetter->setMomentum(this->NWUMomentum, + this->NEUMomentum, + this->SWUMomentum, + this->SEUMomentum, + this->NWDMomentum, + this->NEDMomentum, + this->SWDMomentum, + this->SEDMomentum); + variablesSetter->setEnergy(this->NWUEnergy, + this->NEUEnergy, + this->SWUEnergy, + this->SEUEnergy, + this->NWDEnergy, + this->NEDEnergy, + this->SWDEnergy, + this->SEDEnergy); + variablesSetter->setDiscontinuity(this->discontinuityPlacement); + variablesSetter->placeDensity(conservativeVariables); + variablesSetter->placeMomentum(conservativeVariables); + variablesSetter->placeEnergy(conservativeVariables); + +// for cyklus i = 0 to mesh.getDimensions().x() j pro .y() a k pro .z() +// typedef typename MeshType::Cell CellType +// typedef typename MeshType::CoordinatesType CoordinatesType +// Celltype cell(mesh, CoordinatesType(i,j)) +// p59stup do density setElement(mesh.template getEntityIndex< CellType >(cell), hodnota, kterou budu zapisovat) +// pomocn8 t59da, kterou budu specialiyovat p5es r;zn0 dimenze gridu + +/* + typedef Functions::Analytic::VectorNorm< Dimensions, RealType > VectorNormType; + typedef Operators::Analytic::Sign< Dimensions, RealType > SignType; + typedef Functions::OperatorFunction< SignType, VectorNormType > InitialConditionType; + typedef SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; + + InitialConditionPointer initialCondition; + initialCondition->getFunction().setCenter( center ); + initialCondition->getFunction().setMaxNorm( true ); + initialCondition->getFunction().setRadius( discontinuityPlacement[ 0 ] ); + discontinuityPlacement *= 1.0 / discontinuityPlacement[ 0 ]; + for( int i = 1; i < Dimensions; i++ ) + discontinuityPlacement[ i ] = 1.0 / discontinuityPlacement[ i ]; + initialCondition->getFunction().setAnisotropy( discontinuityPlacement ); + initialCondition->getFunction().setMultiplicator( -1.0 ); + + Functions::MeshFunctionEvaluator< MeshFunctionType, InitialConditionType > evaluator; +*/ + /**** + * Density + */ +/* + conservativeVariables.getDensity()->write( "density.gplt", "gnuplot" ); +*/ +/* + initialCondition->getOperator().setPositiveValue( leftDensity ); + initialCondition->getOperator().setNegativeValue( rightDensity ); + evaluator.evaluate( conservativeVariables.getDensity(), initialCondition ); + conservativeVariables.getDensity()->write( "density.gplt", "gnuplot" ); +*/ + /**** + * Momentum + */ + +/* + for( int i = 0; i < Dimensions; i++ ) + { + initialCondition->getOperator().setPositiveValue( leftDensity * leftVelocity[ i ] ); + initialCondition->getOperator().setNegativeValue( rightDensity * rightVelocity[ i ] ); + evaluator.evaluate( conservativeVariables.getMomentum()[ i ], initialCondition ); + } +*/ + /**** + * Energy + */ +/* + conservativeVariables.getEnergy()->write( "energy-init", "gnuplot" ); +*/ +/* + const RealType leftKineticEnergy = leftVelocity.lpNorm( 2.0 ); + const RealType rightKineticEnergy = rightVelocity.lpNorm( 2.0 ); + const RealType leftEnergy = leftPressure / ( gamma - 1.0 ) + 0.5 * leftDensity * leftKineticEnergy * leftKineticEnergy; + const RealType rightEnergy = rightPressure / ( gamma - 1.0 ) + 0.5 * rightDensity * rightKineticEnergy * rightKineticEnergy; + initialCondition->getOperator().setPositiveValue( leftEnergy ); + initialCondition->getOperator().setNegativeValue( rightEnergy ); + evaluator.evaluate( (* conservativeVariables.getEnergy()), initialCondition ); + (* conservativeVariables.getEnergy())->write( "energy-init", "gnuplot" ); +*/ + } + + + protected: + + PointType discontinuityPlacement; + PointType NWUVelocity, NEUVelocity, SWUVelocity, SEUVelocity, NWDVelocity, NEDVelocity, SWDVelocity, SEDVelocity; + RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; + RealType NWUPressure, NEUPressure, SWUPressure, SEUPressure, NWDPressure, NEDPressure, SWDPressure, SEDPressure; + RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; + RealType leftDensity, rightDensity; + PointType leftVelocity, rightVelocity; + RealType leftPressure, rightPressure; + + RealType gamma; // gamma in the ideal gas state equation +}; + +} //namespace TNL diff --git a/examples/flow/navierStokes.cpp b/examples/flow/navierStokes.cpp new file mode 100644 index 0000000000..7dffcb059f --- /dev/null +++ b/examples/flow/navierStokes.cpp @@ -0,0 +1 @@ +#include "navierStokes.h" diff --git a/examples/flow/navierStokes.cu b/examples/flow/navierStokes.cu new file mode 100644 index 0000000000..7dffcb059f --- /dev/null +++ b/examples/flow/navierStokes.cu @@ -0,0 +1 @@ +#include "navierStokes.h" diff --git a/examples/flow/navierStokes.h b/examples/flow/navierStokes.h new file mode 100644 index 0000000000..38a7affbee --- /dev/null +++ b/examples/flow/navierStokes.h @@ -0,0 +1,117 @@ +#include <TNL/tnlConfig.h> +#include <TNL/Solvers/Solver.h> +#include <TNL/Solvers/BuildConfigTags.h> +#include <TNL/Operators/DirichletBoundaryConditions.h> +#include <TNL/Operators/NeumannBoundaryConditions.h> +#include <TNL/Functions/Analytic/Constant.h> +#include "navierStokesProblem.h" +#include "LaxFridrichs.h" +#include "navierStokesRhs.h" +#include "navierStokesBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" + +using namespace TNL; + +typedef navierStokesBuildConfigTag BuildConfig; + +/**** + * Uncomment the following (and comment the previous line) for the complete build. + * This will include support for all floating point precisions, all indexing types + * and more solvers. You may then choose between them from the command line. + * The compile time may, however, take tens of minutes or even several hours, + * especially if CUDA is enabled. Use this, if you want, only for the final build, + * not in the development phase. + */ +//typedef tnlDefaultConfigTag BuildConfig; + +template< typename ConfigTag >class navierStokesConfig +{ + public: + static void configSetup( Config::ConfigDescription & config ) + { + config.addDelimiter( "Inviscid flow settings:" ); + config.addEntry< String >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter > +class navierStokesSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + typedef LaxFridrichs< MeshType, Real, Index > ApproximateOperator; + typedef navierStokesRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + + /**** + * Resolve the template arguments of your solver here. + * The following code is for the Dirichlet and the Neumann boundary conditions. + * Both can be constant or defined as descrete values of Vector. + */ + String boundaryConditionsType = parameters.getParameter< String >( "boundary-conditions-type" ); + if( parameters.checkParameter( "boundary-conditions-constant" ) ) + { + typedef Functions::Analytic::Constant< Dimension, Real > Constant; + if( boundaryConditionsType == "dirichlet" ) + { + typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Operators::NeumannBoundaryConditions< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef Operators::DirichletBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef Operators::NeumannBoundaryConditions< MeshType, MeshFunction, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< navierStokesSetter, navierStokesConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +} diff --git a/examples/flow/navierStokesBuildConfigTag.h b/examples/flow/navierStokesBuildConfigTag.h new file mode 100644 index 0000000000..f84233ade4 --- /dev/null +++ b/examples/flow/navierStokesBuildConfigTag.h @@ -0,0 +1,51 @@ +#ifndef navierStokesBUILDCONFIGTAG_H_ +#define navierStokesBUILDCONFIGTAG_H_ + +#include <TNL/Solvers/BuildConfigTags.h> + +namespace TNL { + +class navierStokesBuildConfigTag{}; + +namespace Solvers { + +/**** + * Turn off support for float and long double. + */ +template<> struct ConfigTagReal< navierStokesBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct ConfigTagReal< navierStokesBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct ConfigTagIndex< navierStokesBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct ConfigTagIndex< navierStokesBuildConfigTag, long int >{ enum { enabled = false }; }; + +//template< int Dimension > struct ConfigTagDimension< navierStokesBuildConfigTag, Dimension >{ enum { enabled = ( Dimension == 1 ) }; }; + +/**** + * Use of Grid is enabled for allowed dimensions and Real, Device and Index types. + */ +template< int Dimension, typename Real, typename Device, typename Index > + struct ConfigTagMesh< navierStokesBuildConfigTag, Meshes::Grid< Dimension, Real, Device, Index > > + { enum { enabled = ConfigTagDimension< navierStokesBuildConfigTag, Dimension >::enabled && + ConfigTagReal< navierStokesBuildConfigTag, Real >::enabled && + ConfigTagDevice< navierStokesBuildConfigTag, Device >::enabled && + ConfigTagIndex< navierStokesBuildConfigTag, Index >::enabled }; }; + +/**** + * Please, chose your preferred time discretisation here. + */ +template<> struct ConfigTagTimeDiscretisation< navierStokesBuildConfigTag, ExplicitTimeDiscretisationTag >{ enum { enabled = true }; }; +template<> struct ConfigTagTimeDiscretisation< navierStokesBuildConfigTag, SemiImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; +template<> struct ConfigTagTimeDiscretisation< navierStokesBuildConfigTag, ImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; + +/**** + * Only the Runge-Kutta-Merson solver is enabled by default. + */ +template<> struct ConfigTagExplicitSolver< navierStokesBuildConfigTag, ExplicitEulerSolverTag >{ enum { enabled = true }; }; + +} // namespace Solvers +} // namespace TNL + +#endif /* navierStokesBUILDCONFIGTAG_H_ */ diff --git a/examples/flow/navierStokesProblem.h b/examples/flow/navierStokesProblem.h new file mode 100644 index 0000000000..d587ffef8f --- /dev/null +++ b/examples/flow/navierStokesProblem.h @@ -0,0 +1,130 @@ +/*************************************************************************** + navierStokesProblem.h - description + ------------------- + begin : Feb 13, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Problems/PDEProblem.h> +#include <TNL/Functions/MeshFunction.h> +#include "CompressibleConservativeVariables.h" + + +using namespace TNL::Problems; + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +class navierStokesProblem: + public PDEProblem< Mesh, + typename InviscidOperators::RealType, + typename Mesh::DeviceType, + typename InviscidOperators::IndexType > +{ + public: + + typedef typename InviscidOperators::RealType RealType; + typedef typename Mesh::DeviceType DeviceType; + typedef typename InviscidOperators::IndexType IndexType; + typedef PDEProblem< Mesh, RealType, DeviceType, IndexType > BaseType; + + using typename BaseType::MeshType; + using typename BaseType::MeshPointer; + using typename BaseType::DofVectorType; + using typename BaseType::DofVectorPointer; + using typename BaseType::MeshDependentDataType; + using typename BaseType::MeshDependentDataPointer; + + static const int Dimensions = Mesh::getMeshDimension(); + + typedef Functions::MeshFunction< Mesh > MeshFunctionType; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + typedef SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef SharedPointer< InviscidOperators > InviscidOperatorsPointer; + typedef SharedPointer< BoundaryCondition > BoundaryConditionPointer; + typedef SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; + + static String getTypeStatic(); + + String getPrologHeader() const; + + void writeProlog( Logger& logger, + const Config::ParameterContainer& parameters ) const; + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ); + + bool setInitialCondition( const Config::ParameterContainer& parameters, + const MeshPointer& mesh, + DofVectorPointer& dofs, + MeshDependentDataPointer& meshDependentData ); + + template< typename Matrix > + bool setupLinearSystem( const MeshPointer& mesh, + Matrix& matrix ); + + bool makeSnapshot( const RealType& time, + const IndexType& step, + const MeshPointer& mesh, + DofVectorPointer& dofs, + MeshDependentDataPointer& meshDependentData ); + + IndexType getDofs( const MeshPointer& mesh ) const; + + void bindDofs( const MeshPointer& mesh, + DofVectorPointer& dofs ); + + void getExplicitUpdate( const RealType& time, + const RealType& tau, + const MeshPointer& mesh, + DofVectorPointer& _u, + DofVectorPointer& _fu, + MeshDependentDataPointer& meshDependentData ); + + template< typename Matrix > + void assemblyLinearSystem( const RealType& time, + const RealType& tau, + const MeshPointer& mesh, + DofVectorPointer& dofs, + Matrix& matrix, + DofVectorPointer& rightHandSide, + MeshDependentDataPointer& meshDependentData ); + + bool postIterate( const RealType& time, + const RealType& tau, + const MeshPointer& mesh, + DofVectorPointer& dofs, + MeshDependentDataPointer& meshDependentData ); + + protected: + + InviscidOperatorsPointer inviscidOperatorsPointer; + + BoundaryConditionPointer boundaryConditionPointer; + RightHandSidePointer rightHandSidePointer; + + ConservativeVariablesPointer conservativeVariables, + conservativeVariablesRHS; + + VelocityFieldPointer velocity; + MeshFunctionPointer pressure; + + RealType gamma; +}; + +} // namespace TNL + +#include "navierStokesProblem_impl.h" + diff --git a/examples/flow/navierStokesProblem_impl.h b/examples/flow/navierStokesProblem_impl.h new file mode 100644 index 0000000000..478b4b206c --- /dev/null +++ b/examples/flow/navierStokesProblem_impl.h @@ -0,0 +1,416 @@ +/*************************************************************************** + navierStokesProblem_impl.h - description + ------------------- + begin : Feb 13, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/FileName.h> +#include <TNL/Matrices/MatrixSetter.h> +#include <TNL/Solvers/PDE/ExplicitUpdater.h> +#include <TNL/Solvers/PDE/LinearSystemAssembler.h> +#include <TNL/Solvers/PDE/BackwardTimeDiscretisation.h> +#include <TNL/Functions/Analytic/VectorNorm.h> + +#include "RiemannProblemInitialCondition.h" +#include "CompressibleConservativeVariables.h" +#include "PhysicalVariablesGetter.h" +#include "navierStokesProblem.h" + +#include "LaxFridrichsContinuity.h" +#include "LaxFridrichsEnergy.h" +#include "LaxFridrichsMomentumX.h" +#include "LaxFridrichsMomentumY.h" +#include "LaxFridrichsMomentumZ.h" + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +String +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +getTypeStatic() +{ + return String( "navierStokesProblem< " ) + Mesh :: getTypeStatic() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +String +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +getPrologHeader() const +{ + return String( "Inviscid flow solver" ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +void +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +writeProlog( Logger& logger, const Config::ParameterContainer& parameters ) const +{ + /**** + * Add data you want to have in the computation report (log) as follows: + * logger.writeParameter< double >( "Parameter description", parameter ); + */ +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +bool +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix ) +{ + if( ! this->inviscidOperatorsPointer->setup( meshPointer, parameters, prefix + "inviscid-operators-" ) || + ! this->boundaryConditionPointer->setup( meshPointer, parameters, prefix + "boundary-conditions-" ) || + ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) + return false; + this->gamma = parameters.getParameter< double >( "gamma" ); + velocity->setMesh( meshPointer ); + pressure->setMesh( meshPointer ); + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +typename navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >::IndexType +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +getDofs( const MeshPointer& mesh ) const +{ + /**** + * Return number of DOFs (degrees of freedom) i.e. number + * of unknowns to be resolved by the main solver. + */ + return this->conservativeVariables->getDofs( mesh ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +void +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +bindDofs( const MeshPointer& mesh, + DofVectorPointer& dofVector ) +{ + this->conservativeVariables->bind( mesh, dofVector ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +bool +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +setInitialCondition( const Config::ParameterContainer& parameters, + const MeshPointer& mesh, + DofVectorPointer& dofs, + MeshDependentDataPointer& meshDependentData ) +{ + CompressibleConservativeVariables< MeshType > conservativeVariables; + conservativeVariables.bind( mesh, dofs ); + const String& initialConditionType = parameters.getParameter< String >( "initial-condition" ); + if( initialConditionType == "riemann-problem" ) + { + RiemannProblemInitialCondition< MeshType > initialCondition; + if( ! initialCondition.setup( parameters ) ) + return false; + initialCondition.setInitialCondition( conservativeVariables ); + return true; + } + std::cerr << "Unknown initial condition " << initialConditionType << std::endl; + return false; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > + template< typename Matrix > +bool +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +setupLinearSystem( const MeshPointer& mesh, + Matrix& matrix ) +{ +/* const IndexType dofs = this->getDofs( mesh ); + typedef typename Matrix::CompressedRowLengthsVector CompressedRowLengthsVectorType; + CompressedRowLengthsVectorType rowLengths; + if( ! rowLengths.setSize( dofs ) ) + return false; + MatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, CompressedRowLengthsVectorType > matrixSetter; + matrixSetter.template getCompressedRowLengths< typename Mesh::Cell >( mesh, + differentialOperator, + boundaryCondition, + rowLengths ); + matrix.setDimensions( dofs, dofs ); + if( ! matrix.setCompressedRowLengths( rowLengths ) ) + return false;*/ + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +bool +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +makeSnapshot( const RealType& time, + const IndexType& step, + const MeshPointer& mesh, + DofVectorPointer& dofs, + MeshDependentDataPointer& meshDependentData ) +{ + std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; + + this->bindDofs( mesh, dofs ); + PhysicalVariablesGetter< MeshType > physicalVariablesGetter; + physicalVariablesGetter.getVelocity( this->conservativeVariables, this->velocity ); + physicalVariablesGetter.getPressure( this->conservativeVariables, this->gamma, this->pressure ); + + FileName fileName; + fileName.setExtension( "tnl" ); + fileName.setIndex( step ); + fileName.setFileNameBase( "density-" ); + if( ! this->conservativeVariables->getDensity()->save( fileName.getFileName() ) ) + return false; + + fileName.setFileNameBase( "velocity-" ); + if( ! this->velocity->save( fileName.getFileName() ) ) + return false; + + fileName.setFileNameBase( "pressure-" ); + if( ! this->pressure->save( fileName.getFileName() ) ) + return false; + + fileName.setFileNameBase( "energy-" ); + if( ! this->conservativeVariables->getEnergy()->save( fileName.getFileName() ) ) + return false; + + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +void +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +getExplicitUpdate( const RealType& time, + const RealType& tau, + const MeshPointer& mesh, + DofVectorPointer& _u, + DofVectorPointer& _fu, + MeshDependentDataPointer& meshDependentData ) +{ + typedef typename MeshType::Cell Cell; + + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( mesh, _u ); + this->conservativeVariablesRHS->bind( mesh, _fu ); + this->velocity->setMesh( mesh ); + this->pressure->setMesh( mesh ); + + /**** + * Resolve the physical variables + */ + PhysicalVariablesGetter< typename MeshPointer::ObjectType > physicalVariables; + physicalVariables.getVelocity( this->conservativeVariables, this->velocity ); + physicalVariables.getPressure( this->conservativeVariables, this->gamma, this->pressure ); + + /**** + * Set-up operators + */ + typedef typename InviscidOperators::ContinuityOperatorType ContinuityOperatorType; + typedef typename InviscidOperators::MomentumXOperatorType MomentumXOperatorType; + typedef typename InviscidOperators::MomentumYOperatorType MomentumYOperatorType; + typedef typename InviscidOperators::MomentumZOperatorType MomentumZOperatorType; + typedef typename InviscidOperators::EnergyOperatorType EnergyOperatorType; + + this->inviscidOperatorsPointer->setTau( tau ); + this->inviscidOperatorsPointer->setVelocity( this->velocity ); + this->inviscidOperatorsPointer->setPressure( this->pressure ); + + /**** + * Continuity equation + */ + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, ContinuityOperatorType, BoundaryCondition, RightHandSide > explicitUpdaterContinuity; + explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); + explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer ); + explicitUpdaterContinuity.setRightHandSide( this->rightHandSidePointer ); + explicitUpdaterContinuity.template update< typename Mesh::Cell >( time, tau, mesh, + this->conservativeVariables->getDensity(), + this->conservativeVariablesRHS->getDensity() ); + + /**** + * Momentum equations + */ + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumXOperatorType, BoundaryCondition, RightHandSide > explicitUpdaterMomentumX; + explicitUpdaterMomentumX.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumXOperator() ); + explicitUpdaterMomentumX.setBoundaryConditions( this->boundaryConditionPointer ); + explicitUpdaterMomentumX.setRightHandSide( this->rightHandSidePointer ); + explicitUpdaterMomentumX.template update< typename Mesh::Cell >( time, tau, mesh, + ( *this->conservativeVariables->getMomentum() )[ 0 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 0 ] ); //, fuRhoVelocityX ); + + if( Dimensions > 1 ) + { + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumYOperatorType, BoundaryCondition, RightHandSide > explicitUpdaterMomentumY; + explicitUpdaterMomentumY.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumYOperator() ); + explicitUpdaterMomentumY.setBoundaryConditions( this->boundaryConditionPointer ); + explicitUpdaterMomentumY.setRightHandSide( this->rightHandSidePointer ); + explicitUpdaterMomentumY.template update< typename Mesh::Cell >( time, tau, mesh, + ( *this->conservativeVariables->getMomentum() )[ 1 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 1 ] ); //, fuRhoVelocityX ); + } + + if( Dimensions > 2 ) + { + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumZOperatorType, BoundaryCondition, RightHandSide > explicitUpdaterMomentumZ; + explicitUpdaterMomentumZ.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumZOperator() ); + explicitUpdaterMomentumZ.setBoundaryConditions( this->boundaryConditionPointer ); + explicitUpdaterMomentumZ.setRightHandSide( this->rightHandSidePointer ); + explicitUpdaterMomentumZ.template update< typename Mesh::Cell >( time, tau, mesh, + ( *this->conservativeVariables->getMomentum() )[ 2 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 2 ] ); //, fuRhoVelocityX ); + } + + + /**** + * Energy equation + */ + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, EnergyOperatorType, BoundaryCondition, RightHandSide > explicitUpdaterEnergy; + explicitUpdaterEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getEnergyOperator() ); + explicitUpdaterEnergy.setBoundaryConditions( this->boundaryConditionPointer ); + explicitUpdaterEnergy.setRightHandSide( this->rightHandSidePointer ); + explicitUpdaterEnergy.template update< typename Mesh::Cell >( time, tau, mesh, + this->conservativeVariables->getEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); + + /*this->conservativeVariablesRHS->getDensity()->write( "density", "gnuplot" ); + this->conservativeVariablesRHS->getEnergy()->write( "energy", "gnuplot" ); + this->conservativeVariablesRHS->getMomentum()->write( "momentum", "gnuplot", 0.05 ); + getchar();*/ + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > + template< typename Matrix > +void +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +assemblyLinearSystem( const RealType& time, + const RealType& tau, + const MeshPointer& mesh, + DofVectorPointer& _u, + Matrix& matrix, + DofVectorPointer& b, + MeshDependentDataPointer& meshDependentData ) +{ +/* LinearSystemAssembler< Mesh, + MeshFunctionType, + InviscidOperators, + BoundaryCondition, + RightHandSide, + BackwardTimeDiscretisation, + Matrix, + DofVectorType > systemAssembler; + + MeshFunction< Mesh > u( mesh, _u ); + systemAssembler.template assembly< typename Mesh::Cell >( time, + tau, + mesh, + this->differentialOperator, + this->boundaryCondition, + this->rightHandSide, + u, + matrix, + b );*/ +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +bool +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +postIterate( const RealType& time, + const RealType& tau, + const MeshPointer& mesh, + DofVectorPointer& dofs, + MeshDependentDataPointer& meshDependentData ) +{ + /* + typedef typename MeshType::Cell Cell; + int count = mesh->template getEntitiesCount< Cell >()/4; + //bind _u + this->_uRho.bind( *dofs, 0, count); + this->_uRhoVelocityX.bind( *dofs, count, count); + this->_uRhoVelocityY.bind( *dofs, 2 * count, count); + this->_uEnergy.bind( *dofs, 3 * count, count); + + MeshFunctionType velocity( mesh, this->velocity ); + MeshFunctionType velocityX( mesh, this->velocityX ); + MeshFunctionType velocityY( mesh, this->velocityY ); + MeshFunctionType pressure( mesh, this->pressure ); + MeshFunctionType uRho( mesh, _uRho ); + MeshFunctionType uRhoVelocityX( mesh, _uRhoVelocityX ); + MeshFunctionType uRhoVelocityY( mesh, _uRhoVelocityY ); + MeshFunctionType uEnergy( mesh, _uEnergy ); + //Generating differential operators + Velocity navierStokes2DVelocity; + VelocityX navierStokes2DVelocityX; + VelocityY navierStokes2DVelocityY; + Pressure navierStokes2DPressure; + + //velocityX + navierStokes2DVelocityX.setRhoVelX(uRhoVelocityX); + navierStokes2DVelocityX.setRho(uRho); +// OperatorFunction< VelocityX, MeshFunction, void, true > OFVelocityX; +// velocityX = OFVelocityX; + + //velocityY + navierStokes2DVelocityY.setRhoVelY(uRhoVelocityY); + navierStokes2DVelocityY.setRho(uRho); +// OperatorFunction< VelocityY, MeshFunction, void, time > OFVelocityY; +// velocityY = OFVelocityY; + + //velocity + navierStokes2DVelocity.setVelX(velocityX); + navierStokes2DVelocity.setVelY(velocityY); +// OperatorFunction< Velocity, MeshFunction, void, time > OFVelocity; +// velocity = OFVelocity; + + //pressure + navierStokes2DPressure.setGamma(gamma); + navierStokes2DPressure.setVelocity(velocity); + navierStokes2DPressure.setEnergy(uEnergy); + navierStokes2DPressure.setRho(uRho); +// OperatorFunction< navierStokes2DPressure, MeshFunction, void, time > OFPressure; +// pressure = OFPressure; + */ + return true; +} + +} // namespace TNL + diff --git a/examples/flow/navierStokesRhs.h b/examples/flow/navierStokesRhs.h new file mode 100644 index 0000000000..3c82ad4539 --- /dev/null +++ b/examples/flow/navierStokesRhs.h @@ -0,0 +1,35 @@ +#ifndef navierStokesRHS_H_ +#define navierStokesRHS_H_ + +#include <TNL/Functions/Domain.h> + +namespace TNL { + +template< typename Mesh, typename Real >class navierStokesRhs + : public Functions::Domain< Mesh::getMeshDimension(), Functions::MeshDomain > + { + public: + + typedef Mesh MeshType; + typedef Real RealType; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return true; + } + + template< typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshEntity& entity, + const Real& time = 0.0 ) const + { + typedef typename MeshEntity::MeshType::PointType PointType; + PointType v = entity.getCenter(); + return 0.0; + } +}; + +} //namespace TNL + +#endif /* navierStokesRHS_H_ */ diff --git a/examples/flow/run-euler b/examples/flow/run-euler new file mode 100644 index 0000000000..9ebf9cbb55 --- /dev/null +++ b/examples/flow/run-euler @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +tnl-grid-setup --dimensions 2 \ + --origin-x 0.0 \ + --origin-y 0.0 \ + --proportions-x 1.0 \ + --proportions-y 1.0 \ + --size-x 100 \ + --size-y 100 + +tnl-init --test-function sin-wave \ + --output-file init.tnl +tnl-euler-2d --initial-condition riemann-problem \ + --discontinuity-placement-0 0.3 \ + --discontinuity-placement-1 0.3 \ + --discontinuity-placement-2 0.3 \ + --time-discretisation explicit \ + --boundary-conditions-type neumann \ + --boundary-conditions-constant 0 \ + --discrete-solver euler \ + --time-step 0.0001 \ + --snapshot-period 0.01 \ + --final-time 1.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/examples/inviscid-flow/LaxFridrichsContinuity.h b/examples/inviscid-flow/LaxFridrichsContinuity.h index 657230695a..c998087465 100644 --- a/examples/inviscid-flow/LaxFridrichsContinuity.h +++ b/examples/inviscid-flow/LaxFridrichsContinuity.h @@ -119,8 +119,11 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - return 1.0 / 2.0 * this->tau * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) - - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse; + } /*template< typename MeshEntity > @@ -185,8 +188,8 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - return 1.0 / 4.0 * this->tau * this->artificialViscosity * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * ( ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) + - 0.5 * ( ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse ); } @@ -258,9 +261,9 @@ class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Re const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - return 1.0 / 6.0 * this->tau * this->artificialViscosity * + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] + u[ up ] + u[ down ]- 6.0 * u[ center ] ) - - 0.5 * ( ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse + - 0.5 * ( ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse + ( u[ up ] * velocity_z_up - u[ down ] * velocity_z_down ) * hzInverse ); diff --git a/examples/inviscid-flow/LaxFridrichsEnergy.h b/examples/inviscid-flow/LaxFridrichsEnergy.h index d0af1de01d..3549e85f35 100644 --- a/examples/inviscid-flow/LaxFridrichsEnergy.h +++ b/examples/inviscid-flow/LaxFridrichsEnergy.h @@ -123,10 +123,10 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - return 1.0 / 2.0 * this->tau * this->artificialViscosity * ( e[ west ] - 2.0 * e[ center ] + e[ east ] ) - - 0.5 * ( ( e[ west ] + pressure_west ) * velocity_x_west - - ( e[ east ] + pressure_east ) * velocity_x_east ) * hxInverse; - + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( e[ west ] - 2.0 * e[ center ] + e[ east ] ) + - 0.5 * ( ( e[ east ] + pressure_east ) * velocity_x_east + - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse; + } /*template< typename MeshEntity > @@ -196,9 +196,9 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - return 1.0 / 4.0 * this->tau * this->artificialViscosity * ( e[ west ] + e[ east ] + e[ south ] + e[ north ] - 4.0 * e[ center ] ) - - 0.5 * ( ( ( ( e[ west ] + pressure_west ) * velocity_x_west ) - -( ( e[ east ] + pressure_east ) * velocity_x_east ) ) * hxInverse + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( e[ west ] + e[ east ] + e[ south ] + e[ north ] - 4.0 * e[ center ] ) + - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) + -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ); } @@ -278,10 +278,10 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - return 1.0 / 6.0 * this->tau * this->artificialViscosity * + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * ( e[ west ] + e[ east ] + e[ south ] + e[ north ] + e[ up ] + e[ down ] - 6.0 * e[ center ] ) - - 0.5 * ( ( ( ( e[ west ] + pressure_west ) * velocity_x_west ) - -( ( e[ east ] + pressure_east ) * velocity_x_east ) ) * hxInverse + - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) + -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse + ( ( ( e[ up ] + pressure_up ) * velocity_z_up ) diff --git a/examples/inviscid-flow/LaxFridrichsMomentumX.h b/examples/inviscid-flow/LaxFridrichsMomentumX.h index e054ad6ad2..63def12d31 100644 --- a/examples/inviscid-flow/LaxFridrichsMomentumX.h +++ b/examples/inviscid-flow/LaxFridrichsMomentumX.h @@ -75,9 +75,9 @@ class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - return 1.0 / 2.0 * this->tau * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] - 2.0 * rho_u[ center ] ) - - 0.5 * ( ( rho_u[ west ] * velocity_x_west + pressure_west ) - -( rho_u[ east ] * velocity_x_east + pressure_east ) ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] - 2.0 * rho_u[ center ] ) + - 0.5 * ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse; } /*template< typename MeshEntity > @@ -154,9 +154,9 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - return 1.0 / 4.0 * this->tau * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] - 4.0 * rho_u[ center ] ) - - 0.5 * ( ( ( rho_u[ west ] * velocity_x_west + pressure_west ) - - ( rho_u[ east ] * velocity_x_east + pressure_east ) ) * hxInverse + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] - 4.0 * rho_u[ center ] ) + - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + - ( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse + ( ( rho_u[ north ] * velocity_y_north ) - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ); } @@ -243,10 +243,10 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - return 1.0 / 6.0 * this->tau * this->artificialViscosity * + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] + rho_u[ up ] + rho_u[ down ] - 6.0 * rho_u[ center ] ) - - 0.5 * ( ( ( rho_u[ west ] * velocity_x_west + pressure_west ) - - ( rho_u[ east ] * velocity_x_east + pressure_east ) )* hxInverse + - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) + - ( rho_u[ west ] * velocity_x_west + pressure_west ) )* hxInverse + ( ( rho_u[ north ] * velocity_y_north ) - ( rho_u[ south ] * velocity_y_south ) )* hyInverse + ( ( rho_u[ up ] * velocity_z_up ) diff --git a/examples/inviscid-flow/LaxFridrichsMomentumY.h b/examples/inviscid-flow/LaxFridrichsMomentumY.h index ddf7b022c3..8ce42282dd 100644 --- a/examples/inviscid-flow/LaxFridrichsMomentumY.h +++ b/examples/inviscid-flow/LaxFridrichsMomentumY.h @@ -143,9 +143,9 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - return 1.0 / 4.0 * this->tau * this->artificialViscosity * ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] - 4.0 * rho_v[ center ] ) - - 0.5 * ( ( ( rho_v[ west ] * velocity_x_west ) - - ( rho_v[ east ] * velocity_x_east ) )* hxInverse + return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] - 4.0 * rho_v[ center ] ) + - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) + - ( rho_v[ west ] * velocity_x_west ) )* hxInverse + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ); } @@ -227,10 +227,10 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - return 1.0 / 6.0 * this->tau * this->artificialViscosity * + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] + rho_v[ up ] + rho_v[ down ] - 6.0 * rho_v[ center ] ) - - 0.5 * ( ( ( rho_v[ west ] * velocity_x_west ) - - ( rho_v[ east ] * velocity_x_east ) ) * hxInverse + - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) + - ( rho_v[ west ] * velocity_x_west ) ) * hxInverse + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) - ( rho_v[ south ] * velocity_y_south + pressure_south ) ) * hyInverse + ( ( rho_v[ up ] * velocity_z_up ) diff --git a/examples/inviscid-flow/LaxFridrichsMomentumZ.h b/examples/inviscid-flow/LaxFridrichsMomentumZ.h index 7f9213c4d5..a67e862cef 100644 --- a/examples/inviscid-flow/LaxFridrichsMomentumZ.h +++ b/examples/inviscid-flow/LaxFridrichsMomentumZ.h @@ -207,10 +207,10 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - return 1.0 / 6.0 * this->tau * this->artificialViscosity * + return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * ( rho_w[ west ] + rho_w[ east ] + rho_w[ south ] + rho_w[ north ] + rho_w[ up ] + rho_w[ down ] - 6.0 * rho_w[ center ] ) - -0.5 * ( ( ( rho_w[ west ] * velocity_x_west ) - - ( rho_w[ east ] * velocity_x_east ) )* hxInverse + -0.5 * ( ( ( rho_w[ east ] * velocity_x_east ) + - ( rho_w[ west ] * velocity_x_west ) )* hxInverse + ( ( rho_w[ north ] * velocity_y_north ) - ( rho_w[ south ] * velocity_y_south ) )* hyInverse + ( ( rho_w[ up ] * velocity_z_up + pressure_up ) diff --git a/examples/inviscid-flow/RiemannProblemInitialCondition.h b/examples/inviscid-flow/RiemannProblemInitialCondition.h index 493df84ce9..664d93ea32 100644 --- a/examples/inviscid-flow/RiemannProblemInitialCondition.h +++ b/examples/inviscid-flow/RiemannProblemInitialCondition.h @@ -121,14 +121,15 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, Me for( int i = 0; i < mesh.getDimensions().x(); i++) if ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) { - std::cout<<i; CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SWDDensity); } else { CellType cell(mesh, CoordinatesType(i)); -// (* conservativeVariables.getDensity()).setValue(cell, this->SEDDensity); + cell.refresh(); + (* conservativeVariables.getDensity()).setValue(cell, this->SEDDensity); } }; @@ -141,12 +142,14 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, Me if ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) { CellType cell(mesh, CoordinatesType(i)); -// (* conservativeVariables.getMomentum()).setValue(cell, this->SWDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWDMomentum[ 0 ]); } else { CellType cell(mesh, CoordinatesType(i)); -// (* conservativeVariables.getMomentum()).setValue(cell, this->SEDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEDMomentum[ 0 ]); } }; @@ -159,12 +162,14 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, Me if ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) { CellType cell(mesh, CoordinatesType(i)); -// (* conservativeVariables.getEnergy()).setValue(cell, this->SWDEnergy); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SWDEnergy); } else { CellType cell(mesh, CoordinatesType(i)); -// (* conservativeVariables.getEnergy()).setValue(cell, this->SEDEnergy); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SEDEnergy); } }; @@ -276,6 +281,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SWDDensity); } else @@ -283,6 +289,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SEDDensity); } else @@ -290,6 +297,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->NWDDensity); } else @@ -297,6 +305,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->NEDDensity); } }; @@ -312,28 +321,36 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->SWDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWDMomentum[ 1 ]); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->SEDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEDMomentum[ 1 ]); } else if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->NWDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NWDMomentum[ 1 ]); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->NEDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NEDMomentum[ 1 ]); } }; @@ -348,28 +365,32 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->SWDEnergy); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SWDEnergy); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) && ( j <= this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->SEDEnergy); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->SEDEnergy); } else if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->NWDEnergy); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->NWDEnergy); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) && ( j > this->discontinuityPlacement[ 1 ] * mesh.getDimensions().y() ) ) { CellType cell(mesh, CoordinatesType(i,j)); - (* conservativeVariables.getDensity()).setValue(cell, this->NEDEnergy); + cell.refresh(); + (* conservativeVariables.getEnergy()).setValue(cell, this->NEDEnergy); } }; @@ -482,6 +503,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SWDDensity); } else @@ -490,6 +512,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SEDDensity); } else @@ -498,6 +521,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->NWDDensity); } else @@ -506,6 +530,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->NEDDensity); } else @@ -514,6 +539,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SWUDensity); } else @@ -522,6 +548,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SEUDensity); } else @@ -530,6 +557,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SWUDensity); } else @@ -538,6 +566,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getDensity()).setValue(cell, this->SEUDensity); } }; @@ -555,7 +584,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->SWDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SWDMomentum[ 2 ]); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) @@ -563,7 +595,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->SEDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SEDMomentum[ 2 ]); } else if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) @@ -571,7 +606,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->NWDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NWDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NWDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->NWDMomentum[ 2 ]); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) @@ -579,7 +617,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->NEDMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->NEDMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->NEDMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->NEDMomentum[ 2 ]); } else if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) @@ -587,7 +628,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->SWUMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SWUMomentum[ 2 ]); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) @@ -595,7 +639,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->SEUMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SEUMomentum[ 2 ]); } else if ( ( i <= this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) @@ -603,7 +650,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->SWUMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SWUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SWUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SWUMomentum[ 2 ]); } else if ( ( i > this->discontinuityPlacement[ 0 ] * mesh.getDimensions().x() ) @@ -611,7 +661,10 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); - (* conservativeVariables.getMomentum()).setValue(cell, this->SEUMomentum); + cell.refresh(); + (* (* conservativeVariables.getMomentum())[ 0 ]).setValue(cell, this->SEUMomentum[ 0 ]); + (* (* conservativeVariables.getMomentum())[ 1 ]).setValue(cell, this->SEUMomentum[ 1 ]); + (* (* conservativeVariables.getMomentum())[ 2 ]).setValue(cell, this->SEUMomentum[ 2 ]); } }; @@ -628,6 +681,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->SWDEnergy); } else @@ -636,6 +690,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->SEDEnergy); } else @@ -644,6 +699,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->NWDEnergy); } else @@ -652,6 +708,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k <= this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->NEDEnergy); } else @@ -660,6 +717,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->SWUEnergy); } else @@ -668,6 +726,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->SEUEnergy); } else @@ -676,6 +735,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->SWUEnergy); } else @@ -684,6 +744,7 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M && ( k > this->discontinuityPlacement[ 2 ] * mesh.getDimensions().z() ) ) { CellType cell(mesh, CoordinatesType(i,j,k)); + cell.refresh(); (* conservativeVariables.getEnergy()).setValue(cell, this->SEUEnergy); } }; @@ -775,7 +836,7 @@ class RiemannProblemInitialCondition config.addEntry< double >( prefix + "SED-velocity-1", "This sets a value of southeast down y velocity.", 1.0 ); config.addEntry< double >( prefix + "SED-velocity-2", "This sets a value of southeast down z velocity.", 1.0 ); config.addEntry< double >( prefix + "SED-pressure", "This sets a value of southeast down pressure.", 1.0 ); - config.addEntry< double >( prefix + "gamma", "Gamma in the ideal gas state equation.", 1.67 ); + config.addEntry< double >( prefix + "gamma", "Gamma in the ideal gas state equation.", 1.4 ); config.addEntry< String >( prefix + "initial", " One of predefined initial condition.", "none"); config.addEntryEnum< String >( "none" ); @@ -786,6 +847,12 @@ class RiemannProblemInitialCondition config.addEntryEnum< String >( "1D_6" ); config.addEntryEnum< String >( "1D_Noh" ); config.addEntryEnum< String >( "1D_peak" ); + config.addEntryEnum< String >( "2D_3" ); + config.addEntryEnum< String >( "2D_4" ); + config.addEntryEnum< String >( "2D_6" ); + config.addEntryEnum< String >( "2D_12" ); + config.addEntryEnum< String >( "2D_15" ); + config.addEntryEnum< String >( "2D_17" ); } bool setup( const Config::ParameterContainer& parameters, @@ -855,7 +922,7 @@ class RiemannProblemInitialCondition } if(initial == prefix + "1D_2") - predefinedInitialCondition( 1.666, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, 0.0, 0.0, 0.0, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, @@ -870,7 +937,7 @@ class RiemannProblemInitialCondition 2.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_3a") - predefinedInitialCondition( 1.666, 0.8, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + predefinedInitialCondition( 1.4, 0.8, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, 0.0, 0.0, 0.0, 1000.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, @@ -882,7 +949,7 @@ class RiemannProblemInitialCondition 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - -1.57945, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + -19.57945, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_4") predefinedInitialCondition( 1.666, 0.4, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, @@ -900,7 +967,7 @@ class RiemannProblemInitialCondition -6.19633, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_5") - predefinedInitialCondition( 1.666, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, 0.0, 0.0, 0.0, 1.4, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, 0.0, 0.0, 0.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, @@ -915,7 +982,7 @@ class RiemannProblemInitialCondition 0.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_6") - predefinedInitialCondition( 1.666, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, 0.0, 0.0, 0.0, 1.4, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, 0.0, 0.0, 0.0, 0.1, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, @@ -930,7 +997,7 @@ class RiemannProblemInitialCondition 1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_Noh") - predefinedInitialCondition( 1.666, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, 0.0, 0.0, 0.0, 0.000001, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, @@ -945,7 +1012,7 @@ class RiemannProblemInitialCondition -1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_peak") - predefinedInitialCondition( 1.666, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, 0.0, 0.0, 0.0, 0.12612, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, 0.0, 0.0, 0.0, 6.5915, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, 0.0, 0.0, 0.0, 782.929, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, @@ -1141,77 +1208,80 @@ class RiemannProblemInitialCondition ) { - this->discontinuityPlacement[ 0 ] = preDiscX; - this->discontinuityPlacement[ 1 ] = preDiscY; - this->discontinuityPlacement[ 2 ] = preDiscZ; + this->discontinuityPlacement = PointLoad(preDiscX, preDiscY, preDiscZ); this->gamma = preGamma; this->NWUDensity = preNWUDensity; - this->NWUVelocity[ 0 ] = preNWUVelocityX; - this->NWUVelocity[ 1 ] = preNWUVelocityY; - this->NWUVelocity[ 2 ] = preNWUVelocityZ; + this->NWUVelocity = PointLoad(preNWUVelocityX, preNWUVelocityY, preNWUVelocityZ); this->NWUPressure = preNWUPressure; this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); this->NWUMomentum = NWUVelocity * NWUDensity; this->SWUDensity = preNWUDensity; - this->SWUVelocity[ 0 ] = preSWUVelocityX; - this->SWUVelocity[ 1 ] = preSWUVelocityY; - this->SWUVelocity[ 2 ] = preSWUVelocityZ; + this->SWUVelocity = PointLoad(preSWUVelocityX, preSWUVelocityY, preSWUVelocityZ); this->SWUPressure = preSWUPressure; this->SWUEnergy = Energy( SWUDensity, SWUPressure, gamma, SWUVelocity); this->SWUMomentum = SWUVelocity * SWUDensity; this->NWDDensity = preNWDDensity; - this->NWDVelocity[ 0 ] = preNWDVelocityX; - this->NWDVelocity[ 1 ] = preNWDVelocityY; - this->NWDVelocity[ 2 ] = preNWDVelocityZ; + this->NWDVelocity = PointLoad(preNWDVelocityX, preNWDVelocityY, preNWDVelocityZ); this->NWDPressure = preNWDPressure; this->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); this->NWDMomentum = NWDVelocity * NWDDensity; this->SWDDensity = preSWDDensity; - this->SWDVelocity[ 0 ] = preSWDVelocityX; - this->SWDVelocity[ 1 ] = preSWDVelocityY; - this->SWDVelocity[ 2 ] = preSWDVelocityZ; + this->SWDVelocity = PointLoad(preSWDVelocityX, preSWDVelocityY, preSWDVelocityZ); this->SWDPressure = preSWDPressure; this->SWDEnergy = Energy( SWDDensity, SWDPressure, gamma, SWDVelocity); this->SWDMomentum = SWDVelocity * SWDDensity; this->NEUDensity = preNEUDensity; - this->NEUVelocity[ 0 ] = preNEUVelocityX; - this->NEUVelocity[ 1 ] = preNEUVelocityY; - this->NEUVelocity[ 2 ] = preNEUVelocityZ; + this->NEUVelocity = PointLoad(preNEUVelocityX, preNEUVelocityY, preNEUVelocityZ); this->NEUPressure = preNEUPressure; this->NEUEnergy = Energy( NEUDensity, NEUPressure, gamma, NEUVelocity); this->NEUMomentum = NEUVelocity * NEUDensity; this->SEUDensity = preSEUDensity; - this->SEUVelocity[ 0 ] = preSEUVelocityX; - this->SEUVelocity[ 1 ] = preSEUVelocityY; - this->SEUVelocity[ 2 ] = preSEUVelocityZ; + this->SEUVelocity = PointLoad(preSEUVelocityX, preSEUVelocityY, preSEUVelocityZ); this->SEUPressure = preSEUPressure; this->SEUEnergy = Energy( SEUDensity, SEUPressure, gamma, SEUVelocity); this->SEUMomentum = SEUVelocity * SEUDensity; this->NEDDensity = preNEDDensity; - this->NEDVelocity[ 0 ] = preNEDVelocityX; - this->NEDVelocity[ 1 ] = preNEDVelocityY; - this->NEDVelocity[ 2 ] = preNEDVelocityZ; + this->NEDVelocity = PointLoad(preNEDVelocityX, preNEDVelocityY, preNEDVelocityZ); this->NEDPressure = preNEDPressure; this->NEDEnergy = Energy( NEDDensity, NEDPressure, gamma, NEDVelocity); this->NEDMomentum = NEDVelocity * NEDDensity; this->SEDDensity = preSEDDensity; - this->SEDVelocity[ 0 ] = preSEDVelocityX; - this->SEDVelocity[ 1 ] = preSEDVelocityY; - this->SEDVelocity[ 2 ] = preSEDVelocityZ; + this->SEDVelocity = PointLoad(preSEDVelocityX, preSEDVelocityY, preSEDVelocityZ); this->SEDPressure = preSEDPressure; this->SEDEnergy = Energy( SEDDensity, SEDPressure, gamma, SEDVelocity); this->SEDMomentum = SEDVelocity * SEDDensity; + + std::cout << this->SEDEnergy; + std::cout << this->SWDEnergy; } + PointType PointLoad( RealType ValueX, RealType ValueY, RealType ValueZ) + { + PointType point; + switch (Dimensions) + { + case 1: point[ 0 ] = ValueX; + break; + case 2: point[ 0 ] = ValueX; + point[ 1 ] = ValueY; + break; + case 3: point[ 0 ] = ValueX; + point[ 1 ] = ValueY; + point[ 2 ] = ValueZ; + break; + } + return point; + } + RealType Energy( RealType Density, RealType Pressure, RealType gamma, PointType Velocity) { RealType energy; @@ -1258,8 +1328,8 @@ class RiemannProblemInitialCondition this->SEDEnergy); variablesSetter->setDiscontinuity(this->discontinuityPlacement); variablesSetter->placeDensity(conservativeVariables); -// variablesSetter->placeMomentum(conservativeVariables); -// variablesSetter->placeEnergy(conservativeVariables); + variablesSetter->placeMomentum(conservativeVariables); + variablesSetter->placeEnergy(conservativeVariables); // for cyklus i = 0 to mesh.getDimensions().x() j pro .y() a k pro .z() // typedef typename MeshType::Cell CellType diff --git a/examples/inviscid-flow/eulerBuildConfigTag.h b/examples/inviscid-flow/eulerBuildConfigTag.h index b219ba4ff5..fd639c4adf 100644 --- a/examples/inviscid-flow/eulerBuildConfigTag.h +++ b/examples/inviscid-flow/eulerBuildConfigTag.h @@ -21,7 +21,7 @@ template<> struct ConfigTagReal< eulerBuildConfigTag, long double > { enum { ena template<> struct ConfigTagIndex< eulerBuildConfigTag, short int >{ enum { enabled = false }; }; template<> struct ConfigTagIndex< eulerBuildConfigTag, long int >{ enum { enabled = false }; }; -template< int Dimension > struct ConfigTagDimension< eulerBuildConfigTag, Dimension >{ enum { enabled = ( Dimension == 1 ) }; }; +//template< int Dimension > struct ConfigTagDimension< eulerBuildConfigTag, Dimension >{ enum { enabled = ( Dimension == 1 ) }; }; /**** * Use of Grid is enabled for allowed dimensions and Real, Device and Index types. diff --git a/src/TNL/Functions/VectorField.h b/src/TNL/Functions/VectorField.h index 04a7ea0e75..31e00f17e2 100644 --- a/src/TNL/Functions/VectorField.h +++ b/src/TNL/Functions/VectorField.h @@ -186,16 +186,15 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > v[ i ] = ( *this->vectorField[ i ] )[ index ]; return v; } -/* + template< typename EntityType > void setValue( const EntityType& meshEntity, - const PointType& value ) + const FunctionType& value ) { - static_assert( ( EntityType::getEntityDimension() == MeshEntityDimension ) && ( PointType::getSize() == Size ), "Calling with wrong EntityType -- entity dimensions do not match." ); for(int i = 0; i < Size; i++ ) this->vectorfield[ i ].setValue( meshEntity.getIndex(), value[ i ] ); } -*/ + template< typename EntityType > __cuda_callable__ VectorType getVector( const EntityType& meshEntity ) const -- GitLab