diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f4bc90294f926270f3485ff67c65bdc0affdb789..d760c34a8570c4a535fade9d621c637f7a60381d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,6 +12,8 @@ add_subdirectory( navier-stokes ) add_subdirectory( inviscid-flow ) add_subdirectory( inviscid-flow-sw ) +add_subdirectory( inviscid-flow-vl ) #add_subdirectory( mean-curvature-flow ) add_subdirectory( flow ) add_subdirectory( flow-sw ) +add_subdirectory( flow-vl ) diff --git a/examples/flow-vl/BoundaryConditionsBoiler.h b/examples/flow-vl/BoundaryConditionsBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..0cba68d7fa1a8689df50b0ea9016b511ad126918 --- /dev/null +++ b/examples/flow-vl/BoundaryConditionsBoiler.h @@ -0,0 +1,137 @@ +#include <TNL/Functions/FunctionAdapter.h> + +#include "DensityBoundaryConditionBoiler.h" +#include "MomentumXBoundaryConditionBoiler.h" +#include "MomentumYBoundaryConditionBoiler.h" +#include "MomentumZBoundaryConditionBoiler.h" +#include "EnergyBoundaryConditionBoiler.h" + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class BoundaryConditionsBoiler +{ + public: + typedef Mesh MeshType; + typedef Real RealType; + typedef Index IndexType; + typedef Function FunctionType; + typedef Functions::MeshFunction< Mesh > MeshFunctionType; + typedef typename Mesh::DeviceType DeviceType; + + typedef TNL::Operators::DensityBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::MomentumXBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::MomentumYBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::MomentumZBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::EnergyBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshType > MeshPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + } + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->densityBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->momentumXBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->momentumYBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->momentumZBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->energyBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->densityBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->momentumXBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->momentumYBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->momentumZBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->energyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + } + + void setTimestep(const RealType timestep) + { + this->densityBoundaryConditionsPointer->setTimestep(timestep); + this->momentumXBoundaryConditionsPointer->setTimestep(timestep); + this->momentumYBoundaryConditionsPointer->setTimestep(timestep); + this->momentumZBoundaryConditionsPointer->setTimestep(timestep); + this->energyBoundaryConditionsPointer->setTimestep(timestep); + } + + void setGamma(const RealType gamma) + { + this->densityBoundaryConditionsPointer->setGamma(gamma); + this->momentumXBoundaryConditionsPointer->setGamma(gamma); + this->momentumYBoundaryConditionsPointer->setGamma(gamma); + this->momentumZBoundaryConditionsPointer->setGamma(gamma); + this->energyBoundaryConditionsPointer->setGamma(gamma); + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->densityBoundaryConditionsPointer->setPressure(pressure); + this->momentumXBoundaryConditionsPointer->setPressure(pressure); + this->momentumYBoundaryConditionsPointer->setPressure(pressure); + this->momentumZBoundaryConditionsPointer->setPressure(pressure); + this->energyBoundaryConditionsPointer->setPressure(pressure); + } + + void setSpeed(const RealType cavitySpeed) + { + this->momentumXBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->momentumYBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->momentumZBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() + { + return this->densityBoundaryConditionsPointer; + } + + MomentumXBoundaryConditionsTypePointer& getMomentumXBoundaryCondition() + { + return this->momentumXBoundaryConditionsPointer; + } + + MomentumYBoundaryConditionsTypePointer& getMomentumYBoundaryCondition() + { + return this->momentumYBoundaryConditionsPointer; + } + + MomentumZBoundaryConditionsTypePointer& getMomentumZBoundaryCondition() + { + return this->momentumZBoundaryConditionsPointer; + } + + EnergyBoundaryConditionsTypePointer& getEnergyBoundaryCondition() + { + return this->energyBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/examples/flow-vl/BoundaryConditionsCavity.h b/examples/flow-vl/BoundaryConditionsCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..8a42faea17fa4cbdfa40a0b27533bca567d79206 --- /dev/null +++ b/examples/flow-vl/BoundaryConditionsCavity.h @@ -0,0 +1,137 @@ +#include <TNL/Functions/FunctionAdapter.h> + +#include "DensityBoundaryConditionCavity.h" +#include "MomentumXBoundaryConditionCavity.h" +#include "MomentumYBoundaryConditionCavity.h" +#include "MomentumZBoundaryConditionCavity.h" +#include "EnergyBoundaryConditionCavity.h" + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class BoundaryConditionsCavity +{ + public: + typedef Mesh MeshType; + typedef Real RealType; + typedef Index IndexType; + typedef Function FunctionType; + typedef Functions::MeshFunction< Mesh > MeshFunctionType; + typedef typename Mesh::DeviceType DeviceType; + + typedef TNL::Operators::DensityBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::MomentumXBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::MomentumYBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::MomentumZBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::EnergyBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshType > MeshPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + } + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->densityBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->momentumXBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->momentumYBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->momentumZBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->energyBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->densityBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->momentumXBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->momentumYBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->momentumZBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->energyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + } + + void setTimestep(const RealType timestep) + { + this->densityBoundaryConditionsPointer->setTimestep(timestep); + this->momentumXBoundaryConditionsPointer->setTimestep(timestep); + this->momentumYBoundaryConditionsPointer->setTimestep(timestep); + this->momentumZBoundaryConditionsPointer->setTimestep(timestep); + this->energyBoundaryConditionsPointer->setTimestep(timestep); + } + + void setGamma(const RealType gamma) + { + this->densityBoundaryConditionsPointer->setGamma(gamma); + this->momentumXBoundaryConditionsPointer->setGamma(gamma); + this->momentumYBoundaryConditionsPointer->setGamma(gamma); + this->momentumZBoundaryConditionsPointer->setGamma(gamma); + this->energyBoundaryConditionsPointer->setGamma(gamma); + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->densityBoundaryConditionsPointer->setPressure(pressure); + this->momentumXBoundaryConditionsPointer->setPressure(pressure); + this->momentumYBoundaryConditionsPointer->setPressure(pressure); + this->momentumZBoundaryConditionsPointer->setPressure(pressure); + this->energyBoundaryConditionsPointer->setPressure(pressure); + } + + void setSpeed(const RealType cavitySpeed) + { + this->momentumXBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->momentumYBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->momentumZBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() + { + return this->densityBoundaryConditionsPointer; + } + + MomentumXBoundaryConditionsTypePointer& getMomentumXBoundaryCondition() + { + return this->momentumXBoundaryConditionsPointer; + } + + MomentumYBoundaryConditionsTypePointer& getMomentumYBoundaryCondition() + { + return this->momentumYBoundaryConditionsPointer; + } + + MomentumZBoundaryConditionsTypePointer& getMomentumZBoundaryCondition() + { + return this->momentumZBoundaryConditionsPointer; + } + + EnergyBoundaryConditionsTypePointer& getEnergyBoundaryCondition() + { + return this->energyBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/examples/flow-vl/CMakeLists.txt b/examples/flow-vl/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3b23fa0997546283524a2739de2cbdf080c63fb9 --- /dev/null +++ b/examples/flow-vl/CMakeLists.txt @@ -0,0 +1,23 @@ +set( tnl_flow_vl_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_vl_SOURCES + navierStokes.cpp + navierStokes.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-vl${debugExt} navierStokes.cu) + target_link_libraries (tnl-navier-stokes-vl${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-vl${debugExt} navierStokes.cpp) + target_link_libraries (tnl-navier-stokes-vl${debugExt} tnl${debugExt}-${tnlVersion} ) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-vl${debugExt} + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-vl + ${tnl_inviscid_flow_SOURCES} + DESTINATION share/tnl-${tnlVersion}/examples/navier-stokes-vl ) diff --git a/examples/flow-vl/CompressibleConservativeVariables.h b/examples/flow-vl/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..a3afc845366f8df17b41c5affc5a4e49d5da052a --- /dev/null +++ b/examples/flow-vl/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-vl/DensityBoundaryConditionBoiler.h b/examples/flow-vl/DensityBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..c3bae7e3d961ab4a6f6dddb287cc1a23184f1c87 --- /dev/null +++ b/examples/flow-vl/DensityBoundaryConditionBoiler.h @@ -0,0 +1,542 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DensityBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function > +class DensityBoundaryConditionsBoilerBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef DensityBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return u[ neighborEntities.template getEntityIndex< 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef DensityBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if (entity.getCoordinates().y() < 0.8 * ( entity.getMesh().getDimensions().y() - 1 ) && false) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, -1 >() ]; + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef DensityBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if (entity.getCoordinates().z() < 0.8 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DensityBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionBoilers: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/DensityBoundaryConditionCavity.h b/examples/flow-vl/DensityBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..a2d34ce540b8f8806b0ae0bf7e31d357c01ed647 --- /dev/null +++ b/examples/flow-vl/DensityBoundaryConditionCavity.h @@ -0,0 +1,536 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DensityBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function > +class DensityBoundaryConditionsCavityBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef DensityBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return u[ neighborEntities.template getEntityIndex< 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef DensityBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef DensityBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DensityBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/EnergyBoundaryConditionBoiler.h b/examples/flow-vl/EnergyBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..fe227d68f81a0df6b980d429cfb23472c0f97bc2 --- /dev/null +++ b/examples/flow-vl/EnergyBoundaryConditionBoiler.h @@ -0,0 +1,854 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> +#include "CompressibleConservativeVariables.h" + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class EnergyBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function> +class EnergyBoundaryConditionsBoilerBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef EnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef EnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.20 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.19 * ( entity.getMesh().getDimensions().y() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->cavitySpeed + * + this->cavitySpeed + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + ); + else + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 1, 0 >()] + + 0 + ) + * + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 1, 0 >()] + + 0 + ) + );*/ + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if( ( entity.getCoordinates().y() < 0.20 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.19 * ( entity.getMesh().getDimensions().y() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->cavitySpeed * ( -1 ) + * + this->cavitySpeed * ( -1 ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + ); + else if( entity.getCoordinates().y() > 0.8 * ( entity.getMesh().getDimensions().y() - 1 ) && false ) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< -1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< -1, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< -1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< -1, 0 >()] + + 0 + ) + );*/ + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.6 * ( entity.getMesh().getDimensions().x() - 1 ) ) && ( entity.getCoordinates().x() > 0.4 * ( entity.getMesh().getDimensions().x() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + + + this->cavitySpeed + * + this->cavitySpeed + ); + else + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 1 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 1 >()] + + 0 + ) + );*/ + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, -1 >() ]; + /*return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, -1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, -1 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, -1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, -1 >()] + + 0 + ) + );*/ + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef EnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.59 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed + * + this->cavitySpeed + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + ); + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if( ( entity.getCoordinates().y() < 0.59 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed * ( -1 ) + * + this->cavitySpeed * ( -1 ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + ); + else if( entity.getCoordinates().y() >0.8 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.59 * ( entity.getMesh().getDimensions().x() - 1 ) ) && ( entity.getCoordinates().x() > 0.39 * ( entity.getMesh().getDimensions().x() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed + * + this->cavitySpeed + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + ); + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + if( ( entity.getCoordinates().x() < 0.59 * ( entity.getMesh().getDimensions().x() - 1 ) ) && ( entity.getCoordinates().x() > 0.39 * ( entity.getMesh().getDimensions().x() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed * ( -1 ) + * + this->cavitySpeed * ( -1 ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + ); + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) +{ + if( ( entity.getCoordinates().x() < 0.6 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.4 * ( entity.getMesh().getDimensions().y() - 1 ) ) + &&( entity.getCoordinates().y() < 0.6 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.4 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * + ( + ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + + + ( + this->cavitySpeed + * + this->cavitySpeed + ) + ); + + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const EnergyBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/EnergyBoundaryConditionCavity.h b/examples/flow-vl/EnergyBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..ca3fbe01dedcfdb7bc0a40777ff93e264fcfdec0 --- /dev/null +++ b/examples/flow-vl/EnergyBoundaryConditionCavity.h @@ -0,0 +1,673 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> +#include "CompressibleConservativeVariables.h" + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class EnergyBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function> +class EnergyBoundaryConditionsCavityBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef EnergyBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef EnergyBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /* ( (* this->pressure)[ neighborEntities.template getEntityIndex< 1, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 1, 0 >()] + * ( + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 1, 0 >()] + + 0 + ) + * + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 1, 0 >()] + + 0 + ) + )*/; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /* ( (* this->pressure)[ neighborEntities.template getEntityIndex< -1, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< -1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< -1, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< -1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< -1, 0 >()] + + 0 + ) + )*/; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /* ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 1 >() ] + / ( this->gamma - 1 ) + ) + + 0 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 1 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 1 >()] + + 0 + ) + )*/; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, -1 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, -1 >()] + * ( + this->cavitySpeed/* + * ( + entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) + ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ + * + this->cavitySpeed/* + * ( + entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) + ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + + 0 + ) + ); + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef EnergyBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + ( this->cavitySpeed + * ( + entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) + ) + / ( entity.getMesh().getDimensions().x() / 2 ) + ) + * + ( this->cavitySpeed + * ( + entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) + ) + / ( entity.getMesh().getDimensions().x() / 2 ) + ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + + + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 2 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + 0 + ) + ); + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const EnergyBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/LaxFridrichs.h b/examples/flow-vl/LaxFridrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..cdf32899f69eb797a6d9a18a52b84c09709867bf --- /dev/null +++ b/examples/flow-vl/LaxFridrichs.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-vl/LaxFridrichsContinuity.h b/examples/flow-vl/LaxFridrichsContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..45ad4d52b12d402365a40cac043d5525e230cecb --- /dev/null +++ b/examples/flow-vl/LaxFridrichsContinuity.h @@ -0,0 +1,288 @@ +/*************************************************************************** + 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[ 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-vl/LaxFridrichsEnergy.h b/examples/flow-vl/LaxFridrichsEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..18c824762b8c677253dbd4e494be7ad3aea7e769 --- /dev/null +++ b/examples/flow-vl/LaxFridrichsEnergy.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-vl/LaxFridrichsMomentumBase.h b/examples/flow-vl/LaxFridrichsMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..67dae9fdf8256cecf032a731dd5d616d715ca0fe --- /dev/null +++ b/examples/flow-vl/LaxFridrichsMomentumBase.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-vl/LaxFridrichsMomentumX.h b/examples/flow-vl/LaxFridrichsMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..63def12d315188b82e82402635fca863d1b9a629 --- /dev/null +++ b/examples/flow-vl/LaxFridrichsMomentumX.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-vl/LaxFridrichsMomentumY.h b/examples/flow-vl/LaxFridrichsMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..8ce42282dd4c74d5ed72d2abbd661235b95dc160 --- /dev/null +++ b/examples/flow-vl/LaxFridrichsMomentumY.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-vl/LaxFridrichsMomentumZ.h b/examples/flow-vl/LaxFridrichsMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..a67e862ceffd78d4fd770d7b1a07e9f05af349d8 --- /dev/null +++ b/examples/flow-vl/LaxFridrichsMomentumZ.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-vl/MomentumXBoundaryConditionBoiler.h b/examples/flow-vl/MomentumXBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..823ec475a570074f2f147a5b899606f203b76354 --- /dev/null +++ b/examples/flow-vl/MomentumXBoundaryConditionBoiler.h @@ -0,0 +1,594 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumXBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumXBoundaryConditionsBoilerBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumXBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumXBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.20 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.19 * ( entity.getMesh().getDimensions().y() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->cavitySpeed + ); + else + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if( ( entity.getCoordinates().y() < 0.20 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.19 * ( entity.getMesh().getDimensions().y() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->cavitySpeed * ( -1 ) + ); + else if( entity.getCoordinates().y() > 0.8 * ( entity.getMesh().getDimensions().y() - 1 ) && false ) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*(* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 1 >()] + );*/ + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, -1 >() ]; + /*return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, -1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, -1 >()] + );*/ + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumXBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.59 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed + ); + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if( ( entity.getCoordinates().y() < 0.59 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed * ( -1 ) + ); + else if( entity.getCoordinates().y() >0.8 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumXBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/MomentumXBoundaryConditionCavity.h b/examples/flow-vl/MomentumXBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..b78731382731f3aea95b64257c7330af15d78a99 --- /dev/null +++ b/examples/flow-vl/MomentumXBoundaryConditionCavity.h @@ -0,0 +1,570 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumXBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumXBoundaryConditionsCavityBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumXBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumXBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*(* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0, 1 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 1 >()] + );*/ + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, -1 >()] + * ( + ( this->cavitySpeed/* + * ( + entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) + ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ + ) + ); + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumXBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed + ); + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumXBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/MomentumYBoundaryConditionBoiler.h b/examples/flow-vl/MomentumYBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..76f3ff05735d1e813ffef7105509986a14036de8 --- /dev/null +++ b/examples/flow-vl/MomentumYBoundaryConditionBoiler.h @@ -0,0 +1,588 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumYBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumYBoundaryConditionsBoilerBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumYBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumYBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*(* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 1, 0 >()] + );*/ + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if( entity.getCoordinates().y() > 0.8 * ( entity.getMesh().getDimensions().y() - 1 ) && false) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*(* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< -1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< -1, 0 >()] + );*/ + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.6 * ( entity.getMesh().getDimensions().x() - 1 ) ) && ( entity.getCoordinates().x() > 0.4 * ( entity.getMesh().getDimensions().x() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->cavitySpeed + ); + else return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, -1 >() ]; + /*return u[ neighborEntities.template getEntityIndex< 0, 0 >() ];*/ + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumYBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if( entity.getCoordinates().y() >0.8 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.59 * ( entity.getMesh().getDimensions().x() - 1 ) ) && ( entity.getCoordinates().x() > 0.39 * ( entity.getMesh().getDimensions().x() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed + ); + else return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + if( ( entity.getCoordinates().x() < 0.59 * ( entity.getMesh().getDimensions().x() - 1 ) ) && ( entity.getCoordinates().x() > 0.39 * ( entity.getMesh().getDimensions().x() - 1 ) ) + &&( entity.getCoordinates().z() < 0.59 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed * ( -1 ) + ); + else return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumYBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/MomentumYBoundaryConditionCavity.h b/examples/flow-vl/MomentumYBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..afce8239b71ef68697a395177ae28c0be21dc788 --- /dev/null +++ b/examples/flow-vl/MomentumYBoundaryConditionCavity.h @@ -0,0 +1,564 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumYBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumYBoundaryConditionsCavityBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumYBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumYBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*(* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 1, 0 >()] + );*/ + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + /*(* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< -1, 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< -1, 0 >()] + );*/ + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumYBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumYBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/MomentumZBoundaryConditionBoiler.h b/examples/flow-vl/MomentumZBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..188aaa9851aaa93eeadd0de85d26554d562b66df --- /dev/null +++ b/examples/flow-vl/MomentumZBoundaryConditionBoiler.h @@ -0,0 +1,563 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumZBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumZBoundaryConditionsBoilerBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumZBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumZBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< -0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumZBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + if( entity.getCoordinates().y() >0.8 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + else + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.6 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.4 * ( entity.getMesh().getDimensions().y() - 1 ) ) + &&( entity.getCoordinates().y() < 0.6 * ( entity.getMesh().getDimensions().z() - 1 ) ) && ( entity.getCoordinates().z() > 0.4 * ( entity.getMesh().getDimensions().z() - 1 ) ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->cavitySpeed + ); + else return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumZBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/MomentumZBoundaryConditionCavity.h b/examples/flow-vl/MomentumZBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..1942cd58935395f340ea99ab0be0b74f1aee0c69 --- /dev/null +++ b/examples/flow-vl/MomentumZBoundaryConditionCavity.h @@ -0,0 +1,554 @@ +/*************************************************************************** + IdentityOperator.h - description + ------------------- + begin : Nov 17, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + + +#pragma once + +#include <TNL/Functions/FunctionAdapter.h> + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumZBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumZBoundaryConditionsCavityBase +{ + public: + + typedef Function FunctionType; + + static void configSetup( const Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + } + + template< typename MeshPointer > + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return Functions::FunctionAdapter< typename MeshPointer::ObjectType, FunctionType >::setup( this->function, meshPointer, parameters, prefix ); + } + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + Function::configSetup( config, prefix ); + }; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + return this->function.setup( parameters, prefix ); + }; + + void setFunction( const FunctionType& function ) + { + this->function = function; + }; + + FunctionType& getFunction() + { + return this->function; + } + + const FunctionType& getFunction() const + { + return this->function; + }; + + protected: + + FunctionType function; + +}; + +/**** + * 1D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 1, 1, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 1, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumZBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + * ( (* (* this->compressibleConservativeVariables->getMomentum())[ 0 ])[neighborEntities.template getEntityIndex< 0 >()] + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0 >()] + + this->timestep + ); + else + return u[ neighborEntities.template getEntityIndex< -1 >() ]; + + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + else + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 2, 2, + Real, + Index > + +{ + public: + + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 2, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumZBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< -0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + } + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsCavityBase< Function >, + public Operator< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, + Functions::MeshBoundaryDomain, + 3, 3, + Real, + Index > +{ + public: + + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef Function FunctionType; + typedef Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; + typedef Containers::StaticVector< 3, RealType > PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef MomentumZBoundaryConditionsCavity< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsCavityBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + template< typename EntityType, + typename MeshFunction > + __cuda_callable__ + const RealType operator()( const MeshFunction& u, + const EntityType& entity, + const RealType& time = 0 ) const + { + const MeshType& mesh = entity.getMesh(); + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + if( entity.getCoordinates().x() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + // The following line is commented to avoid compiler warning + //if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + } + + + template< typename EntityType > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const EntityType& entity ) const + { + return 2; + } + + template< typename PreimageFunction, + typename MeshEntity, + typename Matrix, + typename Vector > + __cuda_callable__ + void setMatrixElements( const PreimageFunction& u, + const MeshEntity& entity, + const RealType& time, + const RealType& tau, + Matrix& matrix, + Vector& b ) const + { + const auto& neighborEntities = entity.getNeighborEntities(); + const IndexType& index = entity.getIndex(); + typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); + if( entity.getCoordinates().x() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 1, 0, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< -1, 0, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().x() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 1, 0 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, -1, 0 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().y() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == 0 ) + { + matrixRow.setElement( 0, index, 1.0 ); + matrixRow.setElement( 1, neighborEntities.template getEntityIndex< 0, 0, 1 >(), -1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + if( entity.getCoordinates().z() == entity.getMesh().getDimensions().z() - 1 ) + { + matrixRow.setElement( 0, neighborEntities.template getEntityIndex< 0, 0, -1 >(), -1.0 ); + matrixRow.setElement( 1, index, 1.0 ); + b[ index ] = entity.getMesh().getSpaceSteps().z() * + Functions::FunctionAdapter< MeshType, FunctionType >::getValue( this->function, entity, time ); + } + } + + void setTimestep(const RealType timestep ) + { + this->timestep = timestep; + } + + void setGamma(const RealType gamma ) + { + this->gamma = gamma; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + this->compressibleConservativeVariables = compressibleConservativeVariables; + } + + void setPressure(const MeshFunctionPointer& pressure) + { + this->pressure = pressure; + } + + void setCavitySpeed(const RealType cavitySpeed) + { + this->cavitySpeed = cavitySpeed; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumZBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/examples/flow-vl/PhysicalVariablesGetter.h b/examples/flow-vl/PhysicalVariablesGetter.h new file mode 100644 index 0000000000000000000000000000000000000000..f1ba6bd1222b8653faeaac041606c101a071e188 --- /dev/null +++ b/examples/flow-vl/PhysicalVariablesGetter.h @@ -0,0 +1,122 @@ +/*************************************************************************** + 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 + { + if( density.template getData< DeviceType >()( meshEntity ) == 0.0 ) + return 0; + else + 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 ); + if( rho == 0.0 ) + return 0; + else + 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-vl/RiemannProblemInitialCondition.h b/examples/flow-vl/RiemannProblemInitialCondition.h new file mode 100644 index 0000000000000000000000000000000000000000..640e4b6d1e59bca19fd09e0f2374bd88f5b82cd5 --- /dev/null +++ b/examples/flow-vl/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->NWDEnergy = 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.59745, 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, + 0.1, 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.1, 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-vl/Upwind.h b/examples/flow-vl/Upwind.h new file mode 100644 index 0000000000000000000000000000000000000000..cf337144b1b1f2b7e163c56c6e632cb28f495f47 --- /dev/null +++ b/examples/flow-vl/Upwind.h @@ -0,0 +1,158 @@ +/*************************************************************************** + Upwind.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 "UpwindContinuity.h" +#include "UpwindEnergy.h" +#include "UpwindMomentumX.h" +#include "UpwindMomentumY.h" +#include "UpwindMomentumZ.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class Upwind +{ + 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 UpwindContinuity< Mesh, Real, Index > ContinuityOperatorType; + typedef UpwindMomentumX< Mesh, Real, Index > MomentumXOperatorType; + typedef UpwindMomentumY< Mesh, Real, Index > MomentumYOperatorType; + typedef UpwindMomentumZ< Mesh, Real, Index > MomentumZOperatorType; + typedef UpwindEnergy< 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 + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); + } + + Upwind() + :dynamicalViscosity( 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( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + + 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 setGamma( const RealType& gamma ) + { + this->continuityOperatorPointer->setGamma( gamma ); + this->momentumXOperatorPointer->setGamma( gamma ); + this->momentumYOperatorPointer->setGamma( gamma ); + this->momentumZOperatorPointer->setGamma( gamma ); + this->energyOperatorPointer->setGamma( gamma ); + } + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->continuityOperatorPointer->setPressure( pressure ); + this->momentumXOperatorPointer->setPressure( pressure ); + this->momentumYOperatorPointer->setPressure( pressure ); + this->momentumZOperatorPointer->setPressure( pressure ); + this->energyOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + } + + 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 dynamicalViscosity; +}; + +} //namespace TNL diff --git a/examples/flow-vl/UpwindContinuity.h b/examples/flow-vl/UpwindContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..32ff1f88ec78667d9533e6ac5b179cbdb7c36746 --- /dev/null +++ b/examples/flow-vl/UpwindContinuity.h @@ -0,0 +1,382 @@ +/*************************************************************************** + UpwindContinuity.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 UpwindContinuityBase +{ + 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; + + static String getType() + { + return String( "UpwindContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + RealType positiveDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ); + else + return density * velocity; + }; + + RealType negativeDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return density * velocity; + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + RealType multiply (const RealType& a, const RealType& b ) const + { + return a * b; + }; + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindContinuityBase< 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) + - this->positiveDensityFlux( u[ west ], velocity_x_west , pressure_west ) + - this->negativeDensityFlux( u[ center ], velocity_x_center, pressure_center ) + + this->negativeDensityFlux( u[ east ], velocity_x_east , pressure_east ) + ); + } + + /*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 UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindContinuityBase< 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) + - this->positiveDensityFlux( u[ west ], velocity_x_west , pressure_west ) + - this->negativeDensityFlux( u[ center ], velocity_x_center, pressure_center ) + + this->negativeDensityFlux( u[ east ], velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveDensityFlux( u[ center ], velocity_y_center, pressure_center ) + - this->positiveDensityFlux( u[ south ], velocity_y_south , pressure_south ) + - this->negativeDensityFlux( u[ center ], velocity_y_center, pressure_center ) + + this->negativeDensityFlux( u[ north ], velocity_y_north , pressure_north ) + ); + } + + /*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 UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindContinuityBase< 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) + - this->positiveDensityFlux( u[ west ], velocity_x_west , pressure_west ) + - this->negativeDensityFlux( u[ center ], velocity_x_center, pressure_center ) + + this->negativeDensityFlux( u[ east ], velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveDensityFlux( u[ center ], velocity_y_center, pressure_center ) + - this->positiveDensityFlux( u[ south ], velocity_y_south , pressure_south ) + - this->negativeDensityFlux( u[ center ], velocity_y_center, pressure_center ) + + this->negativeDensityFlux( u[ north ], velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveDensityFlux( u[ center ], velocity_z_center, pressure_center ) + - this->positiveDensityFlux( u[ down ], velocity_z_down , pressure_down ) + - this->negativeDensityFlux( u[ center ], velocity_z_center, pressure_center ) + + this->negativeDensityFlux( u[ up ], velocity_z_up , pressure_up ) + ); + + } + + /*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-vl/UpwindEnergy.h b/examples/flow-vl/UpwindEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..a5a30cb17c38c954ad56423ac7ab2418c291eb39 --- /dev/null +++ b/examples/flow-vl/UpwindEnergy.h @@ -0,0 +1,681 @@ +/*************************************************************************** + UpwindEnergy.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 UpwindEnergyBase +{ + 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; + + UpwindEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "UpwindEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindEnergyBase< 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; + + RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) + * ( + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); + }; + + RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) + * ( + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return 0.0; + }; + + 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 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_center = this->pressure.template getData< DeviceType >()[ center ]; + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveEnergyFlux( density_center, velocity_x_center, pressure_center) + - this->positiveEnergyFlux( density_west , velocity_x_west , pressure_west ) + - this->negativeEnergyFlux( density_center, velocity_x_center, pressure_center) + + this->negativeEnergyFlux( density_east , velocity_x_east , pressure_east ) + ) +// 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 / 4 + * 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 UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindEnergyBase< 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; + + RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 ) ); + }; + + RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 ) ); + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return 0.0; + }; + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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_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 -hxInverse * ( + this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_west , velocity_x_west , velocity_y_west , pressure_west ) + - this->negativeEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_east , velocity_x_east , velocity_y_east , pressure_east ) + ) + -hyInverse * ( + this->positiveEnergyFlux( density_center, velocity_y_center, velocity_x_center, pressure_center) + - this->positiveEnergyFlux( density_south , velocity_y_south , velocity_x_south , pressure_south ) + - this->negativeEnergyFlux( density_center, velocity_y_center, velocity_x_center, pressure_center) + + this->negativeEnergyFlux( density_north , velocity_y_north , velocity_x_north , pressure_north ) + ) +// 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 / 4 + ) * 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 / 4 + + ( 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 / 4 + + ( 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 / 4 + ) * 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 UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindEnergyBase< 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; + + RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& velocity_other2, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + velocity_other2 * velocity_other2 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) ); + }; + + RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& velocity_other2, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) ); + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + velocity_other2 * velocity_other2 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return 0.0; + }; + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_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_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_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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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_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_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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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_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_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_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 -hxInverse * ( + this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) + - this->positiveEnergyFlux( density_west , velocity_x_west , velocity_y_west , velocity_z_west , pressure_west ) + - this->negativeEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) + + this->negativeEnergyFlux( density_east , velocity_x_east , velocity_y_east , velocity_z_east , pressure_east ) + ) + -hyInverse * ( + this->positiveEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + - this->positiveEnergyFlux( density_south , velocity_y_south , velocity_x_south , velocity_z_south , pressure_south ) + - this->negativeEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + + this->negativeEnergyFlux( density_north , velocity_y_north , velocity_x_north , velocity_z_north , pressure_north ) + ) + -hyInverse * ( + this->positiveEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_y_down , velocity_x_down , velocity_z_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_y_up , velocity_x_up , velocity_z_up , pressure_up ) + ) +// 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 / 4 + - 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 / 4 + ) * 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 / 4 + + ( 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 / 4 + + ( velocity_x_east * velocity_z_center - velocity_x_center * velocity_z_west + - 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 / 4 + + ( 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 / 4 + - 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 / 4 + ) * 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 / 4 + + ( 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 / 4 + ) * 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 / 4 + + ( 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_down + - 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 / 4 + - 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 / 4 + ) * 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-vl/UpwindMomentumBase.h b/examples/flow-vl/UpwindMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..b9aed78e6c8cba2b7835358b388163a3d7b3e409 --- /dev/null +++ b/examples/flow-vl/UpwindMomentumBase.h @@ -0,0 +1,129 @@ +/*************************************************************************** + UpwindMomentumBase.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 UpwindMomentumBase +{ + 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; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + RealType positiveMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return 0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ); + else + return density * velocity * velocity + pressure; + }; + + RealType negativeMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return density * velocity * velocity + pressure; + else if ( machNumber <= 1.0 ) + return - density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) * ( - 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ); + else + return 0; + }; + + RealType positiveOtherMomentumFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) * velocity_other; + else + return density * velocity_main * velocity_other; + }; + + RealType negativeOtherMomentumFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return density * velocity_main * velocity_other; + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) * velocity_other; + else + return 0.0; + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/examples/flow-vl/UpwindMomentumX.h b/examples/flow-vl/UpwindMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..edd3756208121de465185a84693a10671e587bac --- /dev/null +++ b/examples/flow-vl/UpwindMomentumX.h @@ -0,0 +1,433 @@ +/*************************************************************************** + UpwindMomentumX.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 "UpwindMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + 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 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_center = this->pressure.template getData< DeviceType >()[ center ]; + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + - this->positiveMainMomentumFlux( density_west, velocity_x_west , pressure_west ) + - this->negativeMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + + this->negativeMainMomentumFlux( density_east, velocity_x_east , pressure_east ) + ) +// 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 UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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 -hxInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + - this->positiveMainMomentumFlux( density_west , velocity_x_west , pressure_west ) + - this->negativeMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + + this->negativeMainMomentumFlux( density_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_south , velocity_x_south , velocity_y_south , pressure_south ) + - this->negativeOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_north , velocity_x_north , velocity_y_north , pressure_north ) + ) +// 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 / 4 + ) * this->dynamicalViscosity +// T_21_y + + ( ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north - 2 * velocity_x_center + velocity_x_south + ) * 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 UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_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_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_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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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_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 -hxInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + - this->positiveMainMomentumFlux( density_west , velocity_x_west , pressure_west ) + - this->negativeMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + + this->negativeMainMomentumFlux( density_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_south , velocity_x_south , velocity_y_south , pressure_south ) + - this->negativeOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_north , velocity_x_north , velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_x_center, velocity_z_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_down , velocity_x_down , velocity_z_down , pressure_down ) + - this->negativeOtherMomentumFlux( density_center, velocity_x_center, velocity_z_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_up , velocity_x_up , velocity_z_up , pressure_up ) + ) +// 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 / 4 + - 2.0 / 3.0 * ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse / 4 + ) * this->dynamicalViscosity +// T_21_x + + ( ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + ) * hxInverse * hyInverse / 4 + + ( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// T_31_x + + ( ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse / 4 + + ( 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;*/ +}; + + +} // namespace TNL + diff --git a/examples/flow-vl/UpwindMomentumY.h b/examples/flow-vl/UpwindMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..4b5a7bcb26d049c2773790857d3f79246488b55b --- /dev/null +++ b/examples/flow-vl/UpwindMomentumY.h @@ -0,0 +1,403 @@ +/*************************************************************************** + UpwindMomentumY.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 "UpwindMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumY< " ) + + 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 UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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_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 -hxInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_west , velocity_y_west , velocity_x_west , pressure_west ) + - this->negativeOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_east , velocity_y_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + - this->positiveMainMomentumFlux( density_south , velocity_y_south , pressure_south ) + - this->negativeMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + + this->negativeMainMomentumFlux( density_north , velocity_y_north , pressure_north ) + ) +// 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 / 4 + ) * this->dynamicalViscosity +// T_12_x + + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 + + ( velocity_y_west - 2 * velocity_y_center + velocity_y_east + ) * 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 UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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_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_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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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_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 -hxInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_west , velocity_y_west , velocity_x_west , pressure_west ) + - this->negativeOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_east , velocity_y_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + - this->positiveMainMomentumFlux( density_south , velocity_y_south , pressure_south ) + - this->negativeMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + + this->negativeMainMomentumFlux( density_north , velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_z_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_down , velocity_y_down , velocity_z_down , pressure_down ) + - this->negativeOtherMomentumFlux( density_center, velocity_y_center, velocity_z_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_up , velocity_y_up , velocity_z_up , pressure_up ) + ) +// T_12_y + + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 + + ( 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 / 4 + - 2.0 / 3.0 * ( velocity_z_upNorth - velocity_z_downNorth - velocity_z_upSouth + velocity_z_downSouth + ) * hyInverse * hzInverse / 4 + ) * this->dynamicalViscosity +// T_32_y + + ( ( velocity_z_upNorth - velocity_z_downNorth - velocity_z_upSouth + velocity_z_downSouth + ) * hyInverse * hzInverse / 4 + + ( 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-vl/UpwindMomentumZ.h b/examples/flow-vl/UpwindMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..887eec977517e5850db2085835d8242d63605c96 --- /dev/null +++ b/examples/flow-vl/UpwindMomentumZ.h @@ -0,0 +1,338 @@ +/*************************************************************************** + UpwindMomentumZ.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 "UpwindMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumZ< " ) + + 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 UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumZ< " ) + + 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 UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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_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_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_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 -hxInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_z_center, velocity_x_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_west , velocity_z_west , velocity_x_west , pressure_west ) + - this->negativeOtherMomentumFlux( density_center, velocity_z_center, velocity_x_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_east , velocity_z_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_z_center, velocity_y_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_south , velocity_z_south , velocity_y_south , pressure_south ) + - this->negativeOtherMomentumFlux( density_center, velocity_z_center, velocity_y_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_north , velocity_z_north , velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_z_center, pressure_center ) + - this->positiveMainMomentumFlux( density_down , velocity_z_down , pressure_down ) + - this->negativeMainMomentumFlux( density_center, velocity_z_center, pressure_center ) + + this->negativeMainMomentumFlux( density_up , velocity_z_up , pressure_up ) + ) +// 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 / 4 + ) + * this->dynamicalViscosity +// T_23_z + + ( ( velocity_y_upNorth - velocity_y_downNorth - velocity_y_upSouth + velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + + ( 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 / 4 + - 2.0 / 3.0 * ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) + * hxInverse * hzInverse / 4 + ) + * 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-vl/navierStokes.cpp b/examples/flow-vl/navierStokes.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7dffcb059fb68607cfb12a94f3b929fb0f517ce8 --- /dev/null +++ b/examples/flow-vl/navierStokes.cpp @@ -0,0 +1 @@ +#include "navierStokes.h" diff --git a/examples/flow-vl/navierStokes.cu b/examples/flow-vl/navierStokes.cu new file mode 100644 index 0000000000000000000000000000000000000000..7dffcb059fb68607cfb12a94f3b929fb0f517ce8 --- /dev/null +++ b/examples/flow-vl/navierStokes.cu @@ -0,0 +1 @@ +#include "navierStokes.h" diff --git a/examples/flow-vl/navierStokes.h b/examples/flow-vl/navierStokes.h new file mode 100644 index 0000000000000000000000000000000000000000..b4cf74bfee795de066101f905ec4fe326ab4b5cb --- /dev/null +++ b/examples/flow-vl/navierStokes.h @@ -0,0 +1,107 @@ +#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 "Upwind.h" +#include "navierStokesRhs.h" +#include "navierStokesBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditionsCavity.h" +#include "BoundaryConditionsBoiler.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.", "cavity"); + config.addEntryEnum< String >( "boiler" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + config.addEntry< double >( "speed-increment", "This sets increment of input speed.", 0.0 ); + config.addEntry< double >( "speed-increment-until", "This sets time until input speed will rose", -0.1 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + Upwind< 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 Upwind< 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. + */ + typedef Functions::Analytic::Constant< Dimension, Real > Constant; + String boundaryConditionsType = parameters.getParameter< String >( "boundary-conditions-type" ); + if( boundaryConditionsType == "cavity" ) + { + typedef BoundaryConditionsCavity< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, 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-vl/navierStokesBuildConfigTag.h b/examples/flow-vl/navierStokesBuildConfigTag.h new file mode 100644 index 0000000000000000000000000000000000000000..f84233ade48df8bcd43b184da3ed918a45153888 --- /dev/null +++ b/examples/flow-vl/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/inviscid-flow-sw/3d/eulerProblem.h~ b/examples/flow-vl/navierStokesProblem.h similarity index 64% rename from examples/inviscid-flow-sw/3d/eulerProblem.h~ rename to examples/flow-vl/navierStokesProblem.h index c838b101e25219810633528e02074b3dc6bad91a..2d8f4c2e1de05d93b07d94f51db629b43823abfa 100644 --- a/examples/inviscid-flow-sw/3d/eulerProblem.h~ +++ b/examples/flow-vl/navierStokesProblem.h @@ -1,7 +1,19 @@ +/*************************************************************************** + 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; @@ -10,24 +22,19 @@ namespace TNL { template< typename Mesh, typename BoundaryCondition, typename RightHandSide, - typename DifferentialOperator > -class eulerProblem: + typename InviscidOperators > +class navierStokesProblem: public PDEProblem< Mesh, - typename DifferentialOperator::RealType, - typename Mesh::DeviceType, - typename DifferentialOperator::IndexType > + typename InviscidOperators::RealType, + typename Mesh::DeviceType, + typename InviscidOperators::IndexType > { public: - - typedef typename DifferentialOperator::RealType RealType; + + typedef typename InviscidOperators::RealType RealType; typedef typename Mesh::DeviceType DeviceType; - typedef typename DifferentialOperator::IndexType IndexType; - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; - typedef SharedPointer< DifferentialOperator > DifferentialOperatorPointer; - typedef SharedPointer< BoundaryCondition > BoundaryConditionPointer; - typedef SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - typedef PDEProblem< Mesh, RealType, DeviceType, IndexType > BaseType; + typedef typename InviscidOperators::IndexType IndexType; + typedef PDEProblem< Mesh, RealType, DeviceType, IndexType > BaseType; using typename BaseType::MeshType; using typename BaseType::MeshPointer; @@ -36,13 +43,17 @@ class eulerProblem: using typename BaseType::MeshDependentDataType; using typename BaseType::MeshDependentDataPointer; - typedef typename DifferentialOperator::Continuity Continuity; - typedef typename DifferentialOperator::MomentumX MomentumX; - typedef typename DifferentialOperator::MomentumY MomentumY; - typedef typename DifferentialOperator::Energy Energy; - typedef typename DifferentialOperator::Velocity Velocity; - typedef typename DifferentialOperator::VelocityX VelocityX; - typedef typename DifferentialOperator::Pressure Pressure; + 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(); @@ -75,7 +86,7 @@ class eulerProblem: void bindDofs( const MeshPointer& mesh, DofVectorPointer& dofs ); - void getExplicitRHS( const RealType& time, + void getExplicitUpdate( const RealType& time, const RealType& tau, const MeshPointer& mesh, DofVectorPointer& _u, @@ -99,20 +110,24 @@ class eulerProblem: protected: - DifferentialOperatorPointer differentialOperatorPointer; + InviscidOperatorsPointer inviscidOperatorsPointer; + BoundaryConditionPointer boundaryConditionPointer; RightHandSidePointer rightHandSidePointer; - - MeshFunctionPointer uRho, uRhoVelocityX, uRhoVelocityY, uRhoVelocityZ, uEnergy; - MeshFunctionPointer fuRho, fuRhoVelocityX, fuRhoVelocityY, fuRhoVelocityZ, fuEnergy; - MeshFunctionPointer pressure, velocity, velocityX, velocityY, velocityZ; + ConservativeVariablesPointer conservativeVariables, + conservativeVariablesRHS; + + VelocityFieldPointer velocity; + MeshFunctionPointer pressure; RealType gamma; - + RealType speedIncrement; + RealType cavitySpeed; + RealType speedIncrementUntil; }; } // namespace TNL -#include "eulerProblem_impl.h" +#include "navierStokesProblem_impl.h" diff --git a/examples/flow-vl/navierStokesProblem_impl.h b/examples/flow-vl/navierStokesProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..b0b528dc894d800d9bc845b41bc96e2af5c95358 --- /dev/null +++ b/examples/flow-vl/navierStokesProblem_impl.h @@ -0,0 +1,456 @@ +/*************************************************************************** + 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 "UpwindContinuity.h" +#include "UpwindEnergy.h" +#include "UpwindMomentumX.h" +#include "UpwindMomentumY.h" +#include "UpwindMomentumZ.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" ); + this->speedIncrementUntil = parameters.getParameter< RealType >( "speed-increment-until" ); + this->speedIncrement = parameters.getParameter< RealType >( "speed-increment" ); + this->cavitySpeed = parameters.getParameter< RealType >( "cavity-speed" ); + 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; + + fileName.setFileNameBase( "momentum-" ); + if( ! this->conservativeVariables->getMomentum()->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 ); + +// this->pressure->write( "pressure1", "gnuplot" ); +// getchar(); + /**** + * 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 ); + this->inviscidOperatorsPointer->setDensity( this->conservativeVariables->getDensity() ); + this->inviscidOperatorsPointer->setGamma( this->gamma ); + + /**** + * Set Up Boundary Conditions + */ + + typedef typename BoundaryCondition::DensityBoundaryConditionsType DensityBoundaryConditionsType; + typedef typename BoundaryCondition::MomentumXBoundaryConditionsType MomentumXBoundaryConditionsType; + typedef typename BoundaryCondition::MomentumYBoundaryConditionsType MomentumYBoundaryConditionsType; + typedef typename BoundaryCondition::MomentumZBoundaryConditionsType MomentumZBoundaryConditionsType; + typedef typename BoundaryCondition::EnergyBoundaryConditionsType EnergyBoundaryConditionsType; + + /**** + * Update Boundary Conditions + */ + if(this->speedIncrementUntil > time ) + { + this->boundaryConditionPointer->setTimestep(this->speedIncrement); + } + else + { + this->boundaryConditionPointer->setTimestep(0); + } + this->boundaryConditionPointer->setSpeed(this->cavitySpeed); + this->boundaryConditionPointer->setCompressibleConservativeVariables(this->conservativeVariables); + this->boundaryConditionPointer->setGamma(this->gamma); + this->boundaryConditionPointer->setPressure(this->pressure); + + + /**** + * Continuity equation + */ + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, ContinuityOperatorType, DensityBoundaryConditionsType, RightHandSide > explicitUpdaterContinuity; + explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); + explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer->getDensityBoundaryCondition() ); + 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, MomentumXBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumX; + explicitUpdaterMomentumX.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumXOperator() ); + explicitUpdaterMomentumX.setBoundaryConditions( this->boundaryConditionPointer->getMomentumXBoundaryCondition() ); + 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, MomentumYBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumY; + explicitUpdaterMomentumY.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumYOperator() ); + explicitUpdaterMomentumY.setBoundaryConditions( this->boundaryConditionPointer->getMomentumYBoundaryCondition() ); + 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, MomentumZBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumZ; + explicitUpdaterMomentumZ.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumZOperator() ); + explicitUpdaterMomentumZ.setBoundaryConditions( this->boundaryConditionPointer->getMomentumZBoundaryCondition() ); + 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, EnergyBoundaryConditionsType, RightHandSide > explicitUpdaterEnergy; + explicitUpdaterEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getEnergyOperator() ); + explicitUpdaterEnergy.setBoundaryConditions( this->boundaryConditionPointer->getEnergyBoundaryCondition() ); + explicitUpdaterEnergy.setRightHandSide( this->rightHandSidePointer ); + explicitUpdaterEnergy.template update< typename Mesh::Cell >( time, tau, mesh, + this->conservativeVariablesRHS->getEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); + +/* this->pressure->write( "pressure3", "gnuplot" ); + getchar(); + 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-vl/navierStokesRhs.h b/examples/flow-vl/navierStokesRhs.h new file mode 100644 index 0000000000000000000000000000000000000000..3c82ad4539292a4470fd88e9e3a6d03cd8ae2833 --- /dev/null +++ b/examples/flow-vl/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-vl/run-euler b/examples/flow-vl/run-euler new file mode 100644 index 0000000000000000000000000000000000000000..9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c --- /dev/null +++ b/examples/flow-vl/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/flow/LaxFridrichsEnergy.h b/examples/flow/LaxFridrichsEnergy.h index 4e8d9ffa6b88b74ad075ed1001b16f6536ab29aa..e7cdd91bea2602da3fc27f4af006f99a5bebcc4f 100644 --- a/examples/flow/LaxFridrichsEnergy.h +++ b/examples/flow/LaxFridrichsEnergy.h @@ -122,19 +122,23 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, 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 + - 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 / 4 * this->dynamicalViscosity; @@ -195,6 +199,7 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, 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 >(); @@ -204,10 +209,12 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, 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 ]; @@ -217,6 +224,7 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, 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 ]; @@ -236,22 +244,22 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, + ( 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 + - 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 / 4*/ + ) * hxInverse * hyInverse / 4 ) * this->dynamicalViscosity // vT_21_x - + ( /*( velocity_y_northEast * velocity_y_east - velocity_y_southEast * velocity_y_east + + ( ( 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 / 4*/ + ) * hxInverse * hyInverse / 4 + ( 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_northEast * velocity_x_north - velocity_x_southEast * velocity_x_south - velocity_x_northWest * velocity_x_north + velocity_x_southWest * velocity_x_south - ) * hxInverse * hyInverse / 4*/ + ) * hxInverse * hyInverse / 4 + ( 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 @@ -260,9 +268,9 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, + ( 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 + - 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 / 4*/ + ) * hxInverse * hyInverse / 4 ) * this->dynamicalViscosity; } @@ -322,6 +330,7 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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 >(); diff --git a/examples/flow/LaxFridrichsMomentumX.h b/examples/flow/LaxFridrichsMomentumX.h index 18794904759c4223b25fc32f5c85b0c888e40787..3e295c029f9bc4ae61dfc54650be4c4aff55cf18 100644 --- a/examples/flow/LaxFridrichsMomentumX.h +++ b/examples/flow/LaxFridrichsMomentumX.h @@ -67,12 +67,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea 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 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 ]; @@ -81,7 +84,7 @@ class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea - 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 + - 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west ) * hxSquareInverse * this->dynamicalViscosity; } @@ -147,8 +150,9 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 >(); @@ -161,6 +165,7 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; @@ -170,6 +175,7 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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 ]; @@ -186,13 +192,13 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea // 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 / 4*/ + - 2.0 / 3.0 * ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + ) * hxInverse * hyInverse / 4 ) * this->dynamicalViscosity // T_21_y - + (/* ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest + + ( ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest ) * hxInverse * hyInverse / 4 - + */( velocity_x_north - 2 * velocity_x_center + velocity_x_south + + ( velocity_x_north - 2 * velocity_x_center + velocity_x_south ) * hxInverse * hyInverse ) * this->dynamicalViscosity; } @@ -261,6 +267,7 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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 >(); @@ -283,10 +290,10 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; diff --git a/examples/flow/LaxFridrichsMomentumY.h b/examples/flow/LaxFridrichsMomentumY.h index fa41d78ff4c1cd8f0a68378fa764003503d9af9a..0df12c5227981b42b64437a4be96a511cf1b5991 100644 --- a/examples/flow/LaxFridrichsMomentumY.h +++ b/examples/flow/LaxFridrichsMomentumY.h @@ -132,6 +132,7 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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 >(); @@ -151,6 +152,7 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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 ]; @@ -170,12 +172,12 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea // 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 / 4*/ + - 2.0 / 3.0 * ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 ) * this->dynamicalViscosity // T_12_x - + (/* ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest - ) * hxInverse * hyInverse / 4*/ + + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 + ( velocity_y_west - 2 * velocity_y_center + velocity_y_east ) * hxSquareInverse ) * this->dynamicalViscosity; @@ -244,6 +246,7 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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 >(); diff --git a/examples/flow/LaxFridrichsMomentumZ.h b/examples/flow/LaxFridrichsMomentumZ.h index bc1ec2d6f1fd09cc497c0b9f529805425bf7809c..e4f8501ec1f3c44f1a39fb2a5aa85de5209f9635 100644 --- a/examples/flow/LaxFridrichsMomentumZ.h +++ b/examples/flow/LaxFridrichsMomentumZ.h @@ -194,6 +194,7 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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 >(); diff --git a/examples/inviscid-flow-sw/1d/Euler1DPressureGetter.h~ b/examples/inviscid-flow-sw/1d/Euler1DPressureGetter.h~ deleted file mode 100644 index 7900c4b08555dc87d2013f79441be9b3a5c86e1e..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/Euler1DPressureGetter.h~ +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef EulerPressureGetter_H -#define EulerPressureGetter_H - -#include <TNL/Containers/Vector.h> -#include <TNL/Meshes/Grid.h> -#include <TNL/Functions/Domain.h> - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class EulerPressureGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerPressureGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVel, - const MeshFunctionType& energy, - const RealType& gamma) - : rho( rho ), rhoVel( rhoVel ), energy( energy ), gamma( gamma ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - //if (this->rho[ idx ]==0) return 0; else return ( this->gamma - 1.0 ) * ( this->energy[ idx ] - 0.5 * this->rhoVel[ idx ] * this->rhoVel[ idx ] / this->rho[ idx ]); - return ( this->gamma - 1.0 ) * this->energy[ idx ] * this->rho[ idx ]; - - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVel; - - const MeshFunctionType& energy; - - RealType gamma; - -}; - -} //namespace TNL - -#endif /* EulerPressureGetter_H */ diff --git a/examples/inviscid-flow-sw/1d/LaxFridrichsContinuity_impl.h~ b/examples/inviscid-flow-sw/1d/LaxFridrichsContinuity_impl.h~ deleted file mode 100644 index 0a051d12579de4e378e61f2a63be8064bcd29629..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/LaxFridrichsContinuity_impl.h~ +++ /dev/null @@ -1,347 +0,0 @@ -#ifndef LaxFridrichsContinuity_IMPL_H -#define LaxFridrichsContinuity_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - - //rho - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return /*(0.5 / this->tau) * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) - - 0.5 * hxInverse * ( u[ east ] * this->velocity[ east ] - u[ west ] * this->velocity[ west ] );*/ - (0.5) * ( u[ west ] + u[ east ] ) - - 0.5 * hxInverse * this->tau * ( u[ east ] * this->velocity[ east ] - u[ west ] * this->velocity[ west ] ); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse + - ( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse + - ( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse + - ( u[ up ] - 2.0 * u[ center ] + u[ down ] ) * hzSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} // namespace TNL - -#endif /* LaxFridrichsContinuityIMPL_H */ - diff --git a/examples/inviscid-flow-sw/1d/LaxFridrichsMomentum_impl.h~ b/examples/inviscid-flow-sw/1d/LaxFridrichsMomentum_impl.h~ deleted file mode 100644 index ebfe4073242260eb950e74d6614d1728f7a8fd77..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/LaxFridrichsMomentum_impl.h~ +++ /dev/null @@ -1,351 +0,0 @@ -#ifndef LaxFridrichsMomentum_IMPL_H -#define LaxFridrichsMomentum_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentum< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentum< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentum< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - - //rhoVelocity - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return (0.5 / this->tau) * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) - - 0.5 * hxInverse * - (( u[ east ] * this -> velocity[ east ] + this -> pressure [ east ] ) - -( u[ west ] * this -> velocity[ west ] + this -> pressure [ west ] )); - /*(0.5) * ( u[ west ] + u[ east ] ) - - 0.5 * hxInverse * this->tau * - (( u[ east ] * this -> velocity[ east ] + this -> pressure [ east ] ) - -( u[ west ] * this -> velocity[ west ] + this -> pressure [ west ] ));*/ -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentum< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentum< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentum< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentum< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentum< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse + - ( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentum< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentum< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentum< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentum< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentum< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse + - ( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse + - ( u[ up ] - 2.0 * u[ center ] + u[ down ] ) * hzSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentum< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentum< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} // namespace TNL - -#endif /* LaxFridrichsMomentumIMPL_H */ - diff --git a/examples/inviscid-flow-sw/1d/MyMixedBoundaryConditions.h b/examples/inviscid-flow-sw/1d/MyMixedBoundaryConditions.h deleted file mode 100644 index 006a33e53f772dc961c11ad2a5d2d077ee80020e..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/MyMixedBoundaryConditions.h +++ /dev/null @@ -1,152 +0,0 @@ -// coppied and changed -/*************************************************************************** - tnlMyMixedBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYMIXEDBOUNDARYCONDITIONS_H_ -#define MYMIXEDBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyMixedBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - const IndexType& index = entity.getIndex(); - if( entity.getCoordinates().x() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 0 >() ]; - else - return u[ neighbourEntities.template getEntityIndex< -1 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyMixedBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyMixed boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYMIXEDBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/1d/MyNeumannBoundaryConditions.h b/examples/inviscid-flow-sw/1d/MyNeumannBoundaryConditions.h deleted file mode 100644 index cf9b29dcc19b6a781d00e66f1a97b5ce8aa738bb..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/MyNeumannBoundaryConditions.h +++ /dev/null @@ -1,152 +0,0 @@ -//** coppied and changed -/*************************************************************************** - tnlMyNeumannBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYNEUMANNBOUNDARYCONDITIONS_H_ -#define MYNEUMANNBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyNeumannBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - const IndexType& index = entity.getIndex(); - if( entity.getCoordinates().x() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 1 >() ]; - else - return u[ neighbourEntities.template getEntityIndex< -1 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyNeumannBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyNeumann boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYNEUMANNBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/1d/eulerProblem_impl.h~ b/examples/inviscid-flow-sw/1d/eulerProblem_impl.h~ deleted file mode 100644 index 33903a784bab5446a74331e0d6acb47b2d3ecd99..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/eulerProblem_impl.h~ +++ /dev/null @@ -1,343 +0,0 @@ -#ifndef eulerPROBLEM_IMPL_H_ -#define eulerPROBLEM_IMPL_H_ - -#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 "LaxFridrichsContinuity.h" -#include "LaxFridrichsMomentum.h" -#include "LaxFridrichsEnergy.h" -#include "Euler1DVelGetter.h" -#include "Euler1DPressureGetter.h" - -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getTypeStatic() -{ - return String( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getPrologHeader() const -{ - return String( "euler" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( //! this->boundaryConditionsPointer->setup( meshPointer, parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::IndexType -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 3*mesh->template getEntitiesCount< typename MeshType::Cell >(); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -bindDofs( const MeshPointer& mesh, - DofVectorPointer& dofVector ) -{ -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - std::cout << std::endl << "get conditions from CMD"; - typedef typename MeshType::Cell Cell; - this->gamma = parameters.getParameter< RealType >( "gamma" ); - RealType rhoL = parameters.getParameter< RealType >( "left-density" ); - RealType velL = parameters.getParameter< RealType >( "left-velocity" ); - RealType preL = parameters.getParameter< RealType >( "left-pressure" ); - RealType eL = ( preL / ( rhoL * (gamma - 1) ) ); - //RealType eL = ( preL / (gamma - 1) ) + 0.5 * rhoL * velL * velL; - RealType rhoR = parameters.getParameter< RealType >( "right-density" ); - RealType velR = parameters.getParameter< RealType >( "right-velocity" ); - RealType preR = parameters.getParameter< RealType >( "right-pressure" ); - RealType eR = ( preR / ( rhoR * (gamma - 1) ) ); - //RealType eR = ( preR / (gamma - 1) ) + 0.5 * rhoR * velR * velR; - RealType x0 = parameters.getParameter< RealType >( "riemann-border" ); - int count = mesh->template getEntitiesCount< Cell >(); - uRho->bind( mesh, *dofs, 0); - uRhoVelocity->bind( mesh, *dofs, count); - uEnergy->bind( mesh, *dofs, 2 * count); - Containers::Vector < RealType, DeviceType, IndexType > data; - data.setSize(2*count); - velocity->bind( mesh, data, 0); - pressure->bind( mesh, data, count ); - std::cout << std::endl << "set conditions from CMD"<< std::endl; - for(IndexType i = 0; i < count; i++) - if (i < x0 * count ) - { - ( *uRho )[i] = rhoL; - ( *uRhoVelocity )[i] = rhoL * velL; - ( *uEnergy )[i] = eL; - ( *velocity )[i] = velL; - ( *pressure )[i] = preL; - } - else - { - ( *uRho )[i] = rhoR; - ( *uRhoVelocity )[i] = rhoR * velR; - ( *uEnergy )[i] = eR; - ( *velocity )[i] = velR; - ( *pressure )[i] = preR; - }; - /* - const String& initialConditionFile = parameters.getParameter< String >( "initial-condition" ); - if( ! dofs.load( initialConditionFile ) ) - { - std::cerr << "I am not able to load the initial condition from the file " << initialConditionFile << "." << std::endl; - return false; - } - */ - return true; -} -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setupLinearSystem( const MeshPointer& mesh, - Matrix& matrix ) -{ -/* const IndexType dofs = this->getDofs( mesh ); - typedef typename Matrix::CompressedRowsLengthsVector CompressedRowsLengthsVectorType; - CompressedRowsLengthsVectorType rowLengths; - if( ! rowLengths.setSize( dofs ) ) - return false; - MatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, CompressedRowsLengthsVectorType > matrixSetter; - matrixSetter.template getCompressedRowsLengths< typename Mesh::Cell >( mesh, - differentialOperator, - boundaryCondition, - rowLengths ); - matrix.setDimensions( dofs, dofs ); - if( ! matrix.setCompressedRowsLengths( rowLengths ) ) - return false;*/ - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 ); - FileName fileName; - fileName.setExtension( "tnl" ); - fileName.setIndex( step ); - fileName.setFileNameBase( "rho-" ); - if( ! uRho->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVel-" ); - if( ! uRhoVelocity->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "energy-" ); - if( ! uEnergy->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocity-" ); - if( ! velocity->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "pressure-" ); - if( ! pressure->save( fileName.getFileName() ) ) - return false; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getExplicitRHS( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - DofVectorPointer& _fu, - MeshDependentDataPointer& meshDependentData ) -{ - typedef typename MeshType::Cell Cell; - int count = mesh->template getEntitiesCount< Cell >(); - //bind _fu - this->fuRho->bind(mesh, _fu, 0); - this->fuRhoVelocity->bind(mesh, _fu, count); - this->fuEnergy->bind(mesh, _fu, 2 * count); - - //generating Differential operator object - SharedPointer< Continuity > lF1DContinuity; - SharedPointer< Momentum > lF1DMomentum; - SharedPointer< Energy > lF1DEnergy; - - //rho - this->bindDofs( mesh, _u ); - lF1DContinuity->setTau(tau); - lF1DContinuity->setVelocity( *velocity); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Continuity, BoundaryCondition, RightHandSide > explicitUpdaterContinuity; - explicitUpdaterContinuity.template update< typename Mesh::Cell >( time, - mesh, - lF1DContinuity, - this->boundaryConditionsPointer, - this->rightHandSidePointer, - uRho, - fuRho ); - - - //rhoVelocity - lF1DMomentum->setTau(tau); - lF1DMomentum->setVelocity( *velocity); - lF1DMomentum->setPressure( *pressure); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Momentum, BoundaryCondition, RightHandSide > explicitUpdaterMomentum; - explicitUpdaterMomentum.template update< typename Mesh::Cell >( time, - mesh, - lF1DMomentum, - this->boundaryConditionsPointer, - this->rightHandSidePointer, - uRhoVelocity, - fuRhoVelocity ); - - //energy - lF1DEnergy->setTau(tau); - lF1DEnergy->setPressure( *pressure); - lF1DEnergy->setVelocity( *velocity); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Energy, BoundaryCondition, RightHandSide > explicitUpdaterEnergy; - explicitUpdaterEnergy.template update< typename Mesh::Cell >( time, - mesh, - lF1DEnergy, - this->boundaryConditionsPointer, - this->rightHandSidePointer, - uEnergy, - fuEnergy ); - } - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b, - MeshDependentDataPointer& meshDependentData ) -{ -/* LinearSystemAssembler< Mesh, - MeshFunctionType, - DifferentialOperator, - 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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -postIterate( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - //velocity - this->velocity->setMesh( mesh ); - Velocity velocityGetter( *uRho, *uRhoVelocity ); - *this->velocity = velocityGetter; - //pressure - this->pressure->setMesh( mesh ); - Pressure pressureGetter( *uRho, *uRhoVelocity, *uEnergy, gamma ); - *this->pressure = pressureGetter; - return true; -} - -} // namespace TNL - -#endif /* eulerPROBLEM_IMPL_H_ */ diff --git a/examples/inviscid-flow-sw/1d/tnl-run-euler-1d b/examples/inviscid-flow-sw/1d/tnl-run-euler-1d deleted file mode 100644 index 4829c27d0e0abfd000ce44e15687a8e85470ba0e..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/tnl-run-euler-1d +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -tnl-grid-setup --dimensions 1 \ - --origin-x 0.0 \ - --proportions-x 1.0 \ - --size-x 100 - -#tnl-init --test-function sin-wave \ -# --output-file init.tnl -tnl-euler-1d-dbg --time-discretisation explicit \ - --time-step 2.5e-3 \ - --boundary-conditions-type myneumann \ - --discrete-solver euler \ - --snapshot-period 0.015 \ - --final-time 0.15 \ - --left-density 1.0 \ - --left-velocity -2.0 \ - --left-pressure 0.4 \ - --right-density 1.0 \ - --right-velocity 2.0 \ - --right-pressure 0.4 \ - --gamma 1.4 \ - --riemann-border 0.5 \ - -tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/examples/inviscid-flow-sw/1d/tnl-run-euler-1d~ b/examples/inviscid-flow-sw/1d/tnl-run-euler-1d~ deleted file mode 100644 index 9f7b98e6b5c91803a473bebb1fcb92fa51f20c97..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/tnl-run-euler-1d~ +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -tnl-grid-setup --dimensions 1 \ - --origin-x 0.0 \ - --proportions-x 1.0 \ - --size-x 100 - -#tnl-init --test-function sin-wave \ -# --output-file init.tnl -~/bak/tnl/Debug/bin/tnl-euler-1d-dbg --time-discretisation explicit \ - --time-step 2.5e-3 \ - --boundary-conditions-type myneumann \ - --discrete-solver euler \ - --snapshot-period 0.015 \ - --final-time 0.15 \ - --left-density 1.0 \ - --left-velocity -2.0 \ - --left-pressure 0.4 \ - --right-density 1.0 \ - --right-velocity 2.0 \ - --right-pressure 0.4 \ - --gamma 1.4 \ - --riemann-border 0.5 \ - -tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/examples/inviscid-flow-sw/1d/tnlMyNeumannBoundaryConditions.h~ b/examples/inviscid-flow-sw/1d/tnlMyNeumannBoundaryConditions.h~ deleted file mode 100644 index d0a8e7ae0e8a560c4643b282cfb94310993a5a69..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/1d/tnlMyNeumannBoundaryConditions.h~ +++ /dev/null @@ -1,152 +0,0 @@ -/*** coppied and changed -/*************************************************************************** - tnlMyNeumannBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYNEUMANNBOUNDARYCONDITIONS_H_ -#define MYNEUMANNBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyNeumannBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - const IndexType& index = entity.getIndex(); - if( entity.getCoordinates().x() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 1 >() ]; - else - return u[ neighbourEntities.template getEntityIndex< -1 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyNeumannBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyNeumann boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* TNLMYNEUMANNBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/2d/Euler2DVelXGetter.h b/examples/inviscid-flow-sw/2d/Euler2DVelXGetter.h deleted file mode 100644 index 2e79798a31a7073241903891d0317502c8494a60..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/Euler2DVelXGetter.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef EulerVelXGetter_H -#define EulerVelXGetter_H - -#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 EulerVelXGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerVelXGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVel) - : rho( rho ), rhoVel( rhoVel ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - if (this->rho[ idx ]==0) return 0; else return this->rhoVel[ idx ] / this->rho[ idx ]; - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVel; - -}; - -} // namespace TNL - -#endif /* EulerVelXGetter_H */ diff --git a/examples/inviscid-flow-sw/2d/EulerPressureGetter.h~ b/examples/inviscid-flow-sw/2d/EulerPressureGetter.h~ deleted file mode 100644 index 23865afd3bfc98a36399e51b1822f775d05d616a..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/EulerPressureGetter.h~ +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef EulerPressureGetter_H -#define EulerPressureGetter_H - -#include <TNL/Containers/Vector.h> -#include <TNL/Meshes/Grid.h> -#include <TNL/Functions/Domain.h> - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class EulerPressureGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerPressureGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVelX, - const MeshFunctionType& rhoVelY, - const MeshFunctionType& energy, - const RealType& gamma ) - : rho( rho ), rhoVelX( rhoVelX ), rhoVelY( rhoVelY ), energy( energy ), gamma( gamma ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - if (this->rho[ idx ]==0) return 0 - else return ( this->gamma - 1.0 ) * ( this->energy[ idx ] - 0.5 * this->rho[ idx ] * - ( std::pow(this->rhoVelX[ idx ] / this->rho[ idx ],2) + std::pow(this->rhoVelY[ idx ] / this->rho[ idx ],2) ) ); -//*/ return ( this->gamma - 1.0 ) * ( this->energy[ idx ] * this->rho[ idx ] ); - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVelX; - - const MeshFunctionType& rhoVelY; - - const MeshFunctionType& energy; - - RealType gamma; - -}; - -} //namespace TNL - -#endif /* EulerPressureGetter_H */ diff --git a/examples/inviscid-flow-sw/2d/LaxFridrichsContinuity_impl .h~ b/examples/inviscid-flow-sw/2d/LaxFridrichsContinuity_impl .h~ deleted file mode 100644 index 539e574c96d6171a40407e58803d5c81e1f50acd..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/LaxFridrichsContinuity_impl .h~ +++ /dev/null @@ -1,349 +0,0 @@ -#ifndef LaxFridrichsContinuity_IMPL_H -#define LaxFridrichsContinuity_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return 0;/*( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse;*/ -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - //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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return (0.25 / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * ( u[ east ] * this->velocityX[ east ] - u[ west ] * this->velocityX[ west ] ) - - 0.5 * hyInverse * ( u[ north ] * this->velocityY[ north ] - u[ south ] * this->velocityY[ south ] ); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse + - ( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse + - ( u[ up ] - 2.0 * u[ center ] + u[ down ] ) * hzSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} //namespace TNL - -#endif /* LaxFridrichsContinuityIMPL_H */ - diff --git a/examples/inviscid-flow-sw/2d/MyMixedBoundaryConditions.h b/examples/inviscid-flow-sw/2d/MyMixedBoundaryConditions.h deleted file mode 100644 index 066600f483d7e7bcf2adbb0cb6c68ad73eda52a6..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/MyMixedBoundaryConditions.h +++ /dev/null @@ -1,175 +0,0 @@ -// coppied and changed -/*************************************************************************** - tnlMyMixedBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYMIXEDBOUNDARYCONDITIONS_H_ -#define MYMIXEDBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyMixedBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - typedef typename MeshType::Cell Cell; - int count = mesh.template getEntitiesCount< Cell >(); - count = std::sqrt(count); - float x0 = 0.5; - if( entity.getCoordinates().x() == 0 ) - { - if ( entity.getCoordinates().y() < count * x0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - else if( entity.getCoordinates().y() < count -1 ) - return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - else if( entity.getCoordinates().y() == 0 ) - { - if ( entity.getCoordinates().x() < count * x0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - else if( entity.getCoordinates().x() < count -1 ) - return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - else if( entity.getCoordinates().x() == count ) - return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ]; - else return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyMixedBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyMixed boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYMIXEDBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/2d/MyNeumannBoundaryConditions.h b/examples/inviscid-flow-sw/2d/MyNeumannBoundaryConditions.h deleted file mode 100644 index 72285a4ae0b46ace0750012d0923500e9b61829b..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/MyNeumannBoundaryConditions.h +++ /dev/null @@ -1,157 +0,0 @@ -//** coppied and changed -/*************************************************************************** - tnlMyNeumannBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYNEUMANNBOUNDARYCONDITIONS_H_ -#define MYNEUMANNBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyNeumannBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return true; //Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - typedef typename MeshType::Cell Cell; - int count = mesh.template getEntitiesCount< Cell >(); - count = std::sqrt(count); - if( entity.getCoordinates().x() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ]; - else if( entity.getCoordinates().x() == count-1 ) - return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ]; - else if( entity.getCoordinates().y() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ]; - else return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyNeumannBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyNeumann boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYNEUMANNBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/2d/MyNeumannBoundaryConditions.h~ b/examples/inviscid-flow-sw/2d/MyNeumannBoundaryConditions.h~ deleted file mode 100644 index 680e3751f93c8a2f23115f87b769f3480b9e7974..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/MyNeumannBoundaryConditions.h~ +++ /dev/null @@ -1,157 +0,0 @@ -//** coppied and changed -/*************************************************************************** - tnlMyNeumannBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYNEUMANNBOUNDARYCONDITIONS_H_ -#define MYNEUMANNBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyNeumannBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return true //Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - typedef typename MeshType::Cell Cell; - int count = mesh.template getEntitiesCount< Cell >(); - count = std::sqrt(count); - if( entity.getCoordinates().x() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ]; - else if( entity.getCoordinates().x() == count-1 ) - return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ]; - else if( entity.getCoordinates().y() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ]; - else return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyNeumannBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyNeumann boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYNEUMANNBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/2d/eulerProblem_impl.h~ b/examples/inviscid-flow-sw/2d/eulerProblem_impl.h~ deleted file mode 100644 index 3800566e1ed4a0b467215daf7962eb60ee132eff..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/eulerProblem_impl.h~ +++ /dev/null @@ -1,450 +0,0 @@ -#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 "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "EulerPressureGetter.h" -#include "Euler2DVelXGetter.h" -#include "EulerVelGetter.h" -#include "MyMixedBoundaryConditions.h" -#include "MyNeumannBoundaryConditions.h" - -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getTypeStatic() -{ - return String( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getPrologHeader() const -{ - return String( "euler2D" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( //! this->boundaryConditionPointer->setup( meshPointer, parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::IndexType -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 4*mesh->template getEntitiesCount< typename MeshType::Cell >(); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -bindDofs( const MeshPointer& mesh, - DofVectorPointer& dofVector ) -{ -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - typedef typename MeshType::Cell Cell; - gamma = parameters.getParameter< RealType >( "gamma" ); - RealType rhoLu = parameters.getParameter< RealType >( "NW-density" ); - RealType velLuX = parameters.getParameter< RealType >( "NW-velocityX" ); - RealType velLuY = parameters.getParameter< RealType >( "NW-velocityY" ); - RealType preLu = parameters.getParameter< RealType >( "NW-pressure" ); - //RealType eLu = ( preLu / ( rhoLu * (gamma - 1) ) ); - RealType eLu = ( preLu / (gamma - 1) ) + 0.5 * rhoLu * ( std::pow(velLuX,2)+std::pow(velLuY,2) ); - std::cout << rhoLu <<' '<< velLuX<<' '<<velLuY<<' '<<preLu<<' '<<eLu<<' '; - RealType rhoLd = parameters.getParameter< RealType >( "SW-density" ); - RealType velLdX = parameters.getParameter< RealType >( "SW-velocityX" ); - RealType velLdY = parameters.getParameter< RealType >( "SW-velocityY" ); - RealType preLd = parameters.getParameter< RealType >( "SW-pressure" ); - //RealType eLd = ( preLd / ( rhoLd * (gamma - 1) ) ); - RealType eLd = ( preLd / (gamma - 1) ) + 0.5 * rhoLd * ( std::pow(velLdX,2)+std::pow(velLdY,2) ); - std::cout << rhoLd <<' '<< velLdX<<' '<<velLdY<<' '<<preLd<<' '<<eLd<<' '; - RealType rhoRu = parameters.getParameter< RealType >( "NE-density" ); - RealType velRuX = parameters.getParameter< RealType >( "NE-velocityX" ); - RealType velRuY = parameters.getParameter< RealType >( "NE-velocityY" ); - RealType preRu = parameters.getParameter< RealType >( "NE-pressure" ); - //RealType eRu = ( preRu / ( rhoRu * (gamma - 1) ) ); - RealType eRu = ( preRu / (gamma - 1) ) + 0.5 * rhoRu * ( std::pow(velRuX,2)+std::pow(velRuY,2) ); - std::cout << rhoRu <<' '<< velRuX<<' '<<velRuY<<' '<<preRu<<' '<<eRu<<' '; - RealType rhoRd = parameters.getParameter< RealType >( "SE-density" ); - RealType velRdX = parameters.getParameter< RealType >( "SE-velocityX" ); - RealType velRdY = parameters.getParameter< RealType >( "SE-velocityY" ); - RealType preRd = parameters.getParameter< RealType >( "SE-pressure" ); - //RealType eRd = ( preRd / ( rhoRd * (gamma - 1) ) ); - RealType eRd = ( preRd / (gamma - 1) ) + 0.5 * rhoRd * ( std::pow(velRdX,2)+std::pow(velRdY,2) ); - RealType x0 = parameters.getParameter< RealType >( "riemann-border" ); - int size = mesh->template getEntitiesCount< Cell >(); - uRho->bind(mesh, dofs, 0); - uRhoVelocityX->bind(mesh, dofs, size); - uRhoVelocityY->bind(mesh, dofs, 2*size); - uEnergy->bind(mesh, dofs, 3*size); - Containers::Vector< RealType, DeviceType, IndexType > data; - data.setSize(4*size); - pressure->bind(mesh, data, 0); - velocity->bind(mesh, data, size); - velocityX->bind(mesh, data, 2*size); - velocityY->bind(mesh, data, 3*size); - for(IndexType j = 0; j < std::sqrt(size); j++) - for(IndexType i = 0; i < std::sqrt(size); i++) - if ((i <= x0 * std::sqrt(size))&&(j <= x0 * std::sqrt(size)) ) - { - (* uRho)[j*std::sqrt(size)+i] = rhoLd; - (* uRhoVelocityX)[j*std::sqrt(size)+i] = rhoLd * velLdX; - (* uRhoVelocityY)[j*std::sqrt(size)+i] = rhoLd * velLdY; - (* uEnergy)[j*std::sqrt(size)+i] = eLd; - (* velocity)[j*std::sqrt(size)+i] = std::sqrt(std::pow(velLdX,2)+std::pow(velLdY,2)); - (* velocityX)[j*std::sqrt(size)+i] = velLdX; - (* velocityY)[j*std::sqrt(size)+i] = velLdY; - (* pressure)[j*std::sqrt(size)+i] = preLd; - } - else - if ((i <= x0 * std::sqrt(size))&&(j > x0 * std::sqrt(size)) ) - { - (* uRho)[j*std::sqrt(size)+i] = rhoLu; - (* uRhoVelocityX)[j*std::sqrt(size)+i] = rhoLu * velLuX; - (* uRhoVelocityY)[j*std::sqrt(size)+i] = rhoLu * velLuY; - (* uEnergy)[j*std::sqrt(size)+i] = eLu; - (* velocity)[j*std::sqrt(size)+i] = std::sqrt(std::pow(velLuX,2)+std::pow(velLuY,2)); - (* velocityX)[j*std::sqrt(size)+i] = velLuX; - (* velocityY)[j*std::sqrt(size)+i] = velLuY; - (* pressure)[j*std::sqrt(size)+i] = preLu; - } - else - if ((i > x0 * std::sqrt(size))&&(j > x0 * std::sqrt(size)) ) - { - (* uRho)[j*std::sqrt(size)+i] = rhoRu; - (* uRhoVelocityX)[j*std::sqrt(size)+i] = rhoRu * velRuX; - (* uRhoVelocityY)[j*std::sqrt(size)+i] = rhoRu * velRuY; - (* uEnergy)[j*std::sqrt(size)+i] = eRu; - (* velocity)[j*std::sqrt(size)+i] = std::sqrt(std::pow(velRuX,2)+std::pow(velRuY,2)); - (* velocityX)[j*std::sqrt(size)+i] = velRuX; - (* velocityY)[j*std::sqrt(size)+i] = velRuY; - (* pressure)[j*std::sqrt(size)+i] = preRu; - } - else - { - (* uRho)[j*std::sqrt(size)+i] = rhoRd; - (* uRhoVelocityX)[j*std::sqrt(size)+i] = rhoRd * velRdX; - (* uRhoVelocityY)[j*std::sqrt(size)+i] = rhoRd * velRdY; - (* uEnergy)[j*std::sqrt(size)+i] = eRd; - (* velocity)[j*std::sqrt(size)+i] = std::sqrt(std::pow(velRdX,2)+std::pow(velRdY,2)); - (* velocityX)[j*std::sqrt(size)+i] = velRdX; - (* velocityY)[j*std::sqrt(size)+i] = velRdY; - (* pressure)[j*std::sqrt(size)+i] = preRd; - }; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setupLinearSystem( const MeshPointer& mesh, - Matrix& matrix ) -{ -/* const IndexType dofs = this->getDofs( mesh ); - typedef typename Matrix::CompressedRowsLengthsVector CompressedRowsLengthsVectorType; - CompressedRowsLengthsVectorType rowLengths; - if( ! rowLengths.setSize( dofs ) ) - return false; - MatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, CompressedRowsLengthsVectorType > matrixSetter; - matrixSetter.template getCompressedRowsLengths< typename Mesh::Cell >( mesh, - differentialOperator, - boundaryCondition, - rowLengths ); - matrix.setDimensions( dofs, dofs ); - if( ! matrix.setCompressedRowsLengths( rowLengths ) ) - return false;*/ - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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; - FileName fileName; - fileName.setExtension( "tnl" ); - fileName.setIndex( step ); - fileName.setFileNameBase( "rho-" ); - if( ! uRho->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelX-" ); - if( ! uRhoVelocityX->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelY-" ); - if( ! uRhoVelocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "energy-" ); - if( ! uEnergy->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityX-" ); - if( ! velocityX->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityY-" ); - if( ! velocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocity-" ); - if( ! velocity->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "pressure-" ); - if( ! pressure->save( fileName.getFileName() ) ) - return false; - - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getExplicitRHS( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - DofVectorPointer& _fu, - MeshDependentDataPointer& meshDependentData ) -{ - typedef typename MeshType::Cell Cell; - int count = mesh->template getEntitiesCount< Cell >(); - //bind MeshFunctionType fu - fuRho->bind( mesh, _fu, 0 ); - fuRhoVelocityX->bind( mesh, _fu, count ); - fuRhoVelocityY->bind( mesh, _fu, 2*count ); - fuEnergy->bind( mesh, _fu, 3*count ); - SharedPointer< Continuity > lF2DContinuity; - SharedPointer< MomentumX > lF2DMomentumX; - SharedPointer< MomentumY > lF2DMomentumY; - SharedPointer< Energy > lF2DEnergy; - - this->bindDofs( mesh, _u ); - //rho - lF2DContinuity->setTau(tau); - lF2DContinuity->setVelocityX( *velocityX ); - lF2DContinuity->setVelocityY( *velocityY ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Continuity, BoundaryCondition, RightHandSide > explicitUpdaterContinuity; - explicitUpdaterContinuity.template update< typename Mesh::Cell >( time, - mesh, - lF2DContinuity, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRho, - fuRho ); - - //rhoVelocityX - lF2DMomentumX->setTau(tau); - lF2DMomentumX->setVelocityX( *velocityX ); - lF2DMomentumX->setVelocityY( *velocityY ); - lF2DMomentumX->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumX, BoundaryCondition, RightHandSide > explicitUpdaterMomentumX; - explicitUpdaterMomentumX.template update< typename Mesh::Cell >( time, - mesh, - lF2DMomentumX, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityX, - fuRhoVelocityX ); - - //rhoVelocityY - lF2DMomentumY->setTau(tau); - lF2DMomentumY->setVelocityX( *velocityX ); - lF2DMomentumY->setVelocityY( *velocityY ); - lF2DMomentumY->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumY, BoundaryCondition, RightHandSide > explicitUpdaterMomentumY; - explicitUpdaterMomentumY.template update< typename Mesh::Cell >( time, - mesh, - lF2DMomentumY, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityY, - fuRhoVelocityY ); - - //energy - lF2DEnergy->setTau(tau); - lF2DEnergy->setVelocityX( *velocityX ); - lF2DEnergy->setVelocityY( *velocityY ); - lF2DEnergy->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Energy, BoundaryCondition, RightHandSide > explicitUpdaterEnergy; - explicitUpdaterEnergy.template update< typename Mesh::Cell >( time, - mesh, - lF2DEnergy, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uEnergy, - fuEnergy ); -/* -cout << "rho " << uRho.getData() << endl; -getchar(); -cout << "rhoVelX " << uRhoVelocityX.getData() << endl; -getchar(); -cout << "rhoVelY " << uRhoVelocityY.getData() << endl; -getchar(); -cout << "Energy " << uEnergy.getData() << endl; -getchar(); -cout << "velocity " << velocity.getData() << endl; -getchar(); -cout << "velocityX " << velocityX.getData() << endl; -getchar(); -cout << "velocityY " << velocityY.getData() << endl; -getchar(); -cout << "pressure " << pressure.getData() << endl; -getchar(); -*/ - - -/* - BoundaryConditionsSetter< MeshFunctionType, BoundaryCondition > boundaryConditionsSetter; - boundaryConditionsSetter.template apply< typename Mesh::Cell >( - this->boundaryCondition, - time + tau, - u );*/ - } - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b, - MeshDependentDataPointer& meshDependentData ) -{ -/* LinearSystemAssembler< Mesh, - MeshFunctionType, - DifferentialOperator, - 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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -postIterate( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - - //velocityX - this->velocityX->setMesh( mesh ); - VelocityX velocityXGetter( *uRho, *uRhoVelocityX ); - *this->velocityX = velocityXGetter; - - //velocityY - this->velocityY->setMesh( mesh ); - VelocityX velocityYGetter( *uRho, *uRhoVelocityY ); - *this->velocityY = velocityYGetter; - - //velocity - this->velocity->setMesh( mesh ); - Velocity velocityGetter( *uRho, *uRhoVelocityX, *uRhoVelocityY ); - *this->velocity = velocityGetter; - - //pressure - this->pressure->setMesh( mesh ); - Pressure pressureGetter( *uRho, *uRhoVelocityX, *uRhoVelocityY, *uEnergy, gamma ); - *this->pressure = pressureGetter; - - return true; -} - -} // namespace TNL - diff --git a/examples/inviscid-flow-sw/2d/tnl-run-euler-2d b/examples/inviscid-flow-sw/2d/tnl-run-euler-2d deleted file mode 100644 index 463dd3506a739fb8239abcf8d544dc0ac94610bd..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/tnl-run-euler-2d +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 400 \ - --size-y 400 - -#tnl-init --test-function sin-wave \ -# --output-file init.tnl -# --boundary-conditions-type neumann \ -# --boundary-conditions-constant 0 \ - -tnl-euler-2d-dbg --time-discretisation explicit \ - --time-step 5.0e-4 \ - --boundary-conditions-type myneumann \ - --discrete-solver euler \ - --snapshot-period 0.03 \ - --final-time 0.3 \ - --NW-density 0.5323 \ - --NW-velocityX 1.206 \ - --NW-velocityY 0.0 \ - --NW-pressure 0.3 \ - --NE-density 1.5 \ - --NE-velocityX 0.0 \ - --NE-velocityY 0.0 \ - --NE-pressure 1.5 \ - --SW-density 0.138 \ - --SW-velocityX 1.206 \ - --SW-velocityY 1.206 \ - --SW-pressure 0.029 \ - --SE-density 0.5323 \ - --SE-velocityX 0 \ - --SE-velocityY 1.206 \ - --SE-pressure 0.3 \ - --gamma 1.4 \ - --riemann-border 0.5 \ - -tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/examples/inviscid-flow-sw/2d/tnl-run-euler-2d~ b/examples/inviscid-flow-sw/2d/tnl-run-euler-2d~ deleted file mode 100644 index 05cfd80b5c9b6130a0233b08dfd74932f3f99930..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/2d/tnl-run-euler-2d~ +++ /dev/null @@ -1,42 +0,0 @@ -#!/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 400 \ - --size-y 400 - -#tnl-init --test-function sin-wave \ -# --output-file init.tnl -# --boundary-conditions-type neumann \ -# --boundary-conditions-constant 0 \ - -tnl-euler-2d-dbg --time-discretisation explicit \ - --time-step 5.0e-4 \ - --boundary-conditions-type myneumann \ - --discrete-solver euler \ - --snapshot-period 0.03 \ - --final-time 0.3 \ - --NW-density 0.5323 \ - --NW-velocityX 1.206 \ - --NW-velocityY 0.0 \ - --NW-pressure 0.3 \ - --NE-density 1.5 \ - --NE-velocityX 0.0 \ - --NE-velocityY 0.0 \ - --NE-pressure 1.5 \ - --SW-density 0.138 \ - --SW-velocityX 1.206 \ - --SW-velocityY 1.206 \ - --SW-pressure 0.029 \ - --SE-density 0.5323 \ - --SE-velocityX 0 \ - --SE-velocityY 1.206 \ - --SE-pressure 0.3 \ - --gamma 1.4 \ - --riemann-border 0.5 \ - -tnl-view --mesh mesh.tnl --input-files *tnl -tnl-view --mesh mesh.tnl --input-files *tnl --output-format vtk diff --git a/examples/inviscid-flow-sw/3d/CMakeLists.txt b/examples/inviscid-flow-sw/3d/CMakeLists.txt deleted file mode 100644 index 41096a73a7a5070d15e56d2da7111cbbf85ebf2d..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -set( tnl_heat_equation_SOURCES - euler.cpp - euler-cuda.cu ) - -IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE(tnl-euler-3d${debugExt} euler-cuda.cu) - target_link_libraries (tnl-euler-3d${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE(tnl-euler-3d${debugExt} euler.cpp) - target_link_libraries (tnl-euler-3d${debugExt} tnl${debugExt}-${tnlVersion} ) -ENDIF( BUILD_CUDA ) - - -INSTALL( TARGETS tnl-euler-3d${debugExt} - RUNTIME DESTINATION bin - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) - -INSTALL( FILES run-euler - ${tnl_heat_equation_SOURCES} - DESTINATION share/tnl-${tnlVersion}/examples/inviscid-flow-3d ) - diff --git a/examples/inviscid-flow-sw/3d/CMakeLists.txt~ b/examples/inviscid-flow-sw/3d/CMakeLists.txt~ deleted file mode 100644 index d753d50afcc11a2fccbe04e30410c77e8a5c1f81..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/CMakeLists.txt~ +++ /dev/null @@ -1,21 +0,0 @@ -set( tnl_heat_equation_SOURCES - euler.cpp - euler-cuda.cu ) - -IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE(tnl-euler-2d${debugExt} euler-cuda.cu) - target_link_libraries (tnl-euler-2d${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE(tnl-euler-2d${debugExt} euler.cpp) - target_link_libraries (tnl-euler-2d${debugExt} tnl${debugExt}-${tnlVersion} ) -ENDIF( BUILD_CUDA ) - - -INSTALL( TARGETS tnl-euler-2d${debugExt} - RUNTIME DESTINATION bin - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) - -INSTALL( FILES run-euler - ${tnl_heat_equation_SOURCES} - DESTINATION share/tnl-${tnlVersion}/examples/inviscid-flow-2d ) - diff --git a/examples/inviscid-flow-sw/3d/Euler2DVelXGetter.h b/examples/inviscid-flow-sw/3d/Euler2DVelXGetter.h deleted file mode 100644 index 2e79798a31a7073241903891d0317502c8494a60..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/Euler2DVelXGetter.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef EulerVelXGetter_H -#define EulerVelXGetter_H - -#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 EulerVelXGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerVelXGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVel) - : rho( rho ), rhoVel( rhoVel ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - if (this->rho[ idx ]==0) return 0; else return this->rhoVel[ idx ] / this->rho[ idx ]; - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVel; - -}; - -} // namespace TNL - -#endif /* EulerVelXGetter_H */ diff --git a/examples/inviscid-flow-sw/3d/Euler2DVelXGetter.h~ b/examples/inviscid-flow-sw/3d/Euler2DVelXGetter.h~ deleted file mode 100644 index 224aa61fb8980cabf3270b84aed36c03190e783d..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/Euler2DVelXGetter.h~ +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef EulerVelXGetter_H -#define EulerVelXGetter_H - -#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 EulerVelXGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerVelXGetter( const MeshFunctionType& rho, - /*const MeshFunctionType& rhoVel*/) - : rho( rho ), rhoVel( rhoVel ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - if (this->rho[ idx ]==0) return 0; else return this->rhoVel[ idx ] / this->rho[ idx ]; - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVel; - -}; - -} // namespace TNL - -#endif /* EulerVelXGetter_H */ diff --git a/examples/inviscid-flow-sw/3d/EulerPressureGetter.h b/examples/inviscid-flow-sw/3d/EulerPressureGetter.h deleted file mode 100644 index 45611c64754aa161274bdabe95cd0c60565ef2c1..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/EulerPressureGetter.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef EulerPressureGetter_H -#define EulerPressureGetter_H - -#include <TNL/Containers/Vector.h> -#include <TNL/Meshes/Grid.h> -#include <TNL/Functions/Domain.h> - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class EulerPressureGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerPressureGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVelX, - const MeshFunctionType& rhoVelY, - const MeshFunctionType& rhoVelZ, - const MeshFunctionType& energy, - const RealType& gamma ) - : rho( rho ), rhoVelX( rhoVelX ), rhoVelY( rhoVelY ), rhoVelZ( rhoVelZ ), energy( energy ), gamma( gamma ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { -/* if (this->rho[ idx ]==0) return 0; - else return ( this->gamma - 1.0 ) * ( this->energy[ idx ] - 0.5 * this->rho[ idx ] * - ( std::pow(this->rhoVelX[ idx ] / this->rho[ idx ],2) + std::pow(this->rhoVelY[ idx ] / this->rho[ idx ],2) + std::pow(this->rhoVelZ[ idx ] / this->rho[ idx ],2) ); -*/ return ( this->gamma - 1.0 ) * ( this->energy[ idx ] * this->rho[ idx ] ); - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVelX; - - const MeshFunctionType& rhoVelY; - - const MeshFunctionType& rhoVelZ; - - const MeshFunctionType& energy; - - RealType gamma; - -}; - -} //namespace TNL - -#endif /* EulerPressureGetter_H */ diff --git a/examples/inviscid-flow-sw/3d/EulerPressureGetter.h~ b/examples/inviscid-flow-sw/3d/EulerPressureGetter.h~ deleted file mode 100644 index 45611c64754aa161274bdabe95cd0c60565ef2c1..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/EulerPressureGetter.h~ +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef EulerPressureGetter_H -#define EulerPressureGetter_H - -#include <TNL/Containers/Vector.h> -#include <TNL/Meshes/Grid.h> -#include <TNL/Functions/Domain.h> - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class EulerPressureGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerPressureGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVelX, - const MeshFunctionType& rhoVelY, - const MeshFunctionType& rhoVelZ, - const MeshFunctionType& energy, - const RealType& gamma ) - : rho( rho ), rhoVelX( rhoVelX ), rhoVelY( rhoVelY ), rhoVelZ( rhoVelZ ), energy( energy ), gamma( gamma ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { -/* if (this->rho[ idx ]==0) return 0; - else return ( this->gamma - 1.0 ) * ( this->energy[ idx ] - 0.5 * this->rho[ idx ] * - ( std::pow(this->rhoVelX[ idx ] / this->rho[ idx ],2) + std::pow(this->rhoVelY[ idx ] / this->rho[ idx ],2) + std::pow(this->rhoVelZ[ idx ] / this->rho[ idx ],2) ); -*/ return ( this->gamma - 1.0 ) * ( this->energy[ idx ] * this->rho[ idx ] ); - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVelX; - - const MeshFunctionType& rhoVelY; - - const MeshFunctionType& rhoVelZ; - - const MeshFunctionType& energy; - - RealType gamma; - -}; - -} //namespace TNL - -#endif /* EulerPressureGetter_H */ diff --git a/examples/inviscid-flow-sw/3d/EulerVelGetter.h b/examples/inviscid-flow-sw/3d/EulerVelGetter.h deleted file mode 100644 index 24d06eaf5f0ce322c17086ea2cf04495c96bd3e7..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/EulerVelGetter.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef EulerVelGetter_H -#define EulerVelGetter_H - -#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 EulerVelGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerVelGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVelX, - const MeshFunctionType& rhoVelY, - const MeshFunctionType& rhoVelZ) - : rho( rho ), rhoVelX( rhoVelX ), rhoVelY( rhoVelY ), rhoVelZ( rhoVelZ ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - if (this->rho[ idx ]==0) return 0; else return std::sqrt( std::pow( this->rhoVelX[ idx ] / this->rho[ idx ], 2) + std::pow( this->rhoVelY[ idx ] / this->rho[ idx ], 2) + std::pow( this->rhoVelZ[ idx ] / this->rho[ idx ], 2) ) ; - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVelX; - - const MeshFunctionType& rhoVelY; - - const MeshFunctionType& rhoVelZ; - -}; - -} // namespace TNL - -#endif /* EulerVelGetter_H */ diff --git a/examples/inviscid-flow-sw/3d/EulerVelGetter.h~ b/examples/inviscid-flow-sw/3d/EulerVelGetter.h~ deleted file mode 100644 index 888529954b7bda073ad8dc55e712417e8b5eb188..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/EulerVelGetter.h~ +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef EulerVelGetter_H -#define EulerVelGetter_H - -#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 EulerVelGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerVelGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVelX, - const MeshFunctionType& rhoVelY, - const MeshFunctionType& rhoVelZ) - : rho( rho ), rhoVelX( rhoVelX ), rhoVelY( rhoVelY ), rhoVelZ( rhoVelZ ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - if (this->rho[ idx ]==0) return 0; else return std::sqrt( std::pow( this->rhoVelX[ idx ] / this->rho[ idx ], 2) + std::pow( this->rhoVelY[ idx ] / this->rho[ idx ], 2) + std::pow( this->rhoVelZ[ idx ] / this->rho[ idx ], 2) ) ; - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVelX; - - const MeshFunctionType& rhoVelY; - -}; - -} // namespace TNL - -#endif /* EulerVelGetter_H */ diff --git a/examples/inviscid-flow-sw/3d/EulerVelXGetter.h~ b/examples/inviscid-flow-sw/3d/EulerVelXGetter.h~ deleted file mode 100644 index 54a29d6accee6808c78c0ba883fedb7a6701e9fb..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/EulerVelXGetter.h~ +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef EulerVelXGetter_H -#define EulerVelXGetter_H - -#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 EulerVelXGetter -: public Functions::Domain< Mesh::getMeshDimensions(), Functions::MeshDomain > -{ - public: - - typedef Mesh MeshType; - typedef typename MeshType::DeviceType DeviceType; - typedef Real RealType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - - EulerVelXGetter( const MeshFunctionType& rho, - const MeshFunctionType& rhoVel) - : rho( rho ), rhoVel( rhoVel ) - {} - - template< typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - return this->operator[]( entity.getIndex() ); - } - - __cuda_callable__ - Real operator[]( const IndexType& idx ) const - { - if (this->rho[ idx ]==0) return 0; else return this->rhoVel[ idx ] / this->rho[ idx ]; - } - - - protected: - - const MeshFunctionType& rho; - - const MeshFunctionType& rhoVel; - -}; - -} // namespace TNL - -#endif /* EulerVelXGetter_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichs2D.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichs2D.h~ deleted file mode 100644 index 447569fa4439baecd1a2c6b60828fb027be1b8fd..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichs2D.h~ +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef LaxFridrichs2D_H -#define LaxFridrichs2D_H - -#include <TNL/Containers/Vector.h> -#include <TNL/Meshes/Grid.h> -#include "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "LaxFridrichsMomentumZ.h" -#include "EulerPressureGetter.h" -#include "Euler2DVelXGetter.h" -#include "EulerVelGetter.h" - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class LaxFridrichs2D -{ - public: - typedef Real RealType; - typedef typename Mesh::DeviceType DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - - typedef LaxFridrichsContinuity< Mesh, Real, Index > Continuity; - typedef LaxFridrichsMomentumX< Mesh, Real, Index > MomentumX; - typedef LaxFridrichsMomentumY< Mesh, Real, Index > MomentumY; - typedef LaxFridrichsMomentumZ< Mesh, Real, Index > MomentumZ; - typedef LaxFridrichsEnergy< Mesh, Real, Index > Energy; - typedef EulerVelXGetter< Mesh, Real, Index > VelocityX; - typedef EulerVelGetter< Mesh, Real, Index > Velocity; - typedef EulerPressureGetter< Mesh, Real, Index > Pressure; - -}; - -} //namespace TNL - -#endif /* LaxFridrichs2D_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichs3D.h b/examples/inviscid-flow-sw/3d/LaxFridrichs3D.h deleted file mode 100644 index 57c9fe6b4e676a0fe2c352823be5b1c1b26cd71e..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichs3D.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef LaxFridrichs3D_H -#define LaxFridrichs3D_H - -#include <TNL/Containers/Vector.h> -#include <TNL/Meshes/Grid.h> -#include "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "LaxFridrichsMomentumZ.h" -#include "EulerPressureGetter.h" -#include "Euler2DVelXGetter.h" -#include "EulerVelGetter.h" - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class LaxFridrichs3D -{ - public: - typedef Real RealType; - typedef typename Mesh::DeviceType DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - - typedef LaxFridrichsContinuity< Mesh, Real, Index > Continuity; - typedef LaxFridrichsMomentumX< Mesh, Real, Index > MomentumX; - typedef LaxFridrichsMomentumY< Mesh, Real, Index > MomentumY; - typedef LaxFridrichsMomentumZ< Mesh, Real, Index > MomentumZ; - typedef LaxFridrichsEnergy< Mesh, Real, Index > Energy; - typedef EulerVelXGetter< Mesh, Real, Index > VelocityX; - typedef EulerVelGetter< Mesh, Real, Index > Velocity; - typedef EulerPressureGetter< Mesh, Real, Index > Pressure; - -}; - -} //namespace TNL - -#endif /* LaxFridrichs3D_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichs3D.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichs3D.h~ deleted file mode 100644 index b67b594d8ce51a3cfff67c16192a070ae7a5a18d..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichs3D.h~ +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef LaxFridrichs3D_H -#define LaxFridrichs3D_H - -#include <TNL/Containers/Vector.h> -#include <TNL/Meshes/Grid.h> -#include "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "LaxFridrichsMomentumZ.h" -#include "EulerPressureGetter.h" -#include "Euler2DVelXGetter.h" -#include "EulerVelGetter.h" - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class LaxFridrichs3D -{ - public: - typedef Real RealType; - typedef typename Mesh::DeviceType DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - - typedef LaxFridrichsContinuity< Mesh, Real, Index > Continuity; - typedef LaxFridrichsMomentumX< Mesh, Real, Index > MomentumX; - typedef LaxFridrichsMomentumY< Mesh, Real, Index > MomentumYl; - typedef LaxFridrichsMomentumZ< Mesh, Real, Index > MomentumZ; - typedef LaxFridrichsEnergy< Mesh, Real, Index > Energy; - typedef EulerVelXGetter< Mesh, Real, Index > VelocityX; - typedef EulerVelGetter< Mesh, Real, Index > Velocity; - typedef EulerPressureGetter< Mesh, Real, Index > Pressure; - -}; - -} //namespace TNL - -#endif /* LaxFridrichs3D_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity.h~ deleted file mode 100644 index e60778edce33dfeae736bcf308b60d58e9618146..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity.h~ +++ /dev/null @@ -1,210 +0,0 @@ -#ifndef LaxFridrichsContinuity_H -#define LaxFridrichsContinuity_H - -#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 LaxFridrichsContinuity -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - -#include "LaxFridrichsContinuity_impl .h" - -#endif /* LaxFridrichsContinuity_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity_impl .h b/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity_impl .h deleted file mode 100644 index ac469a52407477aab2d8a60c3eca92e5d168a253..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity_impl .h +++ /dev/null @@ -1,350 +0,0 @@ -#ifndef LaxFridrichsContinuity_IMPL_H -#define LaxFridrichsContinuity_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - //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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return (0.25 / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * ( u[ east ] * this->velocityX[ east ] - u[ west ] * this->velocityX[ west ] ) - - 0.5 * hyInverse * ( u[ north ] * this->velocityY[ north ] - u[ south ] * this->velocityY[ south ] ); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ((1.0/6.0) / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] + u[ up ] + u[ down ] - 6.0 * u[ center ] ) - - 0.5 * hxInverse * ( u[ east ] * this->velocityX[ east ] - u[ west ] * this->velocityX[ west ] ) - - 0.5 * hyInverse * ( u[ north ] * this->velocityY[ north ] - u[ south ] * this->velocityY[ south ] ) - - 0.5 * hzInverse * ( u[ up ] * this->velocityZ[ up ] - u[ down ] * this->velocityZ[ down ] ); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} //namespace TNL - -#endif /* LaxFridrichsContinuityIMPL_H */ - diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity_impl .h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity_impl .h~ deleted file mode 100644 index c76e2ec4490e314b6fcea004b5dad778e1648502..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsContinuity_impl .h~ +++ /dev/null @@ -1,350 +0,0 @@ -#ifndef LaxFridrichsContinuity_IMPL_H -#define LaxFridrichsContinuity_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - //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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return (0.25 / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * ( u[ east ] * this->velocityX[ east ] - u[ west ] * this->velocityX[ west ] ) - - 0.5 * hyInverse * ( u[ north ] * this->velocityY[ north ] - u[ south ] * this->velocityY[ suoth ] ); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsContinuity< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ((1.0/6.0) / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] + u[ up ] + u[ down ] - 6.0 * u[ center ] ) - - 0.5 * hxInverse * ( u[ east ] * this->velocityX[ east ] - u[ west ] * this->velocityX[ west ] ) - - 0.5 * hyInverse * ( u[ north ] * this->velocityY[ north ] - u[ south ] * this->velocityY[ south ] ) - - 0.5 * hzInverse * ( u[ up ] * this->velocityZ[ up ] - u[ down ] * this->velocityZ[ down ] ); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} //namespace TNL - -#endif /* LaxFridrichsContinuityIMPL_H */ - diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy.h b/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy.h deleted file mode 100644 index 9083970ae4bb036b2be46e8556dab2e4f8eb2607..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef LaxFridrichsEnergy_H -#define LaxFridrichsEnergy_H - -#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 LaxFridrichsEnergy -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - - -#include "LaxFridrichsEnergy_impl.h" - -#endif /* LaxFridrichsEnergy_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy.h~ deleted file mode 100644 index d531664fd6b00446c7a72d7f189f3a192c57655c..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy.h~ +++ /dev/null @@ -1,219 +0,0 @@ -#ifndef LaxFridrichsEnergy_H -#define LaxFridrichsEnergy_H - -#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 LaxFridrichsEnergy -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - - -#include "LaxFridrichsEnergy_impl.h" - -#endif /* LaxFridrichsEnergy_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy_impl.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy_impl.h~ deleted file mode 100644 index e52cfe4015e232db2df6048ec45150a945aaac5e..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsEnergy_impl.h~ +++ /dev/null @@ -1,350 +0,0 @@ -#ifndef LaxFridrichsEnergy_IMPL_H -#define LaxFridrichsEnergy_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsEnergy< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsEnergy< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - //energy - 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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return (0.25 / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * ((( u[ east ] + this->pressure[ east ] ) * this->velocityX[ east ] ) - -(( u[ west ] + this->pressure[ west ] ) * this->velocityX[ west ] )) - - 0.5 * hyInverse * ((( u[ north ] + this->pressure[ north ] ) * this->velocityY[ north ] ) - -(( u[ south ] + this->pressure[ south ] ) * this->velocityY[ south ] )); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsEnergy< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse + - ( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse + - ( u[ up ] - 2.0 * u[ center ] + u[ down ] ) * hzSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} //namespace TNL - -#endif /* LaxFridrichsEnergyIMPL_H */ - diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX.h b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX.h deleted file mode 100644 index 5d1cf919252d85f00f08657e7e2944402940615a..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef LaxFridrichsMomentumX_H -#define LaxFridrichsMomentumX_H - -#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 LaxFridrichsMomentumX -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - -#include "LaxFridrichsMomentumX_impl.h" - -#endif /* LaxFridrichsMomentumX_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX.h~ deleted file mode 100644 index c359072f093a302baec114bbcfbbf8f86189f854..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX.h~ +++ /dev/null @@ -1,224 +0,0 @@ -#ifndef LaxFridrichsMomentumX_H -#define LaxFridrichsMomentumX_H - -#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 LaxFridrichsMomentumX -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - -#include "LaxFridrichsMomentumX_impl.h" - -#endif /* LaxFridrichsMomentumX_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX_impl.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX_impl.h~ deleted file mode 100644 index bc666db78ecdf0d768824ab3c5894b0150916fe3..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumX_impl.h~ +++ /dev/null @@ -1,355 +0,0 @@ -#ifndef LaxFridrichsMomentumX_IMPL_H -#define LaxFridrichsMomentumX_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumX< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumX< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - //rhoVelX - 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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return (0.25 / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * (( u[ east ] * this->velocityX[ east ] + this->pressure[ east ] ) - -( u[ west ] * this->velocityX[ west ] + this->pressure[ west ] )) - - 0.5 * hyInverse * (( u[ north ] * this->velocityY[ north ] ) - -( u[ south ] * this->velocityY[ south ] )); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumX< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumX< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumX< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); -return ((1.0/6.0) / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] + u[ up ] + u [ down ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * (( u[ east ] * this->velocityX[ east ] + this->pressure[ east ] ) - -( u[ west ] * this->velocityX[ west ] + this->pressure[ west ] )) - - 0.5 * hyInverse * (( u[ north ] * this->velocityY[ north ] ) - -( u[ south ] * this->velocityY[ south ] )) - - 0.5 * hzInverse * (( u[ up ] * this->velocityZ[ up ] ) - -( u[ down ] * this->velocityZ[ down ] )); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumX< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumX< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} //namespace TNL - -#endif /* LaxFridrichsMomentumXIMPL_H */ - diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumY.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumY.h~ deleted file mode 100644 index 2799f2f2bc5e40beb24238bc4ba76ddb0555411a..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumY.h~ +++ /dev/null @@ -1,218 +0,0 @@ -#ifndef LaxFridrichsMomentumY_H -#define LaxFridrichsMomentumY_H - -#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 LaxFridrichsMomentumY -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - -#include "LaxFridrichsMomentumY_impl.h" - -#endif /* LaxFridrichsMomentumY_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumY_impl.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumY_impl.h~ deleted file mode 100644 index aaa35043239faff3c4ad022c28442dd2af9a8098..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumY_impl.h~ +++ /dev/null @@ -1,355 +0,0 @@ -#ifndef LaxFridrichsMomentumY_IMPL_H -#define LaxFridrichsMomentumY_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumY< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumY< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - //rhoVelY - 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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return (0.25 / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * (( u[ east ] * this->velocityX[ east ] ) - -( u[ west ] * this->velocityX[ west ] )) - - 0.5 * hyInverse * (( u[ north ] * this->velocityY[ north ] + this->pressure[ north ] ) - -( u[ south ] * this->velocityY[ south ] + this->pressure[ south ])); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumY< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumY< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumY< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); - const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); - const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ((1.0/6.0) / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] + u[ up ] + u[ down ]- 6.0 * u[ center ] ) - - 0.5 * hxInverse * (( u[ east ] * this->velocityX[ east ] ) - -( u[ west ] * this->velocityX[ west ] )) - - 0.5 * hyInverse * (( u[ north ] * this->velocityY[ north ] + this->pressure[ north ] ) - -( u[ south ] * this->velocityY[ south ] + this->pressure[ south ])) - - 0.5 * hzInverse * (( u[ up ] * this->velocityZ[ up ] ) - -( u[ down ] * this->velocityZ[ down ] )); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumY< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumY< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} //namespace TNL - -#endif /* LaxFridrichsMomentumYIMPL_H */ - diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ.h b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ.h deleted file mode 100644 index 0d7882f6deaf9d5009775ffa2c9a1ca57d4261db..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ.h +++ /dev/null @@ -1,236 +0,0 @@ -#ifndef LaxFridrichsMomentumZ_H -#define LaxFridrichsMomentumZ_H - -#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 LaxFridrichsMomentumZ -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - -#include "LaxFridrichsMomentumZ_impl.h" - -#endif /* LaxFridrichsMomentumZ_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ.h~ deleted file mode 100644 index 816da05aa24fbda0c06b6c5ef833e8f330b4c7f3..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ.h~ +++ /dev/null @@ -1,236 +0,0 @@ -#ifndef LaxFridrichsMomentumY_H -#define LaxFridrichsMomentumY_H - -#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 LaxFridrichsMomentumY -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 1,MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef typename MeshType::CoordinatesType CoordinatesType; - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - typedef Functions::MeshFunction< MeshType > MeshFunctionType; - enum { Dimensions = MeshType::getMeshDimensions() }; - - static String getType(); - Real tau; - MeshFunctionType velocityX; - MeshFunctionType velocityY; - MeshFunctionType velocityZ; - MeshFunctionType pressure; - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocityX(MeshFunctionType& velocityX) - { - this->velocityX.bind(velocityX); - }; - - void setVelocityY(MeshFunctionType& velocityY) - { - this->velocityY.bind(velocityY); - }; - - void setVelocityZ(MeshFunctionType& velocityZ) - { - this->velocityZ.bind(velocityZ); - }; - - void setPressure(MeshFunctionType& pressure) - { - this->pressure.bind(pressure); - }; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const; - - 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 - -#include "LaxFridrichsMomentumY_impl.h" - -#endif /* LaxFridrichsMomentumY_H */ diff --git a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ_impl.h~ b/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ_impl.h~ deleted file mode 100644 index 0065f28b14f89774ce51c708b979d4bde4c1028c..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/LaxFridrichsMomentumZ_impl.h~ +++ /dev/null @@ -1,351 +0,0 @@ -#ifndef LaxFridrichsMomentumZ_IMPL_H -#define LaxFridrichsMomentumZ_IMPL_H - -namespace TNL { - -/**** - * 1D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumZ< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1 >(); - matrixRow.setElement( 0, west, - lambdaX ); - matrixRow.setElement( 1, center, 2.0 * lambdaX ); - matrixRow.setElement( 2, east, - lambdaX ); -} - -/**** - * 2D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumZ< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - - //rhoVelY - 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 = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - return (0.25 / this->tau) * ( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4.0 * u[ center ] ) - - 0.5 * hxInverse * (( u[ east ] * this->velocityX[ east ] ) - -( u[ west ] * this->velocityX[ west ] )) - - 0.5 * hyInverse * (( u[ north ] * this->velocityY[ north ] + this->pressure[ north ] ) - -( u[ south ] * this->velocityY[ south ] + this->pressure[ south ])); -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >(); - matrixRow.setElement( 0, south, -lambdaY ); - matrixRow.setElement( 1, west, -lambdaX ); - matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) ); - matrixRow.setElement( 3, east, -lambdaX ); - matrixRow.setElement( 4, north, -lambdaY ); -} - -/**** - * 3D problem - */ -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -String -LaxFridrichsMomentumZ< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getType() -{ - return String( "LaxFridrichsMomentumZ< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshFunction, typename MeshEntity > -__cuda_callable__ -Real -LaxFridrichsMomentumZ< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -operator()( const MeshFunction& u, - const MeshEntity& entity, - const Real& time ) const -{ - /**** - * Implement your explicit form of the differential operator here. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - - 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 = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse + - ( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse + - ( u[ up ] - 2.0 * u[ center ] + u[ down ] ) * hzSquareInverse; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -template< typename MeshEntity > -__cuda_callable__ -Index -LaxFridrichsMomentumZ< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const -{ - /**** - * Return a number of non-zero elements in a line (associated with given grid element) of - * the linear system. - * The following example is the Laplace operator approximated - * by the Finite difference method. - */ - - return 2*Dimensions + 1; -} - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > - template< typename MeshEntity, typename Vector, typename MatrixRow > -__cuda_callable__ -void -LaxFridrichsMomentumZ< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >:: -updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const -{ - /**** - * Setup the non-zero elements of the linear system here. - * The following example is the Laplace operator appriximated - * by the Finite difference method. - */ - - const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); - const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - const IndexType& center = entity.getIndex(); - const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >(); - matrixRow.setElement( 0, down, -lambdaZ ); - matrixRow.setElement( 1, south, -lambdaY ); - matrixRow.setElement( 2, west, -lambdaX ); - matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) ); - matrixRow.setElement( 4, east, -lambdaX ); - matrixRow.setElement( 5, north, -lambdaY ); - matrixRow.setElement( 6, up, -lambdaZ ); -} - -} //namespace TNL - -#endif /* LaxFridrichsMomentumZIMPL_H */ - diff --git a/examples/inviscid-flow-sw/3d/MyMixedBoundaryConditions.h b/examples/inviscid-flow-sw/3d/MyMixedBoundaryConditions.h deleted file mode 100644 index 066600f483d7e7bcf2adbb0cb6c68ad73eda52a6..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/MyMixedBoundaryConditions.h +++ /dev/null @@ -1,175 +0,0 @@ -// coppied and changed -/*************************************************************************** - tnlMyMixedBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYMIXEDBOUNDARYCONDITIONS_H_ -#define MYMIXEDBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyMixedBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - typedef typename MeshType::Cell Cell; - int count = mesh.template getEntitiesCount< Cell >(); - count = std::sqrt(count); - float x0 = 0.5; - if( entity.getCoordinates().x() == 0 ) - { - if ( entity.getCoordinates().y() < count * x0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - else if( entity.getCoordinates().y() < count -1 ) - return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - else if( entity.getCoordinates().y() == 0 ) - { - if ( entity.getCoordinates().x() < count * x0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - else if( entity.getCoordinates().x() < count -1 ) - return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - else if( entity.getCoordinates().x() == count ) - return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ]; - else return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyMixedBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyMixed boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYMIXEDBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/3d/MyMixedBoundaryConditions.h~ b/examples/inviscid-flow-sw/3d/MyMixedBoundaryConditions.h~ deleted file mode 100644 index 0cab175bb5847f5c87d735717e37cf9ef082f311..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/MyMixedBoundaryConditions.h~ +++ /dev/null @@ -1,175 +0,0 @@ -/*** coppied and changed -/*************************************************************************** - tnlMyMixedBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYMIXEDBOUNDARYCONDITIONS_H_ -#define MYMIXEDBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyMixedBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - typedef typename MeshType::Cell Cell; - int count = mesh.template getEntitiesCount< Cell >(); - count = std::sqrt(count); - float x0 = 0.5; - if( entity.getCoordinates().x() == 0 ) - { - if ( entity.getCoordinates().y() < count * x0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - else if( entity.getCoordinates().y() < count -1 ) - return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - else if( entity.getCoordinates().y() == 0 ) - { - if ( entity.getCoordinates().x() < count * x0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - else if( entity.getCoordinates().x() < count -1 ) - return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - else if( entity.getCoordinates().x() == count ) - return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ]; - else if( entity.getCoordinates().y() == count ) - return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ]; - else return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - return u[ neighbourEntities.template getEntityIndex< 0, 0 >() ]; - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyMixedBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyMixed boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYMIXEDBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/3d/MyNeumannBoundaryConditions.h b/examples/inviscid-flow-sw/3d/MyNeumannBoundaryConditions.h deleted file mode 100644 index 7987b93160e73f415b86f77882ecb2bc445efaa4..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/MyNeumannBoundaryConditions.h +++ /dev/null @@ -1,157 +0,0 @@ -//** coppied and changed -/*************************************************************************** - tnlMyNeumannBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYNEUMANNBOUNDARYCONDITIONS_H_ -#define MYNEUMANNBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyNeumannBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - typedef typename MeshType::Cell Cell; - int count = mesh.template getEntitiesCount< Cell >(); - count = std::sqrt(count); - if( entity.getCoordinates().x() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ]; - else if( entity.getCoordinates().x() == count-1 ) - return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ]; - else if( entity.getCoordinates().y() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ]; - else return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyNeumannBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyNeumann boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYNEUMANNBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/3d/MyNeumannBoundaryConditions.h~ b/examples/inviscid-flow-sw/3d/MyNeumannBoundaryConditions.h~ deleted file mode 100644 index 6a1e361b46ad91a1acb0d950183339f4e19a9651..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/MyNeumannBoundaryConditions.h~ +++ /dev/null @@ -1,157 +0,0 @@ -/*** coppied and changed -/*************************************************************************** - tnlMyNeumannBoundaryConditions.h - description - ------------------- - begin : Nov 17, 2014 - copyright : (C) 2014 by oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef MYNEUMANNBOUNDARYCONDITIONS_H_ -#define MYNEUMANNBOUNDARYCONDITIONS_H_ - -#pragma once - -#include <TNL/Operators/Operator.h> -#include <TNL/Functions/Analytic/Constant.h> -#include <TNL/Functions/FunctionAdapter.h> -#include <TNL/Functions/MeshFunction.h> - -namespace TNL { -namespace Operators { - -template< typename Mesh, - typename Function = Functions::Analytic::Constant< Mesh::getMeshDimensions(), typename Mesh::RealType >, - int MeshEntitiesDimensions = Mesh::getMeshDimensions(), - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class MyNeumannBoundaryConditions -: public Operator< Mesh, - Functions::MeshBoundaryDomain, - MeshEntitiesDimensions, - MeshEntitiesDimensions, - Real, - Index > -{ - public: - - typedef Mesh MeshType; - typedef Function FunctionType; - typedef Real RealType; - typedef typename MeshType::DeviceType DeviceType; - typedef Index IndexType; - - typedef SharedPointer< Mesh > MeshPointer; - typedef Containers::Vector< RealType, DeviceType, IndexType> DofVectorType; - typedef typename MeshType::VertexType VertexType; - - static constexpr int getMeshDimensions() { return MeshType::meshDimensions; } - - static void configSetup( Config::ConfigDescription& config, - const String& prefix = "" ) - { - Function::configSetup( config, prefix ); - } - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ) - { - return Functions::FunctionAdapter< MeshType, FunctionType >::template setup< MeshPointer >( this->function, meshPointer, parameters, prefix ); - } - - void setFunction( const Function& function ) - { - this->function = function; - } - - Function& getFunction() - { - return this->function; - } - - const Function& getFunction() const - { - return this->function; - } - - template< typename EntityType, - typename MeshFunction > - __cuda_callable__ - const RealType operator()( const MeshFunction& u, - const EntityType& entity, - const RealType& time = 0 ) const - { - const MeshType& mesh = entity.getMesh(); - const auto& neighbourEntities = entity.getNeighbourEntities(); - typedef typename MeshType::Cell Cell; - int count = mesh.template getEntitiesCount< Cell >(); - count = std::sqrt(count); - if( entity.getCoordinates().x() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 1, 0 >() ]; - else if( entity.getCoordinates().x() == count-1 ) - return u[ neighbourEntities.template getEntityIndex< -1, 0 >() ]; - else if( entity.getCoordinates().y() == 0 ) - return u[ neighbourEntities.template getEntityIndex< 0, 1 >() ]; - else return u[ neighbourEntities.template getEntityIndex< 0, -1 >() ]; - //tady se asi delaji okrajove podminky - //static_assert( EntityType::getDimensions() == MeshEntitiesDimensions, "Wrong mesh entity dimensions." ); - } - - template< typename EntityType > - __cuda_callable__ - IndexType getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const EntityType& entity ) const - { - return 1; - } - - template< typename PreimageFunction, - typename MeshEntity, - typename Matrix, - typename Vector > - __cuda_callable__ - void setMatrixElements( const PreimageFunction& u, - const MeshEntity& entity, - const RealType& time, - const RealType& tau, - Matrix& matrix, - Vector& b ) const - { - typename Matrix::MatrixRow matrixRow = matrix.getRow( entity.getIndex() ); - const IndexType& index = entity.getIndex(); - matrixRow.setElement( 0, index, 1.0 ); - b[ index ] = Functions::FunctionAdapter< MeshType, Function >::getValue( this->function, entity, time ); - } - - - protected: - - Function function; - - //static_assert( Device::DeviceType == Function::Device::DeviceType ); -}; - - -template< typename Mesh, - typename Function > -std::ostream& operator << ( std::ostream& str, const MyNeumannBoundaryConditions< Mesh, Function >& bc ) -{ - str << "MyNeumann boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL - -#endif /* MYNEUMANNBOUNDARYCONDITIONS_H_ */ diff --git a/examples/inviscid-flow-sw/3d/euler.h b/examples/inviscid-flow-sw/3d/euler.h deleted file mode 100644 index d5550d0c72dcc1624db2f227d2298346bbb1d73d..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/euler.h +++ /dev/null @@ -1,170 +0,0 @@ -#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 "eulerProblem.h" -#include "LaxFridrichs3D.h" -#include "eulerRhs.h" -#include "eulerBuildConfigTag.h" -#include "MyMixedBoundaryConditions.h" -#include "MyNeumannBoundaryConditions.h" - -using namespace TNL; - -typedef eulerBuildConfigTag BuildConfig; - -/**** - * Uncoment 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, - * esppecially 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 eulerConfig -{ - public: - static void configSetup( Config::ConfigDescription & config ) - { - config.addDelimiter( "euler2D settings:" ); - config.addEntry< String >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); - config.addEntryEnum< String >( "dirichlet" ); - config.addEntryEnum< String >( "neumann" ); - config.addEntryEnum< String >( "mymixed" ); - config.addEntryEnum< String >( "myneumann" ); - config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); - config.addEntry< double >( "NWU-density", "This sets a value of northwest up density." ); - config.addEntry< double >( "NWU-velocityX", "This sets a value of northwest up x velocity." ); - config.addEntry< double >( "NWU-velocityY", "This sets a value of northwest up y velocity." ); - config.addEntry< double >( "NWU-velocityZ", "This sets a value of northwest up z velocity." ); - config.addEntry< double >( "NWU-pressure", "This sets a value of northwest up pressure." ); - config.addEntry< double >( "SWU-density", "This sets a value of southwest up density." ); - config.addEntry< double >( "SWU-velocityX", "This sets a value of southwest up x velocity." ); - config.addEntry< double >( "SWU-velocityY", "This sets a value of southwest up y velocity." ); - config.addEntry< double >( "SWU-velocityZ", "This sets a value of southwest up z velocity." ); - config.addEntry< double >( "SWU-pressure", "This sets a value of southwest up pressure." ); - config.addEntry< double >( "NWD-density", "This sets a value of northwest down density." ); - config.addEntry< double >( "NWD-velocityX", "This sets a value of northwest down x velocity." ); - config.addEntry< double >( "NWD-velocityY", "This sets a value of northwest down y velocity." ); - config.addEntry< double >( "NWD-velocityZ", "This sets a value of northwest down z velocity." ); - config.addEntry< double >( "NWD-pressure", "This sets a value of northwest down pressure." ); - config.addEntry< double >( "SWD-density", "This sets a value of southwest down density." ); - config.addEntry< double >( "SWD-velocityX", "This sets a value of southwest down x velocity." ); - config.addEntry< double >( "SWD-velocityY", "This sets a value of southwest down y velocity." ); - config.addEntry< double >( "SWF-velocityZ", "This sets a value of southwest down z velocity." ); - config.addEntry< double >( "SWD-pressure", "This sets a value of southwest down pressure." ); - config.addEntry< double >( "riemann-border", "This sets a position of discontinuity cross." ); - config.addEntry< double >( "NEU-density", "This sets a value of northeast up density." ); - config.addEntry< double >( "NEU-velocityX", "This sets a value of northeast up x velocity." ); - config.addEntry< double >( "NEU-velocityY", "This sets a value of northeast up y velocity." ); - config.addEntry< double >( "NEU-velocityZ", "This sets a value of northeast up z velocity." ); - config.addEntry< double >( "NEU-pressure", "This sets a value of northeast up pressure." ); - config.addEntry< double >( "SEU-density", "This sets a value of southeast up density." ); - config.addEntry< double >( "SEU-velocityX", "This sets a value of southeast up x velocity." ); - config.addEntry< double >( "SEU-velocityY", "This sets a value of southeast up y velocity." ); - config.addEntry< double >( "SEU-velocityZ", "This sets a value of southeast up z velocity." ); - config.addEntry< double >( "SEU-pressure", "This sets a value of southeast up pressure." ); - config.addEntry< double >( "NED-density", "This sets a value of northeast down density." ); - config.addEntry< double >( "NED-velocityX", "This sets a value of northeast down x velocity." ); - config.addEntry< double >( "NED-velocityY", "This sets a value of northeast down y velocity." ); - config.addEntry< double >( "NED-velocityZ", "This sets a value of northeast down z velocity." ); - config.addEntry< double >( "NED-pressure", "This sets a value of northeast down pressure." ); - config.addEntry< double >( "SED-density", "This sets a value of southeast down density." ); - config.addEntry< double >( "SED-velocityX", "This sets a value of southeast down x velocity." ); - config.addEntry< double >( "SED-velocityY", "This sets a value of southeast down y velocity." ); - config.addEntry< double >( "SED-velocityZ", "This sets a value of southeast down z velocity." ); - config.addEntry< double >( "SED-pressure", "This sets a value of southeast down pressure." ); - config.addEntry< double >( "gamma", "This sets a value of gamma constant." ); - - /**** - * Add definition of your solver command line arguments. - */ - - } -}; - -template< typename Real, - typename Device, - typename Index, - typename MeshType, - typename ConfigTag, - typename SolverStarter > -class eulerSetter -{ - public: - - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - - static bool run( const Config::ParameterContainer & parameters ) - { - enum { Dimensions = MeshType::getMeshDimensions() }; - typedef LaxFridrichs3D< MeshType, Real, Index > ApproximateOperator; - typedef eulerRhs< MeshType, Real > RightHandSide; - typedef Containers::StaticVector < MeshType::getMeshDimensions(), Real > Vertex; - - /**** - * 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< Dimensions, Real > Constant; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - typedef Operators::NeumannBoundaryConditions< MeshType, Constant, Real, Index > BoundaryConditions; - typedef eulerProblem< 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::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - if( boundaryConditionsType == "mymixed" ) - { - typedef Operators::MyMixedBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - if( boundaryConditionsType == "myneumann" ) - { - typedef Operators::MyNeumannBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< 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 eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - return true;} -}; - -int main( int argc, char* argv[] ) -{ - Solvers::Solver< eulerSetter, eulerConfig, BuildConfig > solver; - if( ! solver. run( argc, argv ) ) - return EXIT_FAILURE; - return EXIT_SUCCESS; -} diff --git a/examples/inviscid-flow-sw/3d/euler.h~ b/examples/inviscid-flow-sw/3d/euler.h~ deleted file mode 100644 index 600653ecc7ca8d60080733ee2ca6f62fdd53d175..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/euler.h~ +++ /dev/null @@ -1,162 +0,0 @@ -#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 "eulerProblem.h" -#include "LaxFridrichs3D.h" -#include "eulerRhs.h" -#include "eulerBuildConfigTag.h" -#include "MyMixedBoundaryConditions.h" -#include "MyNeumannBoundaryConditions.h" - -using namespace TNL; - -typedef eulerBuildConfigTag BuildConfig; - -/**** - * Uncoment 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, - * esppecially 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 eulerConfig -{ - public: - static void configSetup( Config::ConfigDescription & config ) - { - config.addDelimiter( "euler2D settings:" ); - config.addEntry< String >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); - config.addEntryEnum< String >( "dirichlet" ); - config.addEntryEnum< String >( "neumann" ); - config.addEntryEnum< String >( "mymixed" ); - config.addEntryEnum< String >( "myneumann" ); - config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); - config.addEntry< double >( "NWU-density", "This sets a value of northwest up density." ); - config.addEntry< double >( "NWU-velocityX", "This sets a value of northwest up x velocity." ); - config.addEntry< double >( "NWU-velocityY", "This sets a value of northwest up y velocity." ); - config.addEntry< double >( "NWU-pressure", "This sets a value of northwest up pressure." ); - config.addEntry< double >( "SWU-density", "This sets a value of southwest up density." ); - config.addEntry< double >( "SWU-velocityX", "This sets a value of southwest up x velocity." ); - config.addEntry< double >( "SWU-velocityY", "This sets a value of southwest up y velocity." ); - config.addEntry< double >( "SWU-pressure", "This sets a value of southwest up pressure." ); - config.addEntry< double >( "NWD-density", "This sets a value of northwest down density." ); - config.addEntry< double >( "NWD-velocityX", "This sets a value of northwest down x velocity." ); - config.addEntry< double >( "NWD-velocityY", "This sets a value of northwest down y velocity." ); - config.addEntry< double >( "NWD-pressure", "This sets a value of northwest down pressure." ); - config.addEntry< double >( "SWD-density", "This sets a value of southwest down density." ); - config.addEntry< double >( "SWD-velocityX", "This sets a value of southwest down x velocity." ); - config.addEntry< double >( "SWD-velocityY", "This sets a value of southwest down y velocity." ); - config.addEntry< double >( "SWD-pressure", "This sets a value of southwest down pressure." ); - config.addEntry< double >( "riemann-border", "This sets a position of discontinuity cross." ); - config.addEntry< double >( "NEU-density", "This sets a value of northeast up density." ); - config.addEntry< double >( "NEU-velocityX", "This sets a value of northeast up x velocity." ); - config.addEntry< double >( "NEU-velocityY", "This sets a value of northeast up y velocity." ); - config.addEntry< double >( "NEU-pressure", "This sets a value of northeast up pressure." ); - config.addEntry< double >( "SEU-density", "This sets a value of southeast up density." ); - config.addEntry< double >( "SEU-velocityX", "This sets a value of southeast up x velocity." ); - config.addEntry< double >( "SEU-velocityY", "This sets a value of southeast up y velocity." ); - config.addEntry< double >( "SEU-pressure", "This sets a value of southeast up pressure." ); - config.addEntry< double >( "NED-density", "This sets a value of northeast down density." ); - config.addEntry< double >( "NED-velocityX", "This sets a value of northeast down x velocity." ); - config.addEntry< double >( "NED-velocityY", "This sets a value of northeast down y velocity." ); - config.addEntry< double >( "NED-pressure", "This sets a value of northeast down pressure." ); - config.addEntry< double >( "SED-density", "This sets a value of southeast down density." ); - config.addEntry< double >( "SED-velocityX", "This sets a value of southeast down x velocity." ); - config.addEntry< double >( "SED-velocityY", "This sets a value of southeast down y velocity." ); - config.addEntry< double >( "SED-pressure", "This sets a value of southeast down pressure." ); - config.addEntry< double >( "gamma", "This sets a value of gamma constant." ); - - /**** - * Add definition of your solver command line arguments. - */ - - } -}; - -template< typename Real, - typename Device, - typename Index, - typename MeshType, - typename ConfigTag, - typename SolverStarter > -class eulerSetter -{ - public: - - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - - static bool run( const Config::ParameterContainer & parameters ) - { - enum { Dimensions = MeshType::getMeshDimensions() }; - typedef LaxFridrichs3D< MeshType, Real, Index > ApproximateOperator; - typedef eulerRhs< MeshType, Real > RightHandSide; - typedef Containers::StaticVector < MeshType::getMeshDimensions(), Real > Vertex; - - /**** - * 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< Dimensions, Real > Constant; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - typedef Operators::NeumannBoundaryConditions< MeshType, Constant, Real, Index > BoundaryConditions; - typedef eulerProblem< 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::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - if( boundaryConditionsType == "mymixed" ) - { - typedef Operators::MyMixedBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - if( boundaryConditionsType == "myneumann" ) - { - typedef Operators::MyNeumannBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< 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 eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - return true;} -}; - -int main( int argc, char* argv[] ) -{ - Solvers::Solver< eulerSetter, eulerConfig, BuildConfig > solver; - if( ! solver. run( argc, argv ) ) - return EXIT_FAILURE; - return EXIT_SUCCESS; -} diff --git a/examples/inviscid-flow-sw/3d/eulerBuildConfigTag.h~ b/examples/inviscid-flow-sw/3d/eulerBuildConfigTag.h~ deleted file mode 100644 index 286a2cae8b868d3dfc719429aab38415cc12bee5..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/eulerBuildConfigTag.h~ +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef eulerBUILDCONFIGTAG_H_ -#define eulerBUILDCONFIGTAG_H_ - -#include <TNL/Solvers/BuildConfigTags.h> - -namespace TNL { - -class eulerBuildConfigTag{}; - -namespace Solvers { - -/**** - * Turn off support for float and long double. - */ -template<> struct ConfigTagReal< eulerBuildConfigTag, float > { enum { enabled = false }; }; -template<> struct ConfigTagReal< eulerBuildConfigTag, long double > { enum { enabled = false }; }; - -/**** - * Turn off support for short int and long int indexing. - */ -template<> struct ConfigTagIndex< eulerBuildConfigTag, short int >{ enum { enabled = false }; }; -template<> struct ConfigTagIndex< eulerBuildConfigTag, long int >{ enum { enabled = false }; }; - -template< int Dimensions > struct ConfigTagDimensions< eulerBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 2 ) }; }; - -/**** - * Use of Grid is enabled for allowed dimensions and Real, Device and Index types. - */ -template< int Dimensions, typename Real, typename Device, typename Index > - struct ConfigTagMesh< eulerBuildConfigTag, Meshes::Grid< Dimensions, Real, Device, Index > > - { enum { enabled = ConfigTagDimensions< eulerBuildConfigTag, Dimensions >::enabled && - ConfigTagReal< eulerBuildConfigTag, Real >::enabled && - ConfigTagDevice< eulerBuildConfigTag, Device >::enabled && - ConfigTagIndex< eulerBuildConfigTag, Index >::enabled }; }; - -/**** - * Please, chose your preferred time discretisation here. - */ -template<> struct ConfigTagTimeDiscretisation< eulerBuildConfigTag, ExplicitTimeDiscretisationTag >{ enum { enabled = true }; }; -template<> struct ConfigTagTimeDiscretisation< eulerBuildConfigTag, SemiImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; -template<> struct ConfigTagTimeDiscretisation< eulerBuildConfigTag, ImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; - -/**** - * Only the Runge-Kutta-Merson solver is enabled by default. - */ -template<> struct ConfigTagExplicitSolver< eulerBuildConfigTag, tnlExplicitEulerSolverTag >{ enum { enabled = true }; }; - -} // namespace Solvers -} // namespace TNL - - -#endif /* eulerBUILDCONFIGTAG_H_ */ diff --git a/examples/inviscid-flow-sw/3d/eulerProblem_impl.h b/examples/inviscid-flow-sw/3d/eulerProblem_impl.h deleted file mode 100644 index b01979b87c6218f6e0ff1018caa8f05467bdfd1c..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/eulerProblem_impl.h +++ /dev/null @@ -1,579 +0,0 @@ -#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 "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "LaxFridrichsMomentumZ.h" -#include "EulerPressureGetter.h" -#include "Euler2DVelXGetter.h" -#include "EulerVelGetter.h" - -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getTypeStatic() -{ - return String( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getPrologHeader() const -{ - return String( "euler3D" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( //! this->boundaryConditionPointer->setup( meshPointer, parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::IndexType -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 5*mesh->template getEntitiesCount< typename MeshType::Cell >(); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -bindDofs( const MeshPointer& mesh, - DofVectorPointer& dofVector ) -{ -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - typedef typename MeshType::Cell Cell; - gamma = parameters.getParameter< RealType >( "gamma" ); - RealType rhoNWU = parameters.getParameter< RealType >( "NWU-density" ); - RealType velNWUX = parameters.getParameter< RealType >( "NWU-velocityX" ); - RealType velNWUY = parameters.getParameter< RealType >( "NWU-velocityY" ); - RealType velNWUZ = parameters.getParameter< RealType >( "NWU-velocityZ" ); - RealType preNWU = parameters.getParameter< RealType >( "NWU-pressure" ); - //RealType eNWU = ( preNWU / ( rhoNWU * (gamma - 1) ) ); - RealType eNWU = ( preNWU / (gamma - 1) ) + 0.5 * rhoNWU * (std::pow(velNWUX,2)+std::pow(velNWUY,2)+std::pow(velNWUZ,2)); - RealType rhoSWU = parameters.getParameter< RealType >( "SWU-density" ); - RealType velSWUX = parameters.getParameter< RealType >( "SWU-velocityX" ); - RealType velSWUY = parameters.getParameter< RealType >( "SWU-velocityY" ); - RealType velSWUZ = parameters.getParameter< RealType >( "SWU-velocityZ" ); - RealType preSWU = parameters.getParameter< RealType >( "SWU-pressure" ); - //RealType eSWU = ( preSWU / ( rhoSWU * (gamma - 1) ) ); - RealType eSWU = ( preSWU / (gamma - 1) ) + 0.5 * rhoSWU * (std::pow(velSWUX,2)+std::pow(velSWUY,2)+std::pow(velSWUZ,2)); - RealType rhoNWD = parameters.getParameter< RealType >( "NWD-density" ); - RealType velNWDX = parameters.getParameter< RealType >( "NWD-velocityX" ); - RealType velNWDY = parameters.getParameter< RealType >( "NWD-velocityY" ); - RealType velNWDZ = parameters.getParameter< RealType >( "NWD-velocityZ" ); - RealType preNWD = parameters.getParameter< RealType >( "NWD-pressure" ); - //RealType eNWD = ( preNWD / ( rhoNWD * (gamma - 1) ) ); - RealType eNWD = ( preNWD / (gamma - 1) ) + 0.5 * rhoNWD * (std::pow(velNWDX,2)+std::pow(velNWDY,2)+std::pow(velNWDZ,2)); - RealType rhoSWD = parameters.getParameter< RealType >( "SWD-density" ); - RealType velSWDX = parameters.getParameter< RealType >( "SWD-velocityX" ); - RealType velSWDY = parameters.getParameter< RealType >( "SWD-velocityY" ); - RealType velSWDZ = parameters.getParameter< RealType >( "SWD-velocityZ" ); - RealType preSWD = parameters.getParameter< RealType >( "SWD-pressure" ); - //RealType eSWD = ( preSWD / ( rhoSWD * (gamma - 1) ) ); - RealType eSWD = ( preSWD / (gamma - 1) ) + 0.5 * rhoSWD * (std::pow(velSWDX,2)+std::pow(velSWDY,2)+std::pow(velSWDZ,2)); - RealType rhoNEU = parameters.getParameter< RealType >( "NEU-density" ); - RealType velNEUX = parameters.getParameter< RealType >( "NEU-velocityX" ); - RealType velNEUY = parameters.getParameter< RealType >( "NEU-velocityY" ); - RealType velNEUZ = parameters.getParameter< RealType >( "NEU-velocityZ" ); - RealType preNEU = parameters.getParameter< RealType >( "NEU-pressure" ); - //RealType eNEU = ( preNEU / ( rhoNEU * (gamma - 1) ) ); - RealType eNEU = ( preNEU / (gamma - 1) ) + 0.5 * rhoNEU * (std::pow(velNEUX,2)+std::pow(velNEUY,2)+std::pow(velNEUZ,2)); - RealType rhoSEU = parameters.getParameter< RealType >( "SEU-density" ); - RealType velSEUX = parameters.getParameter< RealType >( "SEU-velocityX" ); - RealType velSEUY = parameters.getParameter< RealType >( "SEU-velocityY" ); - RealType velSEUZ = parameters.getParameter< RealType >( "SEU-velocityZ" ); - RealType preSEU = parameters.getParameter< RealType >( "SEU-pressure" ); - //RealType eSEU = ( preSEU / ( rhoSEU * (gamma - 1) ) ); - RealType eSEU = ( preSEU / (gamma - 1) ) + 0.5 * rhoSEU * (std::pow(velSEUX,2)+std::pow(velSEUY,2)+std::pow(velSEUZ,2)); - RealType rhoNED = parameters.getParameter< RealType >( "NED-density" ); - RealType velNEDX = parameters.getParameter< RealType >( "NED-velocityX" ); - RealType velNEDY = parameters.getParameter< RealType >( "NED-velocityY" ); - RealType velNEDZ = parameters.getParameter< RealType >( "NED-velocityZ" ); - RealType preNED = parameters.getParameter< RealType >( "NED-pressure" ); - //RealType eNED = ( preNED / ( rhoNED * (gamma - 1) ) ); - RealType eNED = ( preNED / (gamma - 1) ) + 0.5 * rhoNED * (std::pow(velNEDX,2)+std::pow(velNEDY,2)+std::pow(velNEDZ,2)); - RealType rhoSED = parameters.getParameter< RealType >( "SED-density" ); - RealType velSEDX = parameters.getParameter< RealType >( "SED-velocityX" ); - RealType velSEDY = parameters.getParameter< RealType >( "SED-velocityY" ); - RealType velSEDZ = parameters.getParameter< RealType >( "SED-velocityZ" ); - RealType preSED = parameters.getParameter< RealType >( "SED-pressure" ); - //RealType eSED = ( preSED / ( rhoSED * (gamma - 1) ) ); - RealType eSED = ( preSED / (gamma - 1) ) + 0.5 * rhoSED * (std::pow(velSEDX,2)+std::pow(velSEDY,2)+std::pow(velSEDZ,2)); - RealType x0 = parameters.getParameter< RealType >( "riemann-border" ); - int size = mesh->template getEntitiesCount< Cell >(); - uRho->bind(mesh, dofs, 0); - uRhoVelocityX->bind(mesh, dofs, size); - uRhoVelocityY->bind(mesh, dofs, 2*size); - uRhoVelocityZ->bind(mesh, dofs, 3*size); - uEnergy->bind(mesh, dofs, 4*size); - Containers::Vector< RealType, DeviceType, IndexType > data; - data.setSize(5*size); - pressure->bind(mesh, data, 0); - velocity->bind(mesh, data, size); - velocityX->bind(mesh, data, 2*size); - velocityY->bind(mesh, data, 3*size); - velocityZ->bind(mesh, data, 4*size); - int count = std::pow(size, (1.0/3.0)); - for(IndexType i = 0; i < count; i++) - for(IndexType j = 0; j < count; j++) - for(IndexType k = 0; k < count; k++) - if ((i <= x0 * count)&&(j <= x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSWD; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSWD * velSWDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSWD * velSWDY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoSWD * velSWDZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSWD; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSWDX,2)+std::pow(velSWDY,2)+std::pow(velSWDZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSWDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSWDY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velSWDZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSWD; - } - else - if ((i <= x0 * count)&&(j <= x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSED; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSED * velSEDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSED * velSEDY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoSED * velSEDZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSED; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSEDX,2)+std::pow(velSEDY,2)+std::pow(velSEDZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSEDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSEDY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velSEDZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSED; - } - else - if ((i <= x0 * count)&&(j > x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNWD; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNWD * velNWDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNWD * velNWDY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoNWD * velNWDZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNWD; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNWDX,2)+std::pow(velNWDY,2)+std::pow(velNWDZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNWDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNWDY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velNWDZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNWD; - } - else - if ((i <= x0 * count)&&(j > x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNED; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNED * velNEDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNED * velNEDY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoNED * velNEDZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNED; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNEDX,2)+std::pow(velNEDY,2)+std::pow(velNEDZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNEDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNEDY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velNEDZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNED; - } - else - if ((i > x0 * count)&&(j <= x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSWU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSWU * velSWUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSWU * velSWUY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoSWU * velSWUZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSWU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSWUX,2)+std::pow(velSWUY,2)+std::pow(velSWUZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSWUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSWUY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velSWUZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSWU; - } - else - if ((i > x0 * count)&&(j <= x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSEU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSEU * velSEUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSEU * velSEUY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoSEU * velSEUZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSEU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSEUX,2)+std::pow(velSEUY,2)+std::pow(velSEUZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSEUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSEUY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velSEUZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSEU; - } - else - if ((i > x0 * count)&&(j > x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNWU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNWU * velNWUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNWU * velNWUY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoNWU * velNWUZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNWU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNWUX,2)+std::pow(velNWUY,2)+std::pow(velNWUZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNWUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNWUY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velNWUZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNWU; - } - else - if ((i > x0 * count)&&(j > x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNEU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNEU * velNEUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNEU * velNEUY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoNEU * velNEUZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNEU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNEUX,2)+std::pow(velNEUY,2)+std::pow(velNEUZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNEUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNEUY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velNEUZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNEU; - }; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setupLinearSystem( const MeshPointer& mesh, - Matrix& matrix ) -{ -/* const IndexType dofs = this->getDofs( mesh ); - typedef typename Matrix::CompressedRowsLengthsVector CompressedRowsLengthsVectorType; - CompressedRowsLengthsVectorType rowLengths; - if( ! rowLengths.setSize( dofs ) ) - return false; - MatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, CompressedRowsLengthsVectorType > matrixSetter; - matrixSetter.template getCompressedRowsLengths< typename Mesh::Cell >( mesh, - differentialOperator, - boundaryCondition, - rowLengths ); - matrix.setDimensions( dofs, dofs ); - if( ! matrix.setCompressedRowsLengths( rowLengths ) ) - return false;*/ - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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; - FileName fileName; - fileName.setExtension( "tnl" ); - fileName.setIndex( step ); - fileName.setFileNameBase( "rho-" ); - if( ! uRho->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelX-" ); - if( ! uRhoVelocityX->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelY-" ); - if( ! uRhoVelocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelZ-" ); - if( ! uRhoVelocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "energy-" ); - if( ! uEnergy->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityX-" ); - if( ! velocityX->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityY-" ); - if( ! velocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityZ-" ); - if( ! velocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocity-" ); - if( ! velocity->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "pressue-" ); - if( ! pressure->save( fileName.getFileName() ) ) - return false; - - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getExplicitRHS( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - DofVectorPointer& _fu, - MeshDependentDataPointer& meshDependentData ) -{ - typedef typename MeshType::Cell Cell; - int count = mesh->template getEntitiesCount< Cell >(); - fuRho->bind( mesh, _fu, 0 ); - fuRhoVelocityX->bind( mesh, _fu, count ); - fuRhoVelocityY->bind( mesh, _fu, 2*count ); - fuRhoVelocityZ->bind( mesh, _fu, 3*count ); - fuEnergy->bind( mesh, _fu, 4*count ); - SharedPointer< Continuity > lF3DContinuity; - SharedPointer< MomentumX > lF3DMomentumX; - SharedPointer< MomentumY > lF3DMomentumY; - SharedPointer< MomentumZ > lF3DMomentumZ; - SharedPointer< Energy > lF3DEnergy; - - this->bindDofs( mesh, _u ); - //rho - lF3DContinuity->setTau(tau); - lF3DContinuity->setVelocityX( *velocityX ); - lF3DContinuity->setVelocityY( *velocityY ); - lF3DContinuity->setVelocityZ( *velocityZ ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Continuity, BoundaryCondition, RightHandSide > explicitUpdaterContinuity; - explicitUpdaterContinuity.template update< typename Mesh::Cell >( time, - mesh, - lF3DContinuity, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRho, - fuRho ); - - //rhoVelocityX - lF3DMomentumX->setTau(tau); - lF3DMomentumX->setVelocityX( *velocityX ); - lF3DMomentumX->setVelocityY( *velocityY ); - lF3DMomentumX->setVelocityZ( *velocityZ ); - lF3DMomentumX->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumX, BoundaryCondition, RightHandSide > explicitUpdaterMomentumX; - explicitUpdaterMomentumX.template update< typename Mesh::Cell >( time, - mesh, - lF3DMomentumX, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityX, - fuRhoVelocityX ); - - //rhoVelocityY - lF3DMomentumY->setTau(tau); - lF3DMomentumY->setVelocityX( *velocityX ); - lF3DMomentumY->setVelocityY( *velocityY ); - lF3DMomentumY->setVelocityZ( *velocityZ ); - lF3DMomentumY->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumY, BoundaryCondition, RightHandSide > explicitUpdaterMomentumY; - explicitUpdaterMomentumY.template update< typename Mesh::Cell >( time, - mesh, - lF3DMomentumY, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityY, - fuRhoVelocityY ); - - //rhoVelocityZ - lF3DMomentumZ->setTau(tau); - lF3DMomentumZ->setVelocityX( *velocityX ); - lF3DMomentumZ->setVelocityY( *velocityY ); - lF3DMomentumZ->setVelocityZ( *velocityZ ); - lF3DMomentumZ->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumZ, BoundaryCondition, RightHandSide > explicitUpdaterMomentumZ; - explicitUpdaterMomentumZ.template update< typename Mesh::Cell >( time, - mesh, - lF3DMomentumZ, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityZ, - fuRhoVelocityZ ); - - //energy - lF3DEnergy->setTau(tau); - lF3DEnergy->setVelocityX( *velocityX ); - lF3DEnergy->setVelocityY( *velocityY ); - lF3DEnergy->setVelocityZ( *velocityZ ); - lF3DEnergy->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Energy, BoundaryCondition, RightHandSide > explicitUpdaterEnergy; - explicitUpdaterEnergy.template update< typename Mesh::Cell >( time, - mesh, - lF3DEnergy, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uEnergy, - fuEnergy ); - -/* -cout << "rho " << uRho.getData() << endl; -getchar(); -cout << "rhoVelX " << uRhoVelocityX.getData() << endl; -getchar(); -cout << "rhoVelY " << uRhoVelocityY.getData() << endl; -getchar(); -cout << "Energy " << uEnergy.getData() << endl; -getchar(); -cout << "velocity " << velocity.getData() << endl; -getchar(); -cout << "velocityX " << velocityX.getData() << endl; -getchar(); -cout << "velocityY " << velocityY.getData() << endl; -getchar(); -cout << "pressure " << pressure.getData() << endl; -getchar(); -*/ - - -/* - BoundaryConditionsSetter< MeshFunctionType, BoundaryCondition > boundaryConditionsSetter; - boundaryConditionsSetter.template apply< typename Mesh::Cell >( - this->boundaryCondition, - time + tau, - u );*/ - } - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b, - MeshDependentDataPointer& meshDependentData ) -{ -/* LinearSystemAssembler< Mesh, - MeshFunctionType, - DifferentialOperator, - 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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -postIterate( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - - //velocityX - this->velocityX->setMesh( mesh ); - VelocityX velocityXGetter( *uRho, *uRhoVelocityX ); - *this->velocityX = velocityXGetter; - - //velocityY - this->velocityY->setMesh( mesh ); - VelocityX velocityYGetter( *uRho, *uRhoVelocityY ); - *this->velocityY = velocityYGetter; - - //velocityY - this->velocityZ->setMesh( mesh ); - VelocityX velocityZGetter( *uRho, *uRhoVelocityZ ); - *this->velocityZ = velocityZGetter; - - //velocity - this->velocity->setMesh( mesh ); - Velocity velocityGetter( *uRho, *uRhoVelocityX, *uRhoVelocityY, *uRhoVelocityZ); - *this->velocity = velocityGetter; - - //pressure - this->pressure->setMesh( mesh ); - Pressure pressureGetter( *uRho, *uRhoVelocityX, *uRhoVelocityY, *uRhoVelocityZ, *uEnergy, gamma ); - *this->pressure = pressureGetter; - - return true; -} - -} // namespace TNL - diff --git a/examples/inviscid-flow-sw/3d/eulerProblem_impl.h~ b/examples/inviscid-flow-sw/3d/eulerProblem_impl.h~ deleted file mode 100644 index 9f0dbf56be0f32e3d4f8897a82deb1b00cee77c7..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/eulerProblem_impl.h~ +++ /dev/null @@ -1,565 +0,0 @@ -#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 "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "LaxFridrichsMomentumZ.h" -#include "EulerPressureGetter.h" -#include "Euler2DVelXGetter.h" -#include "EulerVelGetter.h" - -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getTypeStatic() -{ - return String( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getPrologHeader() const -{ - return String( "euler3D" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( //! this->boundaryConditionPointer->setup( meshPointer, parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::IndexType -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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 5*mesh->template getEntitiesCount< typename MeshType::Cell >(); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -bindDofs( const MeshPointer& mesh, - DofVectorPointer& dofVector ) -{ -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - typedef typename MeshType::Cell Cell; - gamma = parameters.getParameter< RealType >( "gamma" ); - RealType rhoNWU = parameters.getParameter< RealType >( "NWU-density" ); - RealType velNWUX = parameters.getParameter< RealType >( "NWU-velocityX" ); - RealType velNWUY = parameters.getParameter< RealType >( "NWU-velocityY" ); - RealType velNWUZ = parameters.getParameter< RealType >( "NWU-velocityZ" ); - RealType preNWU = parameters.getParameter< RealType >( "NWU-pressure" ); - //RealType eNWU = ( preNWU / ( rhoNWU * (gamma - 1) ) ); - RealType eNWU = ( preNWU / (gamma - 1) ) + 0.5 * rhoNWU * (std::pow(velNWUX,2)+std::pow(velNWUY,2)+std::pow(velNWUZ,2)); - RealType rhoSWU = parameters.getParameter< RealType >( "SWU-density" ); - RealType velSWUX = parameters.getParameter< RealType >( "SWU-velocityX" ); - RealType velSWUY = parameters.getParameter< RealType >( "SWU-velocityY" ); - RealType velSWUZ = parameters.getParameter< RealType >( "SWU-velocityZ" ); - RealType preSWU = parameters.getParameter< RealType >( "SWU-pressure" ); - //RealType eSWU = ( preSWU / ( rhoSWU * (gamma - 1) ) ); - RealType eSWU = ( preSWU / (gamma - 1) ) + 0.5 * rhoSWU * (std::pow(velSWUX,2)+std::pow(velSWUY,2)+std::pow(velSWUZ,2)); - RealType rhoNWD = parameters.getParameter< RealType >( "NWD-density" ); - RealType velNWDX = parameters.getParameter< RealType >( "NWD-velocityX" ); - RealType velNWDY = parameters.getParameter< RealType >( "NWD-velocityY" ); - RealType velNWDZ = parameters.getParameter< RealType >( "NWD-velocityZ" ); - RealType preNWD = parameters.getParameter< RealType >( "NWD-pressure" ); - //RealType eNWD = ( preNWD / ( rhoNWD * (gamma - 1) ) ); - RealType eNWD = ( preNWD / (gamma - 1) ) + 0.5 * rhoNWD * (std::pow(velNWDX,2)+std::pow(velNWDY,2)+std::pow(velNWDZ,2)); - RealType rhoSWD = parameters.getParameter< RealType >( "SWD-density" ); - RealType velSWDX = parameters.getParameter< RealType >( "SWD-velocityX" ); - RealType velSWDY = parameters.getParameter< RealType >( "SWD-velocityY" ); - RealType velSWDZ = parameters.getParameter< RealType >( "SWD-velocityZ" ); - RealType preSWD = parameters.getParameter< RealType >( "SWD-pressure" ); - //RealType eSWD = ( preSWD / ( rhoSWD * (gamma - 1) ) ); - RealType eSWD = ( preSWD / (gamma - 1) ) + 0.5 * rhoSWD * (std::pow(velSWDX,2)+std::pow(velSWDY,2)+std::pow(velSWDZ,2)); - RealType rhoNEU = parameters.getParameter< RealType >( "NEU-density" ); - RealType velNEUX = parameters.getParameter< RealType >( "NEU-velocityX" ); - RealType velNEUY = parameters.getParameter< RealType >( "NEU-velocityY" ); - RealType velNEUZ = parameters.getParameter< RealType >( "NEU-velocityZ" ); - RealType preNEU = parameters.getParameter< RealType >( "NEU-pressure" ); - //RealType eNEU = ( preNEU / ( rhoNEU * (gamma - 1) ) ); - RealType eNEU = ( preNEU / (gamma - 1) ) + 0.5 * rhoNEU * (std::pow(velNEUX,2)+std::pow(velNEUY,2)+std::pow(velNEUZ,2)); - RealType rhoSEU = parameters.getParameter< RealType >( "SEU-density" ); - RealType velSEUX = parameters.getParameter< RealType >( "SEU-velocityX" ); - RealType velSEUY = parameters.getParameter< RealType >( "SEU-velocityY" ); - RealType velSEUZ = parameters.getParameter< RealType >( "SEU-velocityZ" ); - RealType preSEU = parameters.getParameter< RealType >( "SEU-pressure" ); - //RealType eSEU = ( preSEU / ( rhoSEU * (gamma - 1) ) ); - RealType eSEU = ( preSEU / (gamma - 1) ) + 0.5 * rhoSEU * (std::pow(velSEUX,2)+std::pow(velSEUY,2)+std::pow(velSEUZ,2)); - RealType rhoNED = parameters.getParameter< RealType >( "NED-density" ); - RealType velNEDX = parameters.getParameter< RealType >( "NED-velocityX" ); - RealType velNEDY = parameters.getParameter< RealType >( "NED-velocityY" ); - RealType velNEDZ = parameters.getParameter< RealType >( "NED-velocityZ" ); - RealType preNED = parameters.getParameter< RealType >( "NED-pressure" ); - //RealType eNED = ( preNED / ( rhoNED * (gamma - 1) ) ); - RealType eNED = ( preNED / (gamma - 1) ) + 0.5 * rhoNED * (std::pow(velNEDX,2)+std::pow(velNEDY,2)+std::pow(velNEDZ,2)); - RealType rhoSED = parameters.getParameter< RealType >( "SED-density" ); - RealType velSEDX = parameters.getParameter< RealType >( "SED-velocityX" ); - RealType velSEDY = parameters.getParameter< RealType >( "SED-velocityY" ); - RealType velSEDZ = parameters.getParameter< RealType >( "SED-velocityZ" ); - RealType preSED = parameters.getParameter< RealType >( "SED-pressure" ); - //RealType eSED = ( preSED / ( rhoSED * (gamma - 1) ) ); - RealType eSED = ( preSED / (gamma - 1) ) + 0.5 * rhoSED * (std::pow(velSEDX,2)+std::pow(velSEDY,2)+std::pow(velSEDZ,2)); - RealType x0 = parameters.getParameter< RealType >( "riemann-border" ); - int size = mesh->template getEntitiesCount< Cell >(); - uRho->bind(mesh, dofs, 0); - uRhoVelocityX->bind(mesh, dofs, size); - uRhoVelocityY->bind(mesh, dofs, 2*size); - uRhoVelocityZ->bind(mesh, dofs, 3*size); - uEnergy->bind(mesh, dofs, 4*size); - Containers::Vector< RealType, DeviceType, IndexType > data; - data.setSize(5*size); - pressure->bind(mesh, data, 0); - velocity->bind(mesh, data, size); - velocityX->bind(mesh, data, 2*size); - velocityY->bind(mesh, data, 3*size); - velocityZ->bind(mesh, data, 4*size); - int count = std::pow(size, (1.0/3.0)); - for(IndexType i = 0; i < count; i++) - for(IndexType j = 0; j < count; j++) - for(IndexType k = 0; k < count; k++) - if ((i <= x0 * count)&&(j <= x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSWD; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSWD * velSWDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSWD * velSWDY; - (* uRhoVelocityZ)[i*std::pow(count,2)+j*count+k] = rhoSWD * velSWDZ; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSWD; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSWDX,2)+std::pow(velSWDY,2)+std::pow(velSWDZ,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSWDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSWDY; - (* velocityZ)[i*std::pow(count,2)+j*count+k] = velSWDZ; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSWD; - } - else - if ((i <= x0 * count)&&(j <= x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSED; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSED * velSEDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSED * velSEDY; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSED; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSEDX,2)+std::pow(velSEDY,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSEDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSEDY; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSED; - } - else - if ((i <= x0 * count)&&(j > x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNWD; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNWD * velNWDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNWD * velNWDY; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNWD; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNWDX,2)+std::pow(velNWDY,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNWDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNWDY; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNWD; - } - else - if ((i <= x0 * count)&&(j > x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNED; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNED * velNEDX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNED * velNEDY; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNED; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNEDX,2)+std::pow(velNEDY,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNEDX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNEDY; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNED; - } - else - if ((i > x0 * count)&&(j <= x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSWU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSWU * velSWUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSWU * velSWUY; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSWU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSWUX,2)+std::pow(velSWUY,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSWUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSWUY; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSWU; - } - else - if ((i > x0 * count)&&(j <= x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoSEU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoSEU * velSEUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoSEU * velSEUY; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eSEU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velSEUX,2)+std::pow(velSEUY,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velSEUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velSEUY; - (* pressure)[i*std::pow(count,2)+j*count+k] = preSEU; - } - else - if ((i > x0 * count)&&(j > x0 * count)&&(k <= x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNWU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNWU * velNWUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNWU * velNWUY; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNWU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNWUX,2)+std::pow(velNWUY,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNWUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNWUY; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNWU; - } - else - if ((i > x0 * count)&&(j > x0 * count)&&(k > x0 * count) ) - { - (* uRho)[i*std::pow(count,2)+j*count+k] = rhoNEU; - (* uRhoVelocityX)[i*std::pow(count,2)+j*count+k] = rhoNEU * velNEUX; - (* uRhoVelocityY)[i*std::pow(count,2)+j*count+k] = rhoNEU * velNEUY; - (* uEnergy)[i*std::pow(count,2)+j*count+k] = eNEU; - (* velocity)[i*std::pow(count,2)+j*count+k] = std::sqrt(std::pow(velNEUX,2)+std::pow(velNEUY,2)); - (* velocityX)[i*std::pow(count,2)+j*count+k] = velNEUX; - (* velocityY)[i*std::pow(count,2)+j*count+k] = velNEUY; - (* pressure)[i*std::pow(count,2)+j*count+k] = preNEU; - }; - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -setupLinearSystem( const MeshPointer& mesh, - Matrix& matrix ) -{ -/* const IndexType dofs = this->getDofs( mesh ); - typedef typename Matrix::CompressedRowsLengthsVector CompressedRowsLengthsVectorType; - CompressedRowsLengthsVectorType rowLengths; - if( ! rowLengths.setSize( dofs ) ) - return false; - MatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, CompressedRowsLengthsVectorType > matrixSetter; - matrixSetter.template getCompressedRowsLengths< typename Mesh::Cell >( mesh, - differentialOperator, - boundaryCondition, - rowLengths ); - matrix.setDimensions( dofs, dofs ); - if( ! matrix.setCompressedRowsLengths( rowLengths ) ) - return false;*/ - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -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; - FileName fileName; - fileName.setExtension( "tnl" ); - fileName.setIndex( step ); - fileName.setFileNameBase( "rho-" ); - if( ! uRho->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelX-" ); - if( ! uRhoVelocityX->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelY-" ); - if( ! uRhoVelocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "rhoVelZ-" ); - if( ! uRhoVelocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "energy-" ); - if( ! uEnergy->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityX-" ); - if( ! velocityX->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityY-" ); - if( ! velocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocityZ-" ); - if( ! velocityY->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "velocity-" ); - if( ! velocity->save( fileName.getFileName() ) ) - return false; - fileName.setFileNameBase( "pressue-" ); - if( ! pressure->save( fileName.getFileName() ) ) - return false; - - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -getExplicitRHS( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - DofVectorPointer& _fu, - MeshDependentDataPointer& meshDependentData ) -{ - typedef typename MeshType::Cell Cell; - int count = mesh->template getEntitiesCount< Cell >(); - fuRho->bind( mesh, _fu, 0 ); - fuRhoVelocityX->bind( mesh, _fu, count ); - fuRhoVelocityY->bind( mesh, _fu, 2*count ); - fuRhoVelocityZ->bind( mesh, _fu, 3*count ); - fuEnergy->bind( mesh, _fu, 4*count ); - SharedPointer< Continuity > lF3DContinuity; - SharedPointer< MomentumX > lF3DMomentumX; - SharedPointer< MomentumY > lF3DMomentumY; - SharedPointer< MomentumZ > lF3DMomentumZ; - SharedPointer< Energy > lF3DEnergy; - - this->bindDofs( mesh, _u ); - //rho - lF3DContinuity->setTau(tau); - lF3DContinuity->setVelocityX( *velocityX ); - lF3DContinuity->setVelocityY( *velocityY ); - lF3DContinuity->setVelocityZ( *velocityZ ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Continuity, BoundaryCondition, RightHandSide > explicitUpdaterContinuity; - explicitUpdaterContinuity.template update< typename Mesh::Cell >( time, - mesh, - lF3DContinuity, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRho, - fuRho ); - - //rhoVelocityX - lF3DMomentumX->setTau(tau); - lF3DMomentumX->setVelocityX( *velocityX ); - lF3DMomentumX->setVelocityY( *velocityY ); - lF3DMomentumX->setVelocityZ( *velocityZ ); - lF3DMomentumX->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumX, BoundaryCondition, RightHandSide > explicitUpdaterMomentumX; - explicitUpdaterMomentumX.template update< typename Mesh::Cell >( time, - mesh, - lF3DMomentumX, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityX, - fuRhoVelocityX ); - - //rhoVelocityY - lF3DMomentumY->setTau(tau); - lF3DMomentumY->setVelocityX( *velocityX ); - lF3DMomentumY->setVelocityY( *velocityY ); - lF3DMomentumY->setVelocityZ( *velocityZ ); - lF3DMomentumY->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumY, BoundaryCondition, RightHandSide > explicitUpdaterMomentumY; - explicitUpdaterMomentumY.template update< typename Mesh::Cell >( time, - mesh, - lF3DMomentumY, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityY, - fuRhoVelocityY ); - - //rhoVelocityZ - lF3DMomentumZ->setTau(tau); - lF3DMomentumZ->setVelocityX( *velocityX ); - lF3DMomentumZ->setVelocityY( *velocityY ); - lF3DMomentumZ->setVelocityZ( *velocityZ ); - lF3DMomentumZ->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, MomentumZ, BoundaryCondition, RightHandSide > explicitUpdaterMomentumZ; - explicitUpdaterMomentumZ.template update< typename Mesh::Cell >( time, - mesh, - lF3DMomentumZ, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uRhoVelocityZ, - fuRhoVelocityZ ); - - //energy - lF3DEnergy->setTau(tau); - lF3DEnergy->setVelocityX( *velocityX ); - lF3DEnergy->setVelocityY( *velocityY ); - lF3DEnergy->setVelocityZ( *velocityZ ); - lF3DEnergy->setPressure( *pressure ); - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, Energy, BoundaryCondition, RightHandSide > explicitUpdaterEnergy; - explicitUpdaterEnergy.template update< typename Mesh::Cell >( time, - mesh, - lF3DEnergy, - this->boundaryConditionPointer, - this->rightHandSidePointer, - uEnergy, - fuEnergy ); - -/* -cout << "rho " << uRho.getData() << endl; -getchar(); -cout << "rhoVelX " << uRhoVelocityX.getData() << endl; -getchar(); -cout << "rhoVelY " << uRhoVelocityY.getData() << endl; -getchar(); -cout << "Energy " << uEnergy.getData() << endl; -getchar(); -cout << "velocity " << velocity.getData() << endl; -getchar(); -cout << "velocityX " << velocityX.getData() << endl; -getchar(); -cout << "velocityY " << velocityY.getData() << endl; -getchar(); -cout << "pressure " << pressure.getData() << endl; -getchar(); -*/ - - -/* - BoundaryConditionsSetter< MeshFunctionType, BoundaryCondition > boundaryConditionsSetter; - boundaryConditionsSetter.template apply< typename Mesh::Cell >( - this->boundaryCondition, - time + tau, - u );*/ - } - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > - template< typename Matrix > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b, - MeshDependentDataPointer& meshDependentData ) -{ -/* LinearSystemAssembler< Mesh, - MeshFunctionType, - DifferentialOperator, - 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 DifferentialOperator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: -postIterate( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ) -{ - - //velocityX - this->velocityX->setMesh( mesh ); - VelocityX velocityXGetter( *uRho, *uRhoVelocityX ); - *this->velocityX = velocityXGetter; - - //velocityY - this->velocityY->setMesh( mesh ); - VelocityX velocityYGetter( *uRho, *uRhoVelocityY ); - *this->velocityY = velocityYGetter; - - //velocityY - this->velocityZ->setMesh( mesh ); - VelocityX velocityZGetter( *uRho, *uRhoVelocityZ ); - *this->velocityZ = velocityZGetter; - - //velocity - this->velocity->setMesh( mesh ); - Velocity velocityGetter( *uRho, *uRhoVelocityX, *uRhoVelocityY, *uRhoVelocityZ); - *this->velocity = velocityGetter; - - //pressure - this->pressure->setMesh( mesh ); - Pressure pressureGetter( *uRho, *uRhoVelocityX, *uRhoVelocityY, *uRhoVelocityZ, *uEnergy, gamma ); - *this->pressure = pressureGetter; - - return true; -} - -} // namespace TNL - diff --git a/examples/inviscid-flow-sw/3d/run-euler b/examples/inviscid-flow-sw/3d/run-euler deleted file mode 100644 index f68b98a8406dea2f2142526283ec60248551c56d..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/run-euler +++ /dev/null @@ -1,19 +0,0 @@ -#!/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 -./euler --time-discretisation explicit \ - --boundary-conditions-constant 0 \ - --discrete-solver merson \ - --snapshot-period 0.01 \ - --final-time 1.0 - -tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/examples/inviscid-flow-sw/3d/tnl-run-euler-2d b/examples/inviscid-flow-sw/3d/tnl-run-euler-2d deleted file mode 100644 index 5af33a1a7943e44d0037deff948b4ecfdafedde8..0000000000000000000000000000000000000000 --- a/examples/inviscid-flow-sw/3d/tnl-run-euler-2d +++ /dev/null @@ -1,33 +0,0 @@ -#!/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 -# --boundary-conditions-type neumann \ -# --boundary-conditions-constant 0 \ - -tnl-euler-2d-dbg --time-discretisation explicit \ - --time-step 1.0e-3 \ - --boundary-conditions-type mymixed \ - --discrete-solver euler \ - --snapshot-period 0.1 \ - --final-time 1.0 \ - --left-density 1.0 \ - --left-velocityX 0.75 \ - --left-velocityY 0.75 \ - --left-pressure 1.0 \ - --right-density 0.125 \ - --right-velocityX 0 \ - --right-velocityY 0 \ - --right-pressure 0.1 \ - --gamma 1.4 \ - --riemann-border 0.3 \ - -tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/examples/inviscid-flow-vl/CMakeLists.txt b/examples/inviscid-flow-vl/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b4bfb671a157aff576d539c8ac523d284d50163 --- /dev/null +++ b/examples/inviscid-flow-vl/CMakeLists.txt @@ -0,0 +1,23 @@ +set( tnl_inviscid_flow_vl_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_inviscid_flow_vl_SOURCES + euler.cpp + euler.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-euler-vl${debugExt} euler.cu) + target_link_libraries (tnl-euler-vl${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-euler-vl${debugExt} euler.cpp) + target_link_libraries (tnl-euler-vl${debugExt} tnl${debugExt}-${tnlVersion} ) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-euler-vl${debugExt} + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-euler-vl + ${tnl_inviscid_flow_SOURCES} + DESTINATION share/tnl-${tnlVersion}/examples/inviscid-flow-vl ) diff --git a/examples/inviscid-flow-vl/CompressibleConservativeVariables.h b/examples/inviscid-flow-vl/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..a3afc845366f8df17b41c5affc5a4e49d5da052a --- /dev/null +++ b/examples/inviscid-flow-vl/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/inviscid-flow-vl/LaxFridrichs.h b/examples/inviscid-flow-vl/LaxFridrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..cdf32899f69eb797a6d9a18a52b84c09709867bf --- /dev/null +++ b/examples/inviscid-flow-vl/LaxFridrichs.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/inviscid-flow-vl/LaxFridrichsContinuity.h b/examples/inviscid-flow-vl/LaxFridrichsContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..45ad4d52b12d402365a40cac043d5525e230cecb --- /dev/null +++ b/examples/inviscid-flow-vl/LaxFridrichsContinuity.h @@ -0,0 +1,288 @@ +/*************************************************************************** + 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[ 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/inviscid-flow-vl/LaxFridrichsEnergy.h b/examples/inviscid-flow-vl/LaxFridrichsEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..18c824762b8c677253dbd4e494be7ad3aea7e769 --- /dev/null +++ b/examples/inviscid-flow-vl/LaxFridrichsEnergy.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/inviscid-flow-vl/LaxFridrichsMomentumBase.h b/examples/inviscid-flow-vl/LaxFridrichsMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..67dae9fdf8256cecf032a731dd5d616d715ca0fe --- /dev/null +++ b/examples/inviscid-flow-vl/LaxFridrichsMomentumBase.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/inviscid-flow-vl/LaxFridrichsMomentumX.h b/examples/inviscid-flow-vl/LaxFridrichsMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..63def12d315188b82e82402635fca863d1b9a629 --- /dev/null +++ b/examples/inviscid-flow-vl/LaxFridrichsMomentumX.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/inviscid-flow-vl/LaxFridrichsMomentumY.h b/examples/inviscid-flow-vl/LaxFridrichsMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..8ce42282dd4c74d5ed72d2abbd661235b95dc160 --- /dev/null +++ b/examples/inviscid-flow-vl/LaxFridrichsMomentumY.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/inviscid-flow-vl/LaxFridrichsMomentumZ.h b/examples/inviscid-flow-vl/LaxFridrichsMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..a67e862ceffd78d4fd770d7b1a07e9f05af349d8 --- /dev/null +++ b/examples/inviscid-flow-vl/LaxFridrichsMomentumZ.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/inviscid-flow-vl/PhysicalVariablesGetter.h b/examples/inviscid-flow-vl/PhysicalVariablesGetter.h new file mode 100644 index 0000000000000000000000000000000000000000..f1ba6bd1222b8653faeaac041606c101a071e188 --- /dev/null +++ b/examples/inviscid-flow-vl/PhysicalVariablesGetter.h @@ -0,0 +1,122 @@ +/*************************************************************************** + 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 + { + if( density.template getData< DeviceType >()( meshEntity ) == 0.0 ) + return 0; + else + 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 ); + if( rho == 0.0 ) + return 0; + else + 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/inviscid-flow-vl/RiemannProblemInitialCondition.h b/examples/inviscid-flow-vl/RiemannProblemInitialCondition.h new file mode 100644 index 0000000000000000000000000000000000000000..85fbc8af01994495e2c1f2f7d95f8155ee216684 --- /dev/null +++ b/examples/inviscid-flow-vl/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.59745, 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, + 0.1, 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.1, 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/inviscid-flow-vl/Upwind.h b/examples/inviscid-flow-vl/Upwind.h new file mode 100644 index 0000000000000000000000000000000000000000..263da044a2edaca855b6c6f3fd050bd10cc7c689 --- /dev/null +++ b/examples/inviscid-flow-vl/Upwind.h @@ -0,0 +1,151 @@ +/*************************************************************************** + Upwind.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 "UpwindContinuity.h" +#include "UpwindEnergy.h" +#include "UpwindMomentumX.h" +#include "UpwindMomentumY.h" +#include "UpwindMomentumZ.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class Upwind +{ + 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 UpwindContinuity< Mesh, Real, Index > ContinuityOperatorType; + typedef UpwindMomentumX< Mesh, Real, Index > MomentumXOperatorType; + typedef UpwindMomentumY< Mesh, Real, Index > MomentumYOperatorType; + typedef UpwindMomentumZ< Mesh, Real, Index > MomentumZOperatorType; + typedef UpwindEnergy< 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 = "" ) + { + } + + Upwind() + : artificialViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + 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 setGamma( const RealType& gamma ) + { + this->continuityOperatorPointer->setGamma( gamma ); + this->momentumXOperatorPointer->setGamma( gamma ); + this->momentumYOperatorPointer->setGamma( gamma ); + this->momentumZOperatorPointer->setGamma( gamma ); + this->energyOperatorPointer->setGamma( gamma ); + } + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->continuityOperatorPointer->setPressure( pressure ); + this->momentumXOperatorPointer->setPressure( pressure ); + this->momentumYOperatorPointer->setPressure( pressure ); + this->momentumZOperatorPointer->setPressure( pressure ); + this->energyOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + } + + 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/inviscid-flow-vl/UpwindContinuity.h b/examples/inviscid-flow-vl/UpwindContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..32ff1f88ec78667d9533e6ac5b179cbdb7c36746 --- /dev/null +++ b/examples/inviscid-flow-vl/UpwindContinuity.h @@ -0,0 +1,382 @@ +/*************************************************************************** + UpwindContinuity.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 UpwindContinuityBase +{ + 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; + + static String getType() + { + return String( "UpwindContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + RealType positiveDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ); + else + return density * velocity; + }; + + RealType negativeDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return density * velocity; + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + RealType multiply (const RealType& a, const RealType& b ) const + { + return a * b; + }; + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindContinuityBase< 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) + - this->positiveDensityFlux( u[ west ], velocity_x_west , pressure_west ) + - this->negativeDensityFlux( u[ center ], velocity_x_center, pressure_center ) + + this->negativeDensityFlux( u[ east ], velocity_x_east , pressure_east ) + ); + } + + /*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 UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindContinuityBase< 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) + - this->positiveDensityFlux( u[ west ], velocity_x_west , pressure_west ) + - this->negativeDensityFlux( u[ center ], velocity_x_center, pressure_center ) + + this->negativeDensityFlux( u[ east ], velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveDensityFlux( u[ center ], velocity_y_center, pressure_center ) + - this->positiveDensityFlux( u[ south ], velocity_y_south , pressure_south ) + - this->negativeDensityFlux( u[ center ], velocity_y_center, pressure_center ) + + this->negativeDensityFlux( u[ north ], velocity_y_north , pressure_north ) + ); + } + + /*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 UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindContinuityBase< 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) + - this->positiveDensityFlux( u[ west ], velocity_x_west , pressure_west ) + - this->negativeDensityFlux( u[ center ], velocity_x_center, pressure_center ) + + this->negativeDensityFlux( u[ east ], velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveDensityFlux( u[ center ], velocity_y_center, pressure_center ) + - this->positiveDensityFlux( u[ south ], velocity_y_south , pressure_south ) + - this->negativeDensityFlux( u[ center ], velocity_y_center, pressure_center ) + + this->negativeDensityFlux( u[ north ], velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveDensityFlux( u[ center ], velocity_z_center, pressure_center ) + - this->positiveDensityFlux( u[ down ], velocity_z_down , pressure_down ) + - this->negativeDensityFlux( u[ center ], velocity_z_center, pressure_center ) + + this->negativeDensityFlux( u[ up ], velocity_z_up , pressure_up ) + ); + + } + + /*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/inviscid-flow-vl/UpwindEnergy.h b/examples/inviscid-flow-vl/UpwindEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..4abc7e00b8643c2c5cb38978c2c9c96c54153e43 --- /dev/null +++ b/examples/inviscid-flow-vl/UpwindEnergy.h @@ -0,0 +1,504 @@ +/*************************************************************************** + UpwindEnergy.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 UpwindEnergyBase +{ + 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; + + UpwindEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "UpwindEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + RealType artificialViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindEnergyBase< 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; + + RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) + * ( + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); + }; + + RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) + * ( + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return 0.0; + }; + + 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveEnergyFlux( density_center, velocity_x_center, pressure_center) + - this->positiveEnergyFlux( density_west , velocity_x_west , pressure_west ) + - this->negativeEnergyFlux( density_center, velocity_x_center, pressure_center) + + this->negativeEnergyFlux( density_east , velocity_x_east , pressure_east ) + ); + + } + + /*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 UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindEnergyBase< 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; + + RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 ) ); + }; + + RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 ) ); + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return 0.0; + }; + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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 -hxInverse * ( + this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_west , velocity_x_west , velocity_y_west , pressure_west ) + - this->negativeEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_east , velocity_x_east , velocity_y_east , pressure_east ) + ) + -hyInverse * ( + this->positiveEnergyFlux( density_center, velocity_y_center, velocity_x_center, pressure_center) + - this->positiveEnergyFlux( density_south , velocity_y_south , velocity_x_south , pressure_south ) + - this->negativeEnergyFlux( density_center, velocity_y_center, velocity_x_center, pressure_center) + + this->negativeEnergyFlux( density_north , velocity_y_north , velocity_x_north , pressure_north ) + ); + } + + /*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 UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindEnergyBase< 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; + + RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& velocity_other2, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + velocity_other2 * velocity_other2 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) ); + }; + + RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other1, const RealType& velocity_other2, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main + velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) ); + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) + * ( + velocity_other1 * velocity_other1 / 2.0 + + velocity_other2 * velocity_other2 / 2.0 + + 2.0 * speedOfSound * speedOfSound / ( this->gamma * this->gamma - 1.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) + ); + else + return 0.0; + }; + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_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_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_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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_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_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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_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_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 -hxInverse * ( + this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) + - this->positiveEnergyFlux( density_west , velocity_x_west , velocity_y_west , velocity_z_west , pressure_west ) + - this->negativeEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) + + this->negativeEnergyFlux( density_east , velocity_x_east , velocity_y_east , velocity_z_east , pressure_east ) + ) + -hyInverse * ( + this->positiveEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + - this->positiveEnergyFlux( density_south , velocity_y_south , velocity_x_south , velocity_z_south , pressure_south ) + - this->negativeEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + + this->negativeEnergyFlux( density_north , velocity_y_north , velocity_x_north , velocity_z_north , pressure_north ) + ) + -hyInverse * ( + this->positiveEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_y_down , velocity_x_down , velocity_z_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_y_center, velocity_x_center, velocity_z_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_y_up , velocity_x_up , velocity_z_up , pressure_up ) + ); + } + + /*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/inviscid-flow-vl/UpwindMomentumBase.h b/examples/inviscid-flow-vl/UpwindMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..82d7ae48ae0686ac367fe7dcb53b869e3b4109f0 --- /dev/null +++ b/examples/inviscid-flow-vl/UpwindMomentumBase.h @@ -0,0 +1,122 @@ +/*************************************************************************** + UpwindMomentumBase.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 UpwindMomentumBase +{ + 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; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + RealType positiveMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return 0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ); + else + return density * velocity * velocity + pressure; + }; + + RealType negativeMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return density * velocity * velocity + pressure; + else if ( machNumber <= 1.0 ) + return - density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) * ( - 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.0 ); + else + return 0; + }; + + RealType positiveOtherMomentumFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return 0.0; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) * velocity_other; + else + return density * velocity_main * velocity_other; + }; + + RealType negativeOtherMomentumFlux( const RealType& density, const RealType& velocity_main, const RealType& velocity_other, const RealType& pressure ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity_main / speedOfSound; + if ( machNumber <= -1.0 ) + return density * velocity_main * velocity_other; + else if ( machNumber <= 1.0 ) + return - density * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) * velocity_other; + else + return 0.0; + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/examples/inviscid-flow-vl/UpwindMomentumX.h b/examples/inviscid-flow-vl/UpwindMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..ed49dda94585e64f85d820569a757d849757e6ca --- /dev/null +++ b/examples/inviscid-flow-vl/UpwindMomentumX.h @@ -0,0 +1,342 @@ +/*************************************************************************** + UpwindMomentumX.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 "UpwindMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + 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& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; + const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; + const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + - this->positiveMainMomentumFlux( density_west, velocity_x_west , pressure_west ) + - this->negativeMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + + this->negativeMainMomentumFlux( density_east, velocity_x_east , pressure_east ) + ); + } + + /*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 UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + - this->positiveMainMomentumFlux( density_west , velocity_x_west , pressure_west ) + - this->negativeMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + + this->negativeMainMomentumFlux( density_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_south , velocity_x_south , velocity_y_south , pressure_south ) + - this->negativeOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_north , velocity_x_north , velocity_y_north , pressure_north ) + ); + + + } + + /*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 UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_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_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_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + - this->positiveMainMomentumFlux( density_west , velocity_x_west , pressure_west ) + - this->negativeMainMomentumFlux( density_center, velocity_x_center, pressure_center ) + + this->negativeMainMomentumFlux( density_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_south , velocity_x_south , velocity_y_south , pressure_south ) + - this->negativeOtherMomentumFlux( density_center, velocity_x_center, velocity_y_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_north , velocity_x_north , velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_x_center, velocity_z_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_down , velocity_x_down , velocity_z_down , pressure_down ) + - this->negativeOtherMomentumFlux( density_center, velocity_x_center, velocity_z_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_up , velocity_x_up , velocity_z_up , pressure_up ) + ); + } + + /*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/inviscid-flow-vl/UpwindMomentumY.h b/examples/inviscid-flow-vl/UpwindMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..c2126d43af781289f86999a5f4a7f8d24ad5c6e8 --- /dev/null +++ b/examples/inviscid-flow-vl/UpwindMomentumY.h @@ -0,0 +1,318 @@ +/*************************************************************************** + UpwindMomentumY.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 "UpwindMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumY< " ) + + 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 UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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 -hxInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_west , velocity_y_west , velocity_x_west , pressure_west ) + - this->negativeOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_east , velocity_y_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + - this->positiveMainMomentumFlux( density_south , velocity_y_south , pressure_south ) + - this->negativeMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + + this->negativeMainMomentumFlux( density_north , velocity_y_north , pressure_north ) + ); + } + + /*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 UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_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_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_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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 -hxInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_west , velocity_y_west , velocity_x_west , pressure_west ) + - this->negativeOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_east , velocity_y_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + - this->positiveMainMomentumFlux( density_south , velocity_y_south , pressure_south ) + - this->negativeMainMomentumFlux( density_center, velocity_y_center, pressure_center ) + + this->negativeMainMomentumFlux( density_north , velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_z_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_down , velocity_y_down , velocity_z_down , pressure_down ) + - this->negativeOtherMomentumFlux( density_center, velocity_y_center, velocity_z_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_up , velocity_y_up , velocity_z_up , pressure_up ) + ); + } + + /*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/inviscid-flow-vl/UpwindMomentumZ.h b/examples/inviscid-flow-vl/UpwindMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..97339e804b3bda5203d0b12feeb59e30249f2327 --- /dev/null +++ b/examples/inviscid-flow-vl/UpwindMomentumZ.h @@ -0,0 +1,276 @@ +/*************************************************************************** + UpwindMomentumZ.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 "UpwindMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class UpwindMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumZ< " ) + + 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 UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumZ< " ) + + 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 UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef UpwindMomentumBase< 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( "UpwindMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + 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(); + + 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_center = this->pressure.template getData< DeviceType >()[ center ]; + 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& density_center = this->density.template getData< DeviceType >()[ center ]; + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; + 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_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; + 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_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_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 -hxInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_z_center, velocity_x_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_west , velocity_z_west , velocity_x_west , pressure_west ) + - this->negativeOtherMomentumFlux( density_center, velocity_z_center, velocity_x_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_east , velocity_z_east , velocity_x_east , pressure_east ) + ) + -hyInverse * ( + this->positiveOtherMomentumFlux( density_center, velocity_z_center, velocity_y_center, pressure_center ) + - this->positiveOtherMomentumFlux( density_south , velocity_z_south , velocity_y_south , pressure_south ) + - this->negativeOtherMomentumFlux( density_center, velocity_z_center, velocity_y_center, pressure_center ) + + this->negativeOtherMomentumFlux( density_north , velocity_z_north , velocity_y_north , pressure_north ) + ) + -hzInverse * ( + this->positiveMainMomentumFlux( density_center, velocity_z_center, pressure_center ) + - this->positiveMainMomentumFlux( density_down , velocity_z_down , pressure_down ) + - this->negativeMainMomentumFlux( density_center, velocity_z_center, pressure_center ) + + this->negativeMainMomentumFlux( density_up , velocity_z_up , pressure_up ) + ); + } + + + /*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/inviscid-flow-sw/3d/euler.cpp b/examples/inviscid-flow-vl/euler.cpp similarity index 100% rename from examples/inviscid-flow-sw/3d/euler.cpp rename to examples/inviscid-flow-vl/euler.cpp diff --git a/examples/inviscid-flow-sw/3d/euler-cuda.cu b/examples/inviscid-flow-vl/euler.cu similarity index 100% rename from examples/inviscid-flow-sw/3d/euler-cuda.cu rename to examples/inviscid-flow-vl/euler.cu diff --git a/examples/inviscid-flow-sw/1d/euler.h~ b/examples/inviscid-flow-vl/euler.h similarity index 61% rename from examples/inviscid-flow-sw/1d/euler.h~ rename to examples/inviscid-flow-vl/euler.h index 742ade98af40f4a45cae2aeb548aae4f8a45e2f5..b0e21ffe41b7991873dc90afd402897895ff6236 100644 --- a/examples/inviscid-flow-sw/1d/euler.h~ +++ b/examples/inviscid-flow-vl/euler.h @@ -5,23 +5,22 @@ #include <TNL/Operators/NeumannBoundaryConditions.h> #include <TNL/Functions/Analytic/Constant.h> #include "eulerProblem.h" -#include "LaxFridrichs1D.h" -#include "MyMixedBoundaryConditions.h" -#include "MyNeumannBoundaryConditions.h" - +#include "Upwind.h" #include "eulerRhs.h" #include "eulerBuildConfigTag.h" +#include "RiemannProblemInitialCondition.h" + using namespace TNL; typedef eulerBuildConfigTag BuildConfig; /**** - * Uncoment the following (and comment the previous line) for the complete build. + * 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, - * esppecially if CUDA is enabled. Use this, if you want, only for the final build, + * especially if CUDA is enabled. Use this, if you want, only for the final build, * not in the development phase. */ //typedef tnlDefaultConfigTag BuildConfig; @@ -31,22 +30,13 @@ template< typename ConfigTag >class eulerConfig public: static void configSetup( Config::ConfigDescription & config ) { - config.addDelimiter( "euler settings:" ); + config.addDelimiter( "Inviscid flow settings:" ); config.addEntry< String >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); - //config.addEntry< String >( "boundary-conditions-file", "Choose the boundary conditions type.", "u.tnl"); config.addEntryEnum< String >( "dirichlet" ); config.addEntryEnum< String >( "neumann" ); - config.addEntryEnum< String >( "mymixed" ); - config.addEntryEnum< String >( "myneumann" ); config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); - config.addEntry< double >( "left-density", "This sets a value of left density." ); - config.addEntry< double >( "left-velocity", "This sets a value of left velocity." ); - config.addEntry< double >( "left-pressure", "This sets a value of left pressure." ); - config.addEntry< double >( "riemann-border", "This sets a position of discontinuity." ); - config.addEntry< double >( "right-density", "This sets a value of right density." ); - config.addEntry< double >( "right-velocity", "This sets a value of right velocity." ); - config.addEntry< double >( "right-pressure", "This sets a value of right pressure." ); - config.addEntry< double >( "gamma", "This sets a value of gamma constant." ); + typedef Meshes::Grid< 3 > Mesh; + RiemannProblemInitialCondition< Mesh >::configSetup( config ); /**** * Add definition of your solver command line arguments. @@ -71,10 +61,10 @@ class eulerSetter static bool run( const Config::ParameterContainer & parameters ) { - enum { Dimensions = MeshType::getMeshDimensions() }; - typedef LaxFridrichs1D< MeshType, Real, Index > ApproximateOperator; + enum { Dimension = MeshType::getMeshDimension() }; + typedef Upwind< MeshType, Real, Index > ApproximateOperator; typedef eulerRhs< MeshType, Real > RightHandSide; - typedef Containers::StaticVector < MeshType::getMeshDimensions(), Real > Vertex; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; /**** * Resolve the template arguments of your solver here. @@ -84,10 +74,10 @@ class eulerSetter String boundaryConditionsType = parameters.getParameter< String >( "boundary-conditions-type" ); if( parameters.checkParameter( "boundary-conditions-constant" ) ) { - typedef Functions::Analytic::Constant< Dimensions, Real > Constant; + typedef Functions::Analytic::Constant< Dimension, Real > Constant; if( boundaryConditionsType == "dirichlet" ) { - typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; + typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; SolverStarter solverStarter; return solverStarter.template run< Problem >( parameters ); @@ -100,21 +90,7 @@ class eulerSetter typedef Functions::MeshFunction< MeshType > MeshFunction; if( boundaryConditionsType == "dirichlet" ) { - typedef Operators::DirichletBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - if( boundaryConditionsType == "mymixed" ) - { - typedef Operators::MyMixedBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - if( boundaryConditionsType == "myneumann" ) - { - typedef Operators::MyNeumannBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimensions(), Real, Index > BoundaryConditions; + typedef Operators::DirichletBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Problem; SolverStarter solverStarter; return solverStarter.template run< Problem >( parameters ); @@ -138,5 +114,3 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; return EXIT_SUCCESS; } - - diff --git a/examples/inviscid-flow-sw/3d/eulerBuildConfigTag.h b/examples/inviscid-flow-vl/eulerBuildConfigTag.h similarity index 84% rename from examples/inviscid-flow-sw/3d/eulerBuildConfigTag.h rename to examples/inviscid-flow-vl/eulerBuildConfigTag.h index b3727450de5e7030b04bed15f31bfd5ab8a6fbe9..fd639c4adfd2d4ea4fc04cdac6abeb30dd344c77 100644 --- a/examples/inviscid-flow-sw/3d/eulerBuildConfigTag.h +++ b/examples/inviscid-flow-vl/eulerBuildConfigTag.h @@ -21,14 +21,14 @@ 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 Dimensions > struct ConfigTagDimensions< eulerBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 2 ) }; }; +//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. */ -template< int Dimensions, typename Real, typename Device, typename Index > - struct ConfigTagMesh< eulerBuildConfigTag, Meshes::Grid< Dimensions, Real, Device, Index > > - { enum { enabled = ConfigTagDimensions< eulerBuildConfigTag, Dimensions >::enabled && +template< int Dimension, typename Real, typename Device, typename Index > + struct ConfigTagMesh< eulerBuildConfigTag, Meshes::Grid< Dimension, Real, Device, Index > > + { enum { enabled = ConfigTagDimension< eulerBuildConfigTag, Dimension >::enabled && ConfigTagReal< eulerBuildConfigTag, Real >::enabled && ConfigTagDevice< eulerBuildConfigTag, Device >::enabled && ConfigTagIndex< eulerBuildConfigTag, Index >::enabled }; }; @@ -48,5 +48,4 @@ template<> struct ConfigTagExplicitSolver< eulerBuildConfigTag, ExplicitEulerSol } // namespace Solvers } // namespace TNL - #endif /* eulerBUILDCONFIGTAG_H_ */ diff --git a/examples/inviscid-flow-sw/3d/eulerProblem.h b/examples/inviscid-flow-vl/eulerProblem.h similarity index 66% rename from examples/inviscid-flow-sw/3d/eulerProblem.h rename to examples/inviscid-flow-vl/eulerProblem.h index 6869dcb525083d855a32d681ed3754d05e0cd930..ea9e3155641613eb0cb20712fbc1416d883e1de5 100644 --- a/examples/inviscid-flow-sw/3d/eulerProblem.h +++ b/examples/inviscid-flow-vl/eulerProblem.h @@ -1,7 +1,19 @@ +/*************************************************************************** + eulerProblem.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; @@ -10,24 +22,19 @@ namespace TNL { template< typename Mesh, typename BoundaryCondition, typename RightHandSide, - typename DifferentialOperator > + typename InviscidOperators > class eulerProblem: public PDEProblem< Mesh, - typename DifferentialOperator::RealType, - typename Mesh::DeviceType, - typename DifferentialOperator::IndexType > + typename InviscidOperators::RealType, + typename Mesh::DeviceType, + typename InviscidOperators::IndexType > { public: - - typedef typename DifferentialOperator::RealType RealType; + + typedef typename InviscidOperators::RealType RealType; typedef typename Mesh::DeviceType DeviceType; - typedef typename DifferentialOperator::IndexType IndexType; - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - typedef SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; - typedef SharedPointer< DifferentialOperator > DifferentialOperatorPointer; - typedef SharedPointer< BoundaryCondition > BoundaryConditionPointer; - typedef SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - typedef PDEProblem< Mesh, RealType, DeviceType, IndexType > BaseType; + typedef typename InviscidOperators::IndexType IndexType; + typedef PDEProblem< Mesh, RealType, DeviceType, IndexType > BaseType; using typename BaseType::MeshType; using typename BaseType::MeshPointer; @@ -36,14 +43,17 @@ class eulerProblem: using typename BaseType::MeshDependentDataType; using typename BaseType::MeshDependentDataPointer; - typedef typename DifferentialOperator::Continuity Continuity; - typedef typename DifferentialOperator::MomentumX MomentumX; - typedef typename DifferentialOperator::MomentumY MomentumY; - typedef typename DifferentialOperator::MomentumZ MomentumZ; - typedef typename DifferentialOperator::Energy Energy; - typedef typename DifferentialOperator::Velocity Velocity; - typedef typename DifferentialOperator::VelocityX VelocityX; - typedef typename DifferentialOperator::Pressure Pressure; + 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(); @@ -76,7 +86,7 @@ class eulerProblem: void bindDofs( const MeshPointer& mesh, DofVectorPointer& dofs ); - void getExplicitRHS( const RealType& time, + void getExplicitUpdate( const RealType& time, const RealType& tau, const MeshPointer& mesh, DofVectorPointer& _u, @@ -100,17 +110,18 @@ class eulerProblem: protected: - DifferentialOperatorPointer differentialOperatorPointer; + InviscidOperatorsPointer inviscidOperatorsPointer; + BoundaryConditionPointer boundaryConditionPointer; RightHandSidePointer rightHandSidePointer; - - MeshFunctionPointer uRho, uRhoVelocityX, uRhoVelocityY, uRhoVelocityZ, uEnergy; - MeshFunctionPointer fuRho, fuRhoVelocityX, fuRhoVelocityY, fuRhoVelocityZ, fuEnergy; - MeshFunctionPointer pressure, velocity, velocityX, velocityY, velocityZ; + ConservativeVariablesPointer conservativeVariables, + conservativeVariablesRHS; - RealType gamma; - + VelocityFieldPointer velocity; + MeshFunctionPointer pressure; + + RealType gamma; }; } // namespace TNL diff --git a/examples/inviscid-flow-vl/eulerProblem_impl.h b/examples/inviscid-flow-vl/eulerProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..e061360c2cc1ed0a1bcd8783c7a84d8aa64d7828 --- /dev/null +++ b/examples/inviscid-flow-vl/eulerProblem_impl.h @@ -0,0 +1,428 @@ +/*************************************************************************** + eulerProblem_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 "eulerProblem.h" + +#include "UpwindContinuity.h" +#include "UpwindEnergy.h" +#include "UpwindMomentumX.h" +#include "UpwindMomentumY.h" +#include "UpwindMomentumZ.h" + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +String +eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +getTypeStatic() +{ + return String( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +String +eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >:: +getPrologHeader() const +{ + return String( "Inviscid flow solver" ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +void +eulerProblem< 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 +eulerProblem< 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 eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators >::IndexType +eulerProblem< 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 +eulerProblem< 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 +eulerProblem< 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 +eulerProblem< 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 +eulerProblem< 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; + + fileName.setFileNameBase( "momentum-" ); + if( ! this->conservativeVariables->getMomentum()->save( fileName.getFileName() ) ) + return false; + + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename InviscidOperators > +void +eulerProblem< 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 ); + +// this->pressure->write( "pressure1", "gnuplot" ); +// getchar(); + /**** + * 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 ); + this->inviscidOperatorsPointer->setDensity( this->conservativeVariables->getDensity() ); + this->inviscidOperatorsPointer->setGamma( this->gamma ); + +// this->pressure->write( "pressure2", "gnuplot" ); +// getchar(); + /**** + * 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->conservativeVariablesRHS->getEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); + +/* this->pressure->write( "pressure3", "gnuplot" ); + getchar(); + 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 +eulerProblem< 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 +eulerProblem< 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 euler2DVelocity; + VelocityX euler2DVelocityX; + VelocityY euler2DVelocityY; + Pressure euler2DPressure; + + //velocityX + euler2DVelocityX.setRhoVelX(uRhoVelocityX); + euler2DVelocityX.setRho(uRho); +// OperatorFunction< VelocityX, MeshFunction, void, true > OFVelocityX; +// velocityX = OFVelocityX; + + //velocityY + euler2DVelocityY.setRhoVelY(uRhoVelocityY); + euler2DVelocityY.setRho(uRho); +// OperatorFunction< VelocityY, MeshFunction, void, time > OFVelocityY; +// velocityY = OFVelocityY; + + //velocity + euler2DVelocity.setVelX(velocityX); + euler2DVelocity.setVelY(velocityY); +// OperatorFunction< Velocity, MeshFunction, void, time > OFVelocity; +// velocity = OFVelocity; + + //pressure + euler2DPressure.setGamma(gamma); + euler2DPressure.setVelocity(velocity); + euler2DPressure.setEnergy(uEnergy); + euler2DPressure.setRho(uRho); +// OperatorFunction< euler2DPressure, MeshFunction, void, time > OFPressure; +// pressure = OFPressure; + */ + return true; +} + +} // namespace TNL + diff --git a/examples/inviscid-flow-sw/3d/eulerRhs.h b/examples/inviscid-flow-vl/eulerRhs.h similarity index 76% rename from examples/inviscid-flow-sw/3d/eulerRhs.h rename to examples/inviscid-flow-vl/eulerRhs.h index 1b46dc831fe9daa6133ff32ee4bea5faf4eb8d1c..51d4e024398d579f49c158292e2890536a1e319c 100644 --- a/examples/inviscid-flow-sw/3d/eulerRhs.h +++ b/examples/inviscid-flow-vl/eulerRhs.h @@ -6,7 +6,7 @@ namespace TNL { template< typename Mesh, typename Real >class eulerRhs - : public Functions::Domain< Mesh::meshDimensions, Functions::MeshDomain > + : public Functions::Domain< Mesh::getMeshDimension(), Functions::MeshDomain > { public: @@ -24,8 +24,8 @@ template< typename Mesh, typename Real >class eulerRhs Real operator()( const MeshEntity& entity, const Real& time = 0.0 ) const { - typedef typename MeshEntity::MeshType::VertexType VertexType; - VertexType v = entity.getCenter(); + typedef typename MeshEntity::MeshType::PointType PointType; + PointType v = entity.getCenter(); return 0.0; } }; diff --git a/examples/inviscid-flow-vl/run-euler b/examples/inviscid-flow-vl/run-euler new file mode 100644 index 0000000000000000000000000000000000000000..9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c --- /dev/null +++ b/examples/inviscid-flow-vl/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