diff --git a/src/Examples/CMakeLists.txt b/src/Examples/CMakeLists.txt index 2d46b24465629193ff505257561e974f8fa55a4a..b0ed1aa082cccfb4c000208b7a13b7bb51f0730c 100644 --- a/src/Examples/CMakeLists.txt +++ b/src/Examples/CMakeLists.txt @@ -3,14 +3,13 @@ ADD_SUBDIRECTORY( Containers ) add_subdirectory( simple-examples ) add_subdirectory( heat-equation ) add_subdirectory( transport-equation ) -add_subdirectory( navier-stokes ) -add_subdirectory( inviscid-flow ) -add_subdirectory( inviscid-flow-sw ) -add_subdirectory( inviscid-flow-vl ) +#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 ) +add_subdirectory( flows ) +add_subdirectory( turbulent-flows ) ADD_EXECUTABLE( ConfigDescriptionExample ConfigDescriptionExample.cpp ) @@ -93,4 +92,4 @@ ADD_CUSTOM_TARGET( RunExamples ALL DEPENDS if( BUILD_CUDA ) ADD_CUSTOM_TARGET( RunExamples-cuda ALL DEPENDS FileExampleCuda.out ) -ENDIF() \ No newline at end of file +ENDIF() diff --git a/src/Examples/advection/Riemann1DBoundaryConditions.h b/src/Examples/advection/Riemann1DBoundaryConditions.h deleted file mode 100644 index 69ea8ebe8cf0009132d824c2b431de24150b7f24..0000000000000000000000000000000000000000 --- a/src/Examples/advection/Riemann1DBoundaryConditions.h +++ /dev/null @@ -1,150 +0,0 @@ -//** coppied and changed -/*************************************************************************** - tnlRiemann1DBoundaryConditions.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 TNLRIEMANN1DBOUNDARYCONDITIONS_H_ -#define TNLRIEMANN1DBOUNDARYCONDITIONS_H_ - -#pragma once - -#include -#include -#include -#include - -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 Riemann1DBoundaryConditions -: 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 Pointers::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(); - if( entity.getCoordinates().x() == 0 ) - return 1.0; - else - return 0.0; - //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 Riemann1DBoundaryConditions< Mesh, Function >& bc ) -{ - str << "Riemann1D boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL -#endif /* TNLRIEMANN1DBOUNDARYCONDITIONS_H_ */ diff --git a/src/Examples/advection/Riemann2DBoundaryConditions.h b/src/Examples/advection/Riemann2DBoundaryConditions.h deleted file mode 100644 index 33cafb77376ee5ddd0188f6ab7bd3fcb6ffaf6e4..0000000000000000000000000000000000000000 --- a/src/Examples/advection/Riemann2DBoundaryConditions.h +++ /dev/null @@ -1,153 +0,0 @@ -//** coppied and changed -/*************************************************************************** - tnlRiemann2DBoundaryConditions.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 TNLRIEMANN2DBOUNDARYCONDITIONS_H_ -#define TNLRIEMANN2DBOUNDARYCONDITIONS_H_ - -#pragma once - -#include -#include -#include -#include - -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 Riemann2DBoundaryConditions -: 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 Pointers::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() < count * 0.5 ) - return 1; - else - return 0; - //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 Riemann2DBoundaryConditions< Mesh, Function >& bc ) -{ - str << "Riemann2D boundary conditions: vector = " << bc.getVector(); - return str; -} - -} // namespace Operators -} // namespace TNL -#endif /* RIEMANN2DBOUNDARYCONDITIONS_H_ */ diff --git a/src/Examples/advection/tnl-run-advection b/src/Examples/advection/tnl-run-advection deleted file mode 100644 index 28686f1d02af2c536d2095823c033db407baec36..0000000000000000000000000000000000000000 --- a/src/Examples/advection/tnl-run-advection +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -tnl-grid-setup --dimensions 1 \ - --origin-x 0.0 \ - --proportions-x 1.0 \ - --size-x 50 \ - -#tnl-init --test-function sin-wave \ -# --output-file init.tnl -~/bak/tnl/Debug/bin/tnl-advection-dbg --time-discretisation explicit \ - --time-step 2.0e-2 \ - --boundary-conditions-constant 0 \ - --discrete-solver euler \ - --snapshot-period 1.0\ - --final-time 2.0 \ - --artifical-viscosity 0.5 \ - --begin exp \ - --move advection \ - --advection-speedX 0.2 \ - --dimension 1 \ - --realSize 1.0 - -tnl-view --mesh mesh.tnl --input-files *tnl - -tnl-diff --mesh mesh.tnl \ - --input-files a-*.tnl u-*.tnl \ - --mode halves \ - diff --git a/src/Examples/flow-sw/CMakeLists.txt b/src/Examples/flow-sw/CMakeLists.txt deleted file mode 100644 index cd53d411c9bbbe508f711890f9e1a3eab5063cb8..0000000000000000000000000000000000000000 --- a/src/Examples/flow-sw/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -set( tnl_flow_sw_HEADERS - CompressibleConservativeVariables.h ) - -set( tnl_flow_sw_SOURCES - navierStokes.cpp - navierStokes.cu ) - -IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE(tnl-navier-stokes-sw navierStokes.cu) - target_link_libraries (tnl-navier-stokes-sw ${CUSPARSE_LIBRARY} ) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE(tnl-navier-stokes-sw navierStokes.cpp) -ENDIF( BUILD_CUDA ) - - -INSTALL( TARGETS tnl-navier-stokes-sw - RUNTIME DESTINATION bin - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) - -INSTALL( FILES run-navier-stokes-sw - ${tnl_inviscid_flow_SOURCES} - DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/navier-stokes-sw ) diff --git a/src/Examples/flow-sw/navierStokes.h b/src/Examples/flow-sw/navierStokes.h deleted file mode 100644 index 0d37ad41cb9435f34d142b0b4af06b0e161c4ada..0000000000000000000000000000000000000000 --- a/src/Examples/flow-sw/navierStokes.h +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include -#include -#include -#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, - typename Communicator > -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, Communicator > 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, Communicator > 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/src/Examples/flow-sw/navierStokesBuildConfigTag.h b/src/Examples/flow-sw/navierStokesBuildConfigTag.h deleted file mode 100644 index 9267843d5269e589d4316525a6afda8dd59f61dc..0000000000000000000000000000000000000000 --- a/src/Examples/flow-sw/navierStokesBuildConfigTag.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef navierStokesBUILDCONFIGTAG_H_ -#define navierStokesBUILDCONFIGTAG_H_ - -#include - -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 }; }; - -/**** - * 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 Meshes { -namespace BuildConfigTags { - -template< int Dimensions > struct GridDimensionTag< navierStokesBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 1 ) }; }; - -/**** - * Turn off support for float and long double. - */ -template<> struct GridRealTag< navierStokesBuildConfigTag, float > { enum { enabled = false }; }; -template<> struct GridRealTag< navierStokesBuildConfigTag, long double > { enum { enabled = false }; }; - -/**** - * Turn off support for short int and long int indexing. - */ -template<> struct GridIndexTag< navierStokesBuildConfigTag, short int >{ enum { enabled = false }; }; -template<> struct GridIndexTag< navierStokesBuildConfigTag, long int >{ enum { enabled = false }; }; - -} // namespace BuildConfigTags -} // namespace Meshes - -} // namespace TNL - -#endif /* navierStokesBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/flow-sw/navierStokesProblem_impl.h b/src/Examples/flow-sw/navierStokesProblem_impl.h deleted file mode 100644 index 886c9f03f4e981cd9533d72ba5f71809388c6438..0000000000000000000000000000000000000000 --- a/src/Examples/flow-sw/navierStokesProblem_impl.h +++ /dev/null @@ -1,458 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include -#include - -#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, - typename Communicator > -String -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getTypeStatic() -{ - return String( "navierStokesProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -String -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getPrologHeader() const -{ - return String( "Inviscid flow solver" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || - ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - this->gamma = parameters.getParameter< double >( "gamma" ); - velocity->setMesh( this->getMesh() ); - pressure->setMesh( this->getMesh() ); - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -typename navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >::IndexType -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getDofs() const -{ - /**** - * Return number of DOFs (degrees of freedom) i.e. number - * of unknowns to be resolved by the main solver. - */ - return this->conservativeVariables->getDofs( this->getMesh() ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -bindDofs( DofVectorPointer& dofVector ) -{ - this->conservativeVariables->bind( this->getMesh(), dofVector ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - DofVectorPointer& dofs ) -{ - CompressibleConservativeVariables< MeshType > conservativeVariables; - conservativeVariables.bind( this->getMesh(), 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, - typename Communicator > - template< typename Matrix > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setupLinearSystem( 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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -makeSnapshot( const RealType& time, - const IndexType& step, - DofVectorPointer& dofs ) -{ - std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; - - this->bindDofs( 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-" ); - this->conservativeVariables->getDensity()->save( fileName.getFileName() ); - - fileName.setFileNameBase( "velocity-" ); - this->velocity->save( fileName.getFileName() ); - - fileName.setFileNameBase( "pressure-" ); - this->pressure->save( fileName.getFileName() ); - - /*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, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getExplicitUpdate( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - DofVectorPointer& _fu ) -{ - typedef typename MeshType::Cell Cell; - const MeshPointer& mesh = this->getMesh(); - - /**** - * 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, - typename Communicator > - template< typename Matrix > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b ) -{ -/* 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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -postIterate( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs ) -{ - /* - 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/src/Examples/flow-sw/navierStokesRhs.h b/src/Examples/flow-sw/navierStokesRhs.h deleted file mode 100644 index 3c82ad4539292a4470fd88e9e3a6d03cd8ae2833..0000000000000000000000000000000000000000 --- a/src/Examples/flow-sw/navierStokesRhs.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef navierStokesRHS_H_ -#define navierStokesRHS_H_ - -#include - -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/src/Examples/flow-sw/run-navier-stokes-sw b/src/Examples/flow-sw/run-navier-stokes-sw deleted file mode 100644 index 9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c..0000000000000000000000000000000000000000 --- a/src/Examples/flow-sw/run-navier-stokes-sw +++ /dev/null @@ -1,25 +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 -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/src/Examples/flow-vl/CMakeLists.txt b/src/Examples/flow-vl/CMakeLists.txt deleted file mode 100644 index 47bb72276e06c9a7944b964260b23f78c572e988..0000000000000000000000000000000000000000 --- a/src/Examples/flow-vl/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -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 navierStokes.cu) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE(tnl-navier-stokes-vl navierStokes.cpp) -ENDIF( BUILD_CUDA ) - - -INSTALL( TARGETS tnl-navier-stokes-vl - 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 ${TNL_TARGET_DATA_DIRECTORY}/examples/navier-stokes-vl ) diff --git a/src/Examples/flow-vl/navierStokes.cu b/src/Examples/flow-vl/navierStokes.cu deleted file mode 100644 index 7dffcb059fb68607cfb12a94f3b929fb0f517ce8..0000000000000000000000000000000000000000 --- a/src/Examples/flow-vl/navierStokes.cu +++ /dev/null @@ -1 +0,0 @@ -#include "navierStokes.h" diff --git a/src/Examples/flow-vl/navierStokes.h b/src/Examples/flow-vl/navierStokes.h deleted file mode 100644 index 0d37ad41cb9435f34d142b0b4af06b0e161c4ada..0000000000000000000000000000000000000000 --- a/src/Examples/flow-vl/navierStokes.h +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include -#include -#include -#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, - typename Communicator > -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, Communicator > 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, Communicator > 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/src/Examples/flow-vl/navierStokesBuildConfigTag.h b/src/Examples/flow-vl/navierStokesBuildConfigTag.h deleted file mode 100644 index 9267843d5269e589d4316525a6afda8dd59f61dc..0000000000000000000000000000000000000000 --- a/src/Examples/flow-vl/navierStokesBuildConfigTag.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef navierStokesBUILDCONFIGTAG_H_ -#define navierStokesBUILDCONFIGTAG_H_ - -#include - -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 }; }; - -/**** - * 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 Meshes { -namespace BuildConfigTags { - -template< int Dimensions > struct GridDimensionTag< navierStokesBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 1 ) }; }; - -/**** - * Turn off support for float and long double. - */ -template<> struct GridRealTag< navierStokesBuildConfigTag, float > { enum { enabled = false }; }; -template<> struct GridRealTag< navierStokesBuildConfigTag, long double > { enum { enabled = false }; }; - -/**** - * Turn off support for short int and long int indexing. - */ -template<> struct GridIndexTag< navierStokesBuildConfigTag, short int >{ enum { enabled = false }; }; -template<> struct GridIndexTag< navierStokesBuildConfigTag, long int >{ enum { enabled = false }; }; - -} // namespace BuildConfigTags -} // namespace Meshes - -} // namespace TNL - -#endif /* navierStokesBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/flow-vl/navierStokesProblem_impl.h b/src/Examples/flow-vl/navierStokesProblem_impl.h deleted file mode 100644 index 886c9f03f4e981cd9533d72ba5f71809388c6438..0000000000000000000000000000000000000000 --- a/src/Examples/flow-vl/navierStokesProblem_impl.h +++ /dev/null @@ -1,458 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include -#include - -#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, - typename Communicator > -String -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getTypeStatic() -{ - return String( "navierStokesProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -String -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getPrologHeader() const -{ - return String( "Inviscid flow solver" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || - ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - this->gamma = parameters.getParameter< double >( "gamma" ); - velocity->setMesh( this->getMesh() ); - pressure->setMesh( this->getMesh() ); - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -typename navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >::IndexType -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getDofs() const -{ - /**** - * Return number of DOFs (degrees of freedom) i.e. number - * of unknowns to be resolved by the main solver. - */ - return this->conservativeVariables->getDofs( this->getMesh() ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -bindDofs( DofVectorPointer& dofVector ) -{ - this->conservativeVariables->bind( this->getMesh(), dofVector ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - DofVectorPointer& dofs ) -{ - CompressibleConservativeVariables< MeshType > conservativeVariables; - conservativeVariables.bind( this->getMesh(), 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, - typename Communicator > - template< typename Matrix > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setupLinearSystem( 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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -makeSnapshot( const RealType& time, - const IndexType& step, - DofVectorPointer& dofs ) -{ - std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; - - this->bindDofs( 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-" ); - this->conservativeVariables->getDensity()->save( fileName.getFileName() ); - - fileName.setFileNameBase( "velocity-" ); - this->velocity->save( fileName.getFileName() ); - - fileName.setFileNameBase( "pressure-" ); - this->pressure->save( fileName.getFileName() ); - - /*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, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getExplicitUpdate( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - DofVectorPointer& _fu ) -{ - typedef typename MeshType::Cell Cell; - const MeshPointer& mesh = this->getMesh(); - - /**** - * 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, - typename Communicator > - template< typename Matrix > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b ) -{ -/* 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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -postIterate( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs ) -{ - /* - 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/src/Examples/flow-vl/navierStokesRhs.h b/src/Examples/flow-vl/navierStokesRhs.h deleted file mode 100644 index 3c82ad4539292a4470fd88e9e3a6d03cd8ae2833..0000000000000000000000000000000000000000 --- a/src/Examples/flow-vl/navierStokesRhs.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef navierStokesRHS_H_ -#define navierStokesRHS_H_ - -#include - -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/src/Examples/flow-vl/run-navier-stokes-vl b/src/Examples/flow-vl/run-navier-stokes-vl deleted file mode 100644 index 9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c..0000000000000000000000000000000000000000 --- a/src/Examples/flow-vl/run-navier-stokes-vl +++ /dev/null @@ -1,25 +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 -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/src/Examples/flow/LaxFridrichsEnergy.h b/src/Examples/flow/LaxFridrichsEnergy.h deleted file mode 100644 index dd940243d7fbaa59ae66d013451cd24c2def8488..0000000000000000000000000000000000000000 --- a/src/Examples/flow/LaxFridrichsEnergy.h +++ /dev/null @@ -1,518 +0,0 @@ -/*************************************************************************** - 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 -#include - -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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; - - LaxFridrichsEnergyBase() - : artificialViscosity( 1.0 ){}; - - static String getType() - { - return String( "LaxFridrichsEnergy< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; - } - - void setTau(const Real& tau) - { - this->tau = tau; - }; - - void setVelocity( const VelocityFieldPointer& velocity ) - { - this->velocity = velocity; - }; - - void setPressure( const MeshFunctionPointer& pressure ) - { - this->pressure = pressure; - }; - - void setArtificialViscosity( const RealType& artificialViscosity ) - { - this->artificialViscosity = artificialViscosity; - } - - void setDynamicalViscosity( const RealType& dynamicalViscosity ) - { - this->dynamicalViscosity = dynamicalViscosity; - } - - protected: - - RealType tau; - - VelocityFieldPointer velocity; - - MeshFunctionPointer pressure; - - RealType artificialViscosity, dynamicalViscosity; -}; - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class LaxFridrichsEnergy -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; - - using typename BaseType::RealType; - using typename BaseType::IndexType; - using typename BaseType::DeviceType; - using typename BaseType::CoordinatesType; - using typename BaseType::MeshFunctionType; - using typename BaseType::MeshFunctionPointer; - using typename BaseType::VelocityFieldType; - using typename BaseType::VelocityFieldPointer; - using BaseType::Dimensions; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& e, - const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); - - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); - - const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - - return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( e[ west ] - 2.0 * e[ center ] + e[ east ] ) - - 0.5 * ( ( e[ east ] + pressure_east ) * velocity_x_east - - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse -// 1D uT_11_x - - 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west - - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west - ) * hxSquareInverse / 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 LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; - - using typename BaseType::RealType; - using typename BaseType::IndexType; - using typename BaseType::DeviceType; - using typename BaseType::CoordinatesType; - using typename BaseType::MeshFunctionType; - using typename BaseType::MeshFunctionPointer; - using typename BaseType::VelocityFieldType; - using typename BaseType::VelocityFieldPointer; - using BaseType::Dimensions; - - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& e, - const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); - - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); - const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - - const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); - const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); - const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); - const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); - const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; - const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; - - const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_x_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; - - const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_y_east = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_y_west = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; - - return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( e[ west ] + e[ east ] + e[ south ] + e[ north ] - 4.0 * e[ center ] ) - - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) - -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse - + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) - -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ) -// 2D uT_11_x - + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west - - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west - ) * hxSquareInverse - - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east - velocity_y_southEast * velocity_x_east - - velocity_y_northWest * velocity_x_west + velocity_y_southWest * velocity_x_west - ) * hxInverse * hyInverse / 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 LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; - - using typename BaseType::RealType; - using typename BaseType::IndexType; - using typename BaseType::DeviceType; - using typename BaseType::CoordinatesType; - using typename BaseType::MeshFunctionType; - using typename BaseType::MeshFunctionPointer; - using typename BaseType::VelocityFieldType; - using typename BaseType::VelocityFieldPointer; - using BaseType::Dimensions; - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& e, - const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); - - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); - const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); - const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - - const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); - const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); - const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); - const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); - const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); - const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); - const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); - const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); - const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); - const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); - const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); - const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); - const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; - const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; - const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; - const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; - - const RealType& velocity_x_north = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_x_south = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_up = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ up ]; - const RealType& velocity_x_down = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ down ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; - - const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_y_east = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_y_west = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_y_up = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ up ]; - const RealType& velocity_y_down = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ down ]; - const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; - - const RealType& velocity_z_north = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_z_south = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_z_east = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_z_west = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; - const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; - const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; - - return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * - ( e[ west ] + e[ east ] + e[ south ] + e[ north ] + e[ up ] + e[ down ] - 6.0 * e[ center ] ) - - 0.5 * ( ( ( ( e[ east ] + pressure_east ) * velocity_x_east ) - -( ( e[ west ] + pressure_west ) * velocity_x_west ) ) * hxInverse - + ( ( ( e[ north ] + pressure_north ) * velocity_y_north ) - -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse - + ( ( ( e[ up ] + pressure_up ) * velocity_z_up ) - -( ( e[ down ] + pressure_down ) * velocity_z_down ) ) * hzInverse ) -// 3D uT_11_x - + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west - - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west - ) * hxSquareInverse - - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east - velocity_y_southEast * velocity_x_east - - velocity_y_northWest * velocity_x_west + velocity_y_southWest * velocity_x_west - ) * hxInverse * hyInverse / 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/src/Examples/flow/LaxFridrichsEuler.h b/src/Examples/flow/LaxFridrichsEuler.h deleted file mode 100644 index c56d20aed9947bd16796a5bf7ceb22adb237bf0c..0000000000000000000000000000000000000000 --- a/src/Examples/flow/LaxFridrichsEuler.h +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - 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 -#include -#include - -#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; - typedef Pointers::SharedPointer< MeshType > MeshPointer; - - typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; - typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; - typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; - typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; - typedef Pointers::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/src/Examples/flow/LaxFridrichsMomentumX.h b/src/Examples/flow/LaxFridrichsMomentumX.h deleted file mode 100644 index 3e295c029f9bc4ae61dfc54650be4c4aff55cf18..0000000000000000000000000000000000000000 --- a/src/Examples/flow/LaxFridrichsMomentumX.h +++ /dev/null @@ -1,383 +0,0 @@ -/*************************************************************************** - 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 -#include -#include "LaxFridrichsMomentumBase.h" - -namespace TNL { - -template< typename Mesh, - typename Real = typename Mesh::RealType, - typename Index = typename Mesh::IndexType > -class LaxFridrichsMomentumX -{ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - - typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; - - using typename BaseType::RealType; - using typename BaseType::IndexType; - using typename BaseType::DeviceType; - using typename BaseType::CoordinatesType; - using typename BaseType::MeshFunctionType; - using typename BaseType::MeshFunctionPointer; - using typename BaseType::VelocityFieldType; - using typename BaseType::VelocityFieldPointer; - using BaseType::Dimensions; - - static String getType() - { - return String( "LaxFridrichsMomentumX< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; - } - - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& rho_u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); - const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); - - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); - - const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - - return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] - 2.0 * rho_u[ center ] ) - - 0.5 * ( ( rho_u[ east ] * velocity_x_east + pressure_east ) - -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse -// 1D T_11_x - - 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west - ) * hxSquareInverse - * this->dynamicalViscosity; - } - - /*template< typename MeshEntity > - __cuda_callable__ - Index getLinearSystemRowLength( const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity ) const; - - template< typename MeshEntity, typename Vector, typename MatrixRow > - __cuda_callable__ - void updateLinearSystem( const RealType& time, - const RealType& tau, - const MeshType& mesh, - const IndexType& index, - const MeshEntity& entity, - const MeshFunctionType& u, - Vector& b, - MatrixRow& matrixRow ) const;*/ -}; - -template< typename MeshReal, - typename Device, - typename MeshIndex, - typename Real, - typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; - - using typename BaseType::RealType; - using typename BaseType::IndexType; - using typename BaseType::DeviceType; - using typename BaseType::CoordinatesType; - using typename BaseType::MeshFunctionType; - using typename BaseType::MeshFunctionPointer; - using typename BaseType::VelocityFieldType; - using typename BaseType::VelocityFieldPointer; - using BaseType::Dimensions; - - static String getType() - { - return String( "LaxFridrichsMomentumX< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; - } - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& rho_u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); - const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); - - - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); - const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); - const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); - - const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); - const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); - const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); - const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); - const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); - const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); - const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_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_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; - - const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; - - return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] - 4.0 * rho_u[ center ] ) - - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) - - ( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse - + ( ( rho_u[ north ] * velocity_y_north ) - - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ) -// 2D T_11_x - + ( 4.0 / 3.0 * ( velocity_x_east - 2 * velocity_x_center + velocity_x_west - ) * hxSquareInverse - - 2.0 / 3.0 * ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest - ) * hxInverse * hyInverse / 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 LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > -{ - public: - typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; - - using typename BaseType::RealType; - using typename BaseType::IndexType; - using typename BaseType::DeviceType; - using typename BaseType::CoordinatesType; - using typename BaseType::MeshFunctionType; - using typename BaseType::MeshFunctionPointer; - using typename BaseType::VelocityFieldType; - using typename BaseType::VelocityFieldPointer; - using BaseType::Dimensions; - - static String getType() - { - return String( "LaxFridrichsMomentumX< " ) + - MeshType::getType() + ", " + - TNL::getType< Real >() + ", " + - TNL::getType< Index >() + " >"; - } - - template< typename MeshFunction, typename MeshEntity > - __cuda_callable__ - Real operator()( const MeshFunction& rho_u, - const MeshEntity& entity, - const RealType& time = 0.0 ) const - { - static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); - static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); - const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); - - const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); - const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); - const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); - const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); - const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); - - const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); - const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); - const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); - const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); - const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); - const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); - const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); - const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); - const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); - const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); - const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); - const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); - const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); - const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); - const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); - const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); - const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; - const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; - const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; - const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; - - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; - - const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; - - const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; - const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; - const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; - - return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * - ( rho_u[ west ] + rho_u[ east ] + rho_u[ south ] + rho_u[ north ] + rho_u[ up ] + rho_u[ down ] - 6.0 * rho_u[ center ] ) - - 0.5 * ( ( ( rho_u[ east ] * velocity_x_east + pressure_east ) - - ( rho_u[ west ] * velocity_x_west + pressure_west ) )* hxInverse - + ( ( rho_u[ north ] * velocity_y_north ) - - ( rho_u[ south ] * velocity_y_south ) )* hyInverse - + ( ( rho_u[ up ] * velocity_z_up ) - - ( rho_u[ down ] * velocity_z_down ) )* hzInverse ) -// 3D T_11_x - + ( 4.0 / 3.0 * ( velocity_x_east - 2 * velocity_x_center + velocity_x_west - ) * hxSquareInverse - - 2.0 / 3.0 * ( velocity_y_northEast - velocity_y_southEast - velocity_y_northWest + velocity_y_southWest - ) * hxInverse * hyInverse / 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/src/Examples/flow/LaxFridrichsMomentumXEuler.h b/src/Examples/flow/LaxFridrichsMomentumXEuler.h deleted file mode 100644 index 63def12d315188b82e82402635fca863d1b9a629..0000000000000000000000000000000000000000 --- a/src/Examples/flow/LaxFridrichsMomentumXEuler.h +++ /dev/null @@ -1,276 +0,0 @@ -/*************************************************************************** - 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 -#include -#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/src/Examples/flow/LaxFridrichsMomentumYEuler.h b/src/Examples/flow/LaxFridrichsMomentumYEuler.h deleted file mode 100644 index 8ce42282dd4c74d5ed72d2abbd661235b95dc160..0000000000000000000000000000000000000000 --- a/src/Examples/flow/LaxFridrichsMomentumYEuler.h +++ /dev/null @@ -1,260 +0,0 @@ -/*************************************************************************** - 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 -#include -#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/src/Examples/flow/RiemannProblemInitialCondition.h b/src/Examples/flow/RiemannProblemInitialCondition.h deleted file mode 100644 index 481a45bba9601b3f402e765ab0f830a65bdb7010..0000000000000000000000000000000000000000 --- a/src/Examples/flow/RiemannProblemInitialCondition.h +++ /dev/null @@ -1,1413 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include -#include "CompressibleConservativeVariables.h" - -namespace TNL { -template -class RiemannProblemInitialConditionSetter -{ - -}; - -template -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 Pointers::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 -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 Pointers::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 -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 Pointers::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 Pointers::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.57945, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "1D_4") - predefinedInitialCondition( 1.666, 0.4, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.0, 5.99924, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 0.0, 5.99242, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.0, 460.894, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 0.0, 46.095, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 19.5975, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - -6.19633, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "1D_5") - predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.0, 1.4, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 0.0, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 0.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 0.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "1D_6") - predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.0, 1.4, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.0, 0.1, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 0.0, 0.1, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 1.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "1D_Noh") - predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.0, 0.000001, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 0.0, 0.000001, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 1.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - -1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "1D_peak") - predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.0, 0.12612, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 0.0, 6.5915, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.0, 782.929, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 0.0, 3.15449, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 8.90470, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 2.26542, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "2D_3") - predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.5323, 0.138, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 1.5, 0.5323, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.3, 0.029, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 1.5, 0.3, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 1.206, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 1.206, 1.206, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 0.0, 1.206, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "2D_4") - predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.5065, 1.1, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 1.1, 0.5065, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.35, 1.1, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 1.1, 0.35, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.8939, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 0.8939, 0.8939, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 0.0, 0.8939, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - - if(initial == prefix + "2D_6") - predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 2.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 1.0, 3.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 1.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 1.0, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.75, 0.5, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - -0.75, 0.5, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.75, -0.5, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - -0.75, -0.5, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "2D_12") - predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 1.0, 0.8, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 0.5313, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 1.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 0.4, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.7276, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 0.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 0.0, 0.7276, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - - if(initial == prefix + "2D_15") - predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 0.5197, 0.8, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 1.0, 0.5313, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 0.4, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 1.0, 0.4, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - -0.6259, -0.3, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 0.1, -0.3, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.1, -0.3, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 0.1, 0.4276, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - if(initial == prefix + "2D_17") - predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, - 0.0, 0.0, 2.0, 1.0625, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - 0.0, 0.0, 1.0, 0.5197, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - 0.0, 0.0, 1.0, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - 0.0, 0.0, 1.0, 0.4, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - 0.0, -0.3, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - 0.0, 0.2145, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - 0.0, -0.4, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - 0.0, 1.1259, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ); - return true; - } - - void setDiscontinuityPlacement( const PointType& v ) - { - this->discontinuityPlacement = v; - } - - const PointType& getDiscontinuityPlasement() const - { - return this->discontinuityPlacement; - } - - void setLeftDensity( const RealType& leftDensity ) - { - this->leftDensity = leftDensity; - } - - const RealType& getLeftDensity() const - { - return this->leftDensity; - } - - void setRightDensity( const RealType& rightDensity ) - { - this->rightDensity = rightDensity; - } - - const RealType& getRightDensity() const - { - return this->rightDensity; - } - - void setLeftVelocity( const PointType& leftVelocity ) - { - this->leftVelocity = leftVelocity; - } - - const PointType& getLeftVelocity() const - { - return this->leftVelocity; - } - - void setRightVelocity( const RealType& rightVelocity ) - { - this->rightVelocity = rightVelocity; - } - - const PointType& getRightVelocity() const - { - return this->rightVelocity; - } - - void setLeftPressure( const RealType& leftPressure ) - { - this->leftPressure = leftPressure; - } - - const RealType& getLeftPressure() const - { - return this->leftPressure; - } - - void setRightPressure( const RealType& rightPressure ) - { - this->rightPressure = rightPressure; - } - - const RealType& getRightPressure() const - { - return this->rightPressure; - } - - - void predefinedInitialCondition( double preGamma, double preDiscX, double preDiscY, double preDiscZ, - double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, - double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, - double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, - double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, - double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, - double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, - double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, - double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, - double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, - double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, - double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, - double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ - ) - - { - this->discontinuityPlacement = PointLoad(preDiscX, preDiscY, preDiscZ); - this->gamma = preGamma; - - this->NWUDensity = preNWUDensity; - this->NWUVelocity = PointLoad(preNWUVelocityX, preNWUVelocityY, preNWUVelocityZ); - this->NWUPressure = preNWUPressure; - this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); - this->NWUMomentum = NWUVelocity * NWUDensity; - - this->SWUDensity = preNWUDensity; - this->SWUVelocity = PointLoad(preSWUVelocityX, preSWUVelocityY, preSWUVelocityZ); - this->SWUPressure = preSWUPressure; - this->SWUEnergy = Energy( SWUDensity, SWUPressure, gamma, SWUVelocity); - this->SWUMomentum = SWUVelocity * SWUDensity; - - this->NWDDensity = preNWDDensity; - this->NWDVelocity = PointLoad(preNWDVelocityX, preNWDVelocityY, preNWDVelocityZ); - this->NWDPressure = preNWDPressure; - this->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); - this->NWDMomentum = NWDVelocity * NWDDensity; - - this->SWDDensity = preSWDDensity; - this->SWDVelocity = PointLoad(preSWDVelocityX, preSWDVelocityY, preSWDVelocityZ); - this->SWDPressure = preSWDPressure; - this->SWDEnergy = Energy( SWDDensity, SWDPressure, gamma, SWDVelocity); - this->SWDMomentum = SWDVelocity * SWDDensity; - - this->NEUDensity = preNEUDensity; - this->NEUVelocity = PointLoad(preNEUVelocityX, preNEUVelocityY, preNEUVelocityZ); - this->NEUPressure = preNEUPressure; - this->NEUEnergy = Energy( NEUDensity, NEUPressure, gamma, NEUVelocity); - this->NEUMomentum = NEUVelocity * NEUDensity; - - this->SEUDensity = preSEUDensity; - this->SEUVelocity = PointLoad(preSEUVelocityX, preSEUVelocityY, preSEUVelocityZ); - this->SEUPressure = preSEUPressure; - this->SEUEnergy = Energy( SEUDensity, SEUPressure, gamma, SEUVelocity); - this->SEUMomentum = SEUVelocity * SEUDensity; - - this->NEDDensity = preNEDDensity; - this->NEDVelocity = PointLoad(preNEDVelocityX, preNEDVelocityY, preNEDVelocityZ); - this->NEDPressure = preNEDPressure; - this->NEDEnergy = Energy( NEDDensity, NEDPressure, gamma, NEDVelocity); - this->NEDMomentum = NEDVelocity * NEDDensity; - - this->SEDDensity = preSEDDensity; - this->SEDVelocity = PointLoad(preSEDVelocityX, preSEDVelocityY, preSEDVelocityZ); - this->SEDPressure = preSEDPressure; - this->SEDEnergy = Energy( SEDDensity, SEDPressure, gamma, SEDVelocity); - this->SEDMomentum = SEDVelocity * SEDDensity; - } - - 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* variablesSetter = new RiemannProblemInitialConditionSetter; - 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 Pointers::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/src/Examples/flow/navierStokes.cpp b/src/Examples/flow/navierStokes.cpp deleted file mode 100644 index 7dffcb059fb68607cfb12a94f3b929fb0f517ce8..0000000000000000000000000000000000000000 --- a/src/Examples/flow/navierStokes.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "navierStokes.h" diff --git a/src/Examples/flow/navierStokes.cu b/src/Examples/flow/navierStokes.cu deleted file mode 100644 index 7dffcb059fb68607cfb12a94f3b929fb0f517ce8..0000000000000000000000000000000000000000 --- a/src/Examples/flow/navierStokes.cu +++ /dev/null @@ -1 +0,0 @@ -#include "navierStokes.h" diff --git a/src/Examples/flow/navierStokes.h b/src/Examples/flow/navierStokes.h deleted file mode 100644 index 5b37345bc6bc18ae1355b458a1cff5eaef64a346..0000000000000000000000000000000000000000 --- a/src/Examples/flow/navierStokes.h +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include -#include -#include -#include -#include "navierStokesProblem.h" -#include "LaxFridrichs.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; - LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); - RiemannProblemInitialCondition< Mesh >::configSetup( config ); - - /**** - * Add definition of your solver command line arguments. - */ - - } -}; - -template< typename Real, - typename Device, - typename Index, - typename MeshType, - typename ConfigTag, - typename SolverStarter, - typename Communicator > -class navierStokesSetter -{ - public: - - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - - static bool run( const Config::ParameterContainer & parameters ) - { - enum { Dimension = MeshType::getMeshDimension() }; - typedef LaxFridrichs< MeshType, Real, Index > ApproximateOperator; - typedef navierStokesRhs< MeshType, Real > RightHandSide; - typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; - - /**** - * Resolve the template arguments of your solver here. - * The following code is for the Dirichlet and the Neumann boundary conditions. - * Both can be constant or defined as descrete values of Vector. - */ - - 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, Communicator > 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, Communicator > 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/src/Examples/flow/navierStokesBuildConfigTag.h b/src/Examples/flow/navierStokesBuildConfigTag.h deleted file mode 100644 index 9267843d5269e589d4316525a6afda8dd59f61dc..0000000000000000000000000000000000000000 --- a/src/Examples/flow/navierStokesBuildConfigTag.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef navierStokesBUILDCONFIGTAG_H_ -#define navierStokesBUILDCONFIGTAG_H_ - -#include - -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 }; }; - -/**** - * 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 Meshes { -namespace BuildConfigTags { - -template< int Dimensions > struct GridDimensionTag< navierStokesBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 1 ) }; }; - -/**** - * Turn off support for float and long double. - */ -template<> struct GridRealTag< navierStokesBuildConfigTag, float > { enum { enabled = false }; }; -template<> struct GridRealTag< navierStokesBuildConfigTag, long double > { enum { enabled = false }; }; - -/**** - * Turn off support for short int and long int indexing. - */ -template<> struct GridIndexTag< navierStokesBuildConfigTag, short int >{ enum { enabled = false }; }; -template<> struct GridIndexTag< navierStokesBuildConfigTag, long int >{ enum { enabled = false }; }; - -} // namespace BuildConfigTags -} // namespace Meshes - -} // namespace TNL - -#endif /* navierStokesBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/flow/navierStokesProblem_impl.h b/src/Examples/flow/navierStokesProblem_impl.h deleted file mode 100644 index 4b0c7977441e87cab05fccab2c3984705670cfd4..0000000000000000000000000000000000000000 --- a/src/Examples/flow/navierStokesProblem_impl.h +++ /dev/null @@ -1,464 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include -#include - -#include "RiemannProblemInitialCondition.h" -#include "CompressibleConservativeVariables.h" -#include "PhysicalVariablesGetter.h" -#include "navierStokesProblem.h" - -#include "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "LaxFridrichsMomentumZ.h" -/* -#include "DensityBoundaryConditionCavity.h" -#include "MomentumXBoundaryConditionCavity.h" -#include "MomentumYBoundaryConditionCavity.h" -#include "MomentumZBoundaryConditionCavity.h" -#include "EnergyBoundaryConditionCavity.h" - -#include "DensityBoundaryConditionBoiler.h" -#include "MomentumXBoundaryConditionBoiler.h" -#include "MomentumYBoundaryConditionBoiler.h" -#include "MomentumZBoundaryConditionBoiler.h" -#include "EnergyBoundaryConditionBoiler.h" -*/ -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -String -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getTypeStatic() -{ - return String( "navierStokesProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -String -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getPrologHeader() const -{ - return String( "Inviscid flow solver" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || - ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - this->gamma = parameters.getParameter< double >( "gamma" ); - velocity->setMesh( this->getMesh() ); - pressure->setMesh( this->getMesh() ); - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -typename navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >::IndexType -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getDofs() const -{ - /**** - * Return number of DOFs (degrees of freedom) i.e. number - * of unknowns to be resolved by the main solver. - */ - return this->conservativeVariables->getDofs( this->getMesh() ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -bindDofs( DofVectorPointer& dofVector ) -{ - this->conservativeVariables->bind( this->getMesh(), dofVector ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - DofVectorPointer& dofs ) -{ - CompressibleConservativeVariables< MeshType > conservativeVariables; - conservativeVariables.bind( this->getMesh(), 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, - typename Communicator > - template< typename Matrix > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setupLinearSystem( 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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -makeSnapshot( const RealType& time, - const IndexType& step, - DofVectorPointer& dofs ) -{ - std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; - - this->bindDofs( 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-" ); - this->velocity->save( fileName.getFileName() ); - -// 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, - typename Communicator > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getExplicitUpdate( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - DofVectorPointer& _fu ) -{ - typedef typename MeshType::Cell Cell; - const MeshPointer& mesh = this->getMesh(); - - /**** - * Bind DOFs - */ - this->conservativeVariables->bind( mesh, _u ); - this->conservativeVariablesRHS->bind( mesh, _fu ); - this->velocity->setMesh( mesh ); - this->pressure->setMesh( mesh ); - - /**** - * Resolve the physical variables - */ - PhysicalVariablesGetter< typename MeshPointer::ObjectType > physicalVariables; - physicalVariables.getVelocity( this->conservativeVariables, this->velocity ); - physicalVariables.getPressure( this->conservativeVariables, this->gamma, this->pressure ); - - /**** - * Set-up operators - */ - typedef typename InviscidOperators::ContinuityOperatorType ContinuityOperatorType; - typedef typename InviscidOperators::MomentumXOperatorType MomentumXOperatorType; - typedef typename InviscidOperators::MomentumYOperatorType MomentumYOperatorType; - typedef typename InviscidOperators::MomentumZOperatorType MomentumZOperatorType; - typedef typename InviscidOperators::EnergyOperatorType EnergyOperatorType; - - this->inviscidOperatorsPointer->setTau( tau ); - this->inviscidOperatorsPointer->setVelocity( this->velocity ); - this->inviscidOperatorsPointer->setPressure( this->pressure ); - - /**** - * 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( 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, CommunicatorType >( - time, tau, mesh, - this->conservativeVariables->getEnergy(), // uRhoVelocityX, - this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); - - /* - this->conservativeVariablesRHS->getDensity()->write( "density", "gnuplot" ); - this->conservativeVariablesRHS->getEnergy()->write( "energy", "gnuplot" ); - this->conservativeVariablesRHS->getMomentum()->write( "momentum", "gnuplot", 0.05 ); - getchar(); - */ - -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > - template< typename Matrix > -void -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b ) -{ -/* 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, - typename Communicator > -bool -navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -postIterate( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs ) -{ - /* - 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/src/Examples/flow/run-navier-stokes b/src/Examples/flow/run-navier-stokes deleted file mode 100644 index 9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c..0000000000000000000000000000000000000000 --- a/src/Examples/flow/run-navier-stokes +++ /dev/null @@ -1,25 +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 -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/src/Examples/flow-vl/BoundaryConditionsBoiler.h b/src/Examples/flows/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h similarity index 92% rename from src/Examples/flow-vl/BoundaryConditionsBoiler.h rename to src/Examples/flows/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h index f61f988da66f3f7476827c8f8853f4d6dbf67217..953199081f0b912fd0c4323c6d5ab26037f7abf5 100644 --- a/src/Examples/flow-vl/BoundaryConditionsBoiler.h +++ b/src/Examples/flows/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h @@ -99,6 +99,22 @@ class BoundaryConditionsBoiler this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); } + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() { return this->densityBoundaryConditionsPointer; diff --git a/src/Examples/flow/CompressibleConservativeVariables.h b/src/Examples/flows/BoundaryConditions/Boiler/CompressibleConservativeVariables.h similarity index 94% rename from src/Examples/flow/CompressibleConservativeVariables.h rename to src/Examples/flows/BoundaryConditions/Boiler/CompressibleConservativeVariables.h index 01e820686e98781a3267c4526e8e7c6449218415..b66f4d5c52e67a440d9dfca7350266c71977f3f7 100644 --- a/src/Examples/flow/CompressibleConservativeVariables.h +++ b/src/Examples/flows/BoundaryConditions/Boiler/CompressibleConservativeVariables.h @@ -71,11 +71,13 @@ class CompressibleConservativeVariables this->energy->getDofs( meshPointer ); } + __cuda_callable__ MeshFunctionPointer& getDensity() { return this->density; } + __cuda_callable__ const MeshFunctionPointer& getDensity() const { return this->density; @@ -86,11 +88,13 @@ class CompressibleConservativeVariables this->density = density; } + __cuda_callable__ MomentumFieldPointer& getMomentum() { return this->momentum; } + __cuda_callable__ const MomentumFieldPointer& getMomentum() const { return this->momentum; @@ -101,11 +105,14 @@ class CompressibleConservativeVariables this->momentum = momentum; } - /*MeshFunctionPointer& getPressure() + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() { return this->pressure; } + __cuda_callable__ const MeshFunctionPointer& getPressure() const { return this->pressure; @@ -116,11 +123,13 @@ class CompressibleConservativeVariables this->pressure = pressure; }*/ + __cuda_callable__ MeshFunctionPointer& getEnergy() { return this->energy; } + __cuda_callable__ const MeshFunctionPointer& getEnergy() const { return this->energy; @@ -144,4 +153,4 @@ class CompressibleConservativeVariables }; -} // namespace TN +} // namespace TNL diff --git a/src/Examples/flow-sw/DensityBoundaryConditionBoiler.h b/src/Examples/flows/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-sw/DensityBoundaryConditionBoiler.h rename to src/Examples/flows/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h diff --git a/src/Examples/flow-vl/EnergyBoundaryConditionBoiler.h b/src/Examples/flows/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h similarity index 99% rename from src/Examples/flow-vl/EnergyBoundaryConditionBoiler.h rename to src/Examples/flows/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h index a99fdf0157bfcbca614374e8472ab9fe8a3b4f58..412640b5472f0e85026e26954503a6412bba0c39 100644 --- a/src/Examples/flow-vl/EnergyBoundaryConditionBoiler.h +++ b/src/Examples/flows/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h @@ -12,7 +12,6 @@ #pragma once #include -#include "CompressibleConservativeVariables.h" namespace TNL { namespace Operators { diff --git a/src/Examples/flow-sw/MomentumXBoundaryConditionBoiler.h b/src/Examples/flows/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-sw/MomentumXBoundaryConditionBoiler.h rename to src/Examples/flows/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h diff --git a/src/Examples/flow-sw/MomentumYBoundaryConditionBoiler.h b/src/Examples/flows/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-sw/MomentumYBoundaryConditionBoiler.h rename to src/Examples/flows/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h diff --git a/src/Examples/flow-sw/MomentumZBoundaryConditionBoiler.h b/src/Examples/flows/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-sw/MomentumZBoundaryConditionBoiler.h rename to src/Examples/flows/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h diff --git a/src/Examples/flows/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h b/src/Examples/flows/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..06228f789664fbc508cc294df6bae489941d9c2b --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h @@ -0,0 +1,194 @@ +#include + +#include "DensityBoundaryConditionBoilerModel.h" +#include "MomentumXBoundaryConditionBoilerModel.h" +#include "MomentumYBoundaryConditionBoilerModel.h" +#include "MomentumZBoundaryConditionBoilerModel.h" +#include "EnergyBoundaryConditionBoilerModel.h" + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class BoundaryConditionsBoilerModel +{ + 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::DensityBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::MomentumXBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::MomentumYBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::MomentumZBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::EnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "vertical-angle", "Vertical angle of throttle in degrees", 0 ); + config.addEntry< double >( prefix + "horizontal-angle", "Horizontal angle of throttle in degrees", 45 ); + } + + 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); + setZAngle(parameters.getParameter< double >( prefix + "vertical-angle" ) * M_PI / 180.0 ); + setXYAngle(parameters.getParameter< double >( prefix + "horizontal-angle" ) * M_PI / 180.0 ); + 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 setZAngle(const RealType zAngle) + { + this->densityBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumXBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumYBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumZBoundaryConditionsPointer->setZAngle(zAngle); + this->energyBoundaryConditionsPointer->setZAngle(zAngle); + } + + void setXYAngle(const RealType xYAngle) + { + this->densityBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumXBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumYBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumZBoundaryConditionsPointer->setXYAngle(xYAngle); + this->energyBoundaryConditionsPointer->setXYAngle(xYAngle); + } + + 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) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType horizontalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + horizontalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + horizontalThrottleSpeed = 0; + else + horizontalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->energyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType verticalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + verticalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + verticalThrottleSpeed = 0; + else + verticalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->energyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + } + + 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/src/Examples/inviscid-flow-sw/CompressibleConservativeVariables.h b/src/Examples/flows/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h similarity index 94% rename from src/Examples/inviscid-flow-sw/CompressibleConservativeVariables.h rename to src/Examples/flows/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h index 01e820686e98781a3267c4526e8e7c6449218415..b66f4d5c52e67a440d9dfca7350266c71977f3f7 100644 --- a/src/Examples/inviscid-flow-sw/CompressibleConservativeVariables.h +++ b/src/Examples/flows/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h @@ -71,11 +71,13 @@ class CompressibleConservativeVariables this->energy->getDofs( meshPointer ); } + __cuda_callable__ MeshFunctionPointer& getDensity() { return this->density; } + __cuda_callable__ const MeshFunctionPointer& getDensity() const { return this->density; @@ -86,11 +88,13 @@ class CompressibleConservativeVariables this->density = density; } + __cuda_callable__ MomentumFieldPointer& getMomentum() { return this->momentum; } + __cuda_callable__ const MomentumFieldPointer& getMomentum() const { return this->momentum; @@ -101,11 +105,14 @@ class CompressibleConservativeVariables this->momentum = momentum; } - /*MeshFunctionPointer& getPressure() + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() { return this->pressure; } + __cuda_callable__ const MeshFunctionPointer& getPressure() const { return this->pressure; @@ -116,11 +123,13 @@ class CompressibleConservativeVariables this->pressure = pressure; }*/ + __cuda_callable__ MeshFunctionPointer& getEnergy() { return this->energy; } + __cuda_callable__ const MeshFunctionPointer& getEnergy() const { return this->energy; @@ -144,4 +153,4 @@ class CompressibleConservativeVariables }; -} // namespace TN +} // namespace TNL diff --git a/src/Examples/flows/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h b/src/Examples/flows/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..a58f32f7c577590801504d675dec55243e2f0b57 --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h @@ -0,0 +1,580 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DensityBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class DensityBoundaryConditionsBoilerModelBase +{ + 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 DensityBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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.835 * ( entity.getMesh().getDimensions().y() - 1 )) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ 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, -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 setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 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 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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DensityBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flows/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h b/src/Examples/flows/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..d0475576b5fa910528eaa3c7a80ffd8047bddcc9 --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,962 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class EnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class EnergyBoundaryConditionsBoilerModelBase +{ + 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 EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const EnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h b/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..893815913ba45510c520de2033d7be690faea8bb --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h @@ -0,0 +1,940 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumXBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumXBoundaryConditionsBoilerModelBase +{ + 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 MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumXBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h b/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..e8aa33e885efcc06f134a94f7e6df8cb974fb417 --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h @@ -0,0 +1,941 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumYBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumYBoundaryConditionsBoilerModelBase +{ + 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 MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( - 1.0 ) + * std::sin( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) +// down throttle + { + if( + ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumYBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h b/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..ee40b1b74066d4c5ee0491345538577525a7e4f5 --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h @@ -0,0 +1,838 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumZBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumZBoundaryConditionsBoilerModelBase +{ + 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 MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( + ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.408 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumZBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flow/BoundaryConditionsCavity.h b/src/Examples/flows/BoundaryConditions/Cavity/BoundaryConditionsCavity.h similarity index 92% rename from src/Examples/flow/BoundaryConditionsCavity.h rename to src/Examples/flows/BoundaryConditions/Cavity/BoundaryConditionsCavity.h index bbae2d3e93c65383db11a53a3b16d734fc3131e2..9c3c0b0996d682c57b99c7ce05164e1e8cdc58a8 100644 --- a/src/Examples/flow/BoundaryConditionsCavity.h +++ b/src/Examples/flows/BoundaryConditions/Cavity/BoundaryConditionsCavity.h @@ -99,6 +99,22 @@ class BoundaryConditionsCavity this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); } + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() { return this->densityBoundaryConditionsPointer; diff --git a/src/Examples/flow-sw/CompressibleConservativeVariables.h b/src/Examples/flows/BoundaryConditions/Cavity/CompressibleConservativeVariables.h similarity index 94% rename from src/Examples/flow-sw/CompressibleConservativeVariables.h rename to src/Examples/flows/BoundaryConditions/Cavity/CompressibleConservativeVariables.h index 01e820686e98781a3267c4526e8e7c6449218415..b66f4d5c52e67a440d9dfca7350266c71977f3f7 100644 --- a/src/Examples/flow-sw/CompressibleConservativeVariables.h +++ b/src/Examples/flows/BoundaryConditions/Cavity/CompressibleConservativeVariables.h @@ -71,11 +71,13 @@ class CompressibleConservativeVariables this->energy->getDofs( meshPointer ); } + __cuda_callable__ MeshFunctionPointer& getDensity() { return this->density; } + __cuda_callable__ const MeshFunctionPointer& getDensity() const { return this->density; @@ -86,11 +88,13 @@ class CompressibleConservativeVariables this->density = density; } + __cuda_callable__ MomentumFieldPointer& getMomentum() { return this->momentum; } + __cuda_callable__ const MomentumFieldPointer& getMomentum() const { return this->momentum; @@ -101,11 +105,14 @@ class CompressibleConservativeVariables this->momentum = momentum; } - /*MeshFunctionPointer& getPressure() + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() { return this->pressure; } + __cuda_callable__ const MeshFunctionPointer& getPressure() const { return this->pressure; @@ -116,11 +123,13 @@ class CompressibleConservativeVariables this->pressure = pressure; }*/ + __cuda_callable__ MeshFunctionPointer& getEnergy() { return this->energy; } + __cuda_callable__ const MeshFunctionPointer& getEnergy() const { return this->energy; @@ -144,4 +153,4 @@ class CompressibleConservativeVariables }; -} // namespace TN +} // namespace TNL diff --git a/src/Examples/flow/DensityBoundaryConditionCavity.h b/src/Examples/flows/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow/DensityBoundaryConditionCavity.h rename to src/Examples/flows/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h diff --git a/src/Examples/flow/EnergyBoundaryConditionCavity.h b/src/Examples/flows/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h similarity index 99% rename from src/Examples/flow/EnergyBoundaryConditionCavity.h rename to src/Examples/flows/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h index 60e55f4240ed1fcb8bc63e494c01faf61f899568..ca5d85442d02edeb7ddd39749c6441c13e3eb6ed 100644 --- a/src/Examples/flow/EnergyBoundaryConditionCavity.h +++ b/src/Examples/flows/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h @@ -12,7 +12,6 @@ #pragma once #include -#include "CompressibleConservativeVariables.h" namespace TNL { namespace Operators { @@ -521,18 +520,18 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshInd + 0.5 * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] * ( - ( this->cavitySpeed + ( this->cavitySpeed/* * ( entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) ) - / ( entity.getMesh().getDimensions().x() / 2 ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ ) * - ( this->cavitySpeed + ( this->cavitySpeed/* * ( entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) ) - / ( entity.getMesh().getDimensions().x() / 2 ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ ) + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] diff --git a/src/Examples/flow-sw/MomentumXBoundaryConditionCavity.h b/src/Examples/flows/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow-sw/MomentumXBoundaryConditionCavity.h rename to src/Examples/flows/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h diff --git a/src/Examples/flow-sw/MomentumYBoundaryConditionCavity.h b/src/Examples/flows/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow-sw/MomentumYBoundaryConditionCavity.h rename to src/Examples/flows/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h diff --git a/src/Examples/flow-sw/MomentumZBoundaryConditionCavity.h b/src/Examples/flows/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow-sw/MomentumZBoundaryConditionCavity.h rename to src/Examples/flows/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h diff --git a/src/Examples/flows/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h b/src/Examples/flows/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h new file mode 100644 index 0000000000000000000000000000000000000000..930183476e5085ac80c115785f4c0eff0aa8e7d8 --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function = Functions::Analytic::Constant< Mesh::getMeshDimension(), typename Mesh::RealType >, + int MeshEntitiesDimension = Mesh::getMeshDimension(), + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsDirichlet +{ + 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::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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/src/Examples/flows/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h b/src/Examples/flows/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h new file mode 100644 index 0000000000000000000000000000000000000000..ec99b86e7872ea867bdc49317e2987c04def1470 --- /dev/null +++ b/src/Examples/flows/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h @@ -0,0 +1,124 @@ +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsNeumann +{ + 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::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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/src/Examples/flows/CMakeLists.txt b/src/Examples/flows/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd8e6f8708f7029abaf81aea4050908eb47bb71b --- /dev/null +++ b/src/Examples/flows/CMakeLists.txt @@ -0,0 +1,101 @@ +#navier-stokes-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesLaxFriedrichs.cpp + navierStokesLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cu) + target_link_libraries (tnl-navier-stokes-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesStegerWarming.cpp + navierStokesStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cu) + target_link_libraries (tnl-navier-stokes-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesVanLeer.cpp + navierStokesVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cu) + target_link_libraries (tnl-navier-stokes-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesAUSMPlus.cpp + navierStokesAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cu) + target_link_libraries (tnl-navier-stokes-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/flows/CMakeLists_separate.txt b/src/Examples/flows/CMakeLists_separate.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd8e6f8708f7029abaf81aea4050908eb47bb71b --- /dev/null +++ b/src/Examples/flows/CMakeLists_separate.txt @@ -0,0 +1,101 @@ +#navier-stokes-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesLaxFriedrichs.cpp + navierStokesLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cu) + target_link_libraries (tnl-navier-stokes-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesStegerWarming.cpp + navierStokesStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cu) + target_link_libraries (tnl-navier-stokes-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesVanLeer.cpp + navierStokesVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cu) + target_link_libraries (tnl-navier-stokes-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesAUSMPlus.cpp + navierStokesAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cu) + target_link_libraries (tnl-navier-stokes-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/flow/CMakeLists.txt b/src/Examples/flows/CMakeLists_together.txt similarity index 84% rename from src/Examples/flow/CMakeLists.txt rename to src/Examples/flows/CMakeLists_together.txt index 6b156036bf3e283f4aa1d0c3bb8b6bc46978a86f..f26fc6d34635dad513d36fd9c4ea21d3c1e95489 100644 --- a/src/Examples/flow/CMakeLists.txt +++ b/src/Examples/flows/CMakeLists_together.txt @@ -1,3 +1,5 @@ +#navier-stokes + set( tnl_flow_HEADERS CompressibleConservativeVariables.h ) @@ -7,6 +9,7 @@ set( tnl_flow_SOURCES IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cu) + target_link_libraries (tnl-navier-stokes ${CUSPARSE_LIBRARY} ) ELSE( BUILD_CUDA ) ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cpp) ENDIF( BUILD_CUDA ) @@ -17,5 +20,7 @@ INSTALL( TARGETS tnl-navier-stokes PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) INSTALL( FILES run-navier-stokes - ${tnl_inviscid_flow_SOURCES} + ${tnl_flow_SOURCES} DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/flow-vl/CompressibleConservativeVariables.h b/src/Examples/flows/CompressibleConservativeVariables.h similarity index 94% rename from src/Examples/flow-vl/CompressibleConservativeVariables.h rename to src/Examples/flows/CompressibleConservativeVariables.h index 01e820686e98781a3267c4526e8e7c6449218415..b66f4d5c52e67a440d9dfca7350266c71977f3f7 100644 --- a/src/Examples/flow-vl/CompressibleConservativeVariables.h +++ b/src/Examples/flows/CompressibleConservativeVariables.h @@ -71,11 +71,13 @@ class CompressibleConservativeVariables this->energy->getDofs( meshPointer ); } + __cuda_callable__ MeshFunctionPointer& getDensity() { return this->density; } + __cuda_callable__ const MeshFunctionPointer& getDensity() const { return this->density; @@ -86,11 +88,13 @@ class CompressibleConservativeVariables this->density = density; } + __cuda_callable__ MomentumFieldPointer& getMomentum() { return this->momentum; } + __cuda_callable__ const MomentumFieldPointer& getMomentum() const { return this->momentum; @@ -101,11 +105,14 @@ class CompressibleConservativeVariables this->momentum = momentum; } - /*MeshFunctionPointer& getPressure() + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() { return this->pressure; } + __cuda_callable__ const MeshFunctionPointer& getPressure() const { return this->pressure; @@ -116,11 +123,13 @@ class CompressibleConservativeVariables this->pressure = pressure; }*/ + __cuda_callable__ MeshFunctionPointer& getEnergy() { return this->energy; } + __cuda_callable__ const MeshFunctionPointer& getEnergy() const { return this->energy; @@ -144,4 +153,4 @@ class CompressibleConservativeVariables }; -} // namespace TN +} // namespace TNL diff --git a/src/Examples/flow-vl/Upwind.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h similarity index 77% rename from src/Examples/flow-vl/Upwind.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h index 5aee91b62520fa9afd1c3427d330b6dab0e4ea98..9ff57640731d8485becb9784a6d39421c367b08c 100644 --- a/src/Examples/flow-vl/Upwind.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h @@ -1,5 +1,5 @@ /*************************************************************************** - Upwind.h - description + AUSMPlus.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -15,18 +15,21 @@ #include #include -#include "UpwindContinuity.h" -#include "UpwindEnergy.h" -#include "UpwindMomentumX.h" -#include "UpwindMomentumY.h" -#include "UpwindMomentumZ.h" +#include "AUSMPlusContinuity.h" +#include "AUSMPlusEnergy.h" +#include "AUSMPlusMomentumX.h" +#include "AUSMPlusMomentumY.h" +#include "AUSMPlusMomentumZ.h" + +#include "Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide = NullOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class Upwind +class AUSMPlus { public: typedef Mesh MeshType; @@ -36,12 +39,18 @@ class Upwind typedef Functions::MeshFunction< Mesh > MeshFunctionType; static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; - 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 AUSMPlusContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef AUSMPlusMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef AUSMPlusMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef AUSMPlusMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef AUSMPlusEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; @@ -59,13 +68,14 @@ class Upwind config.addEntry< double >( prefix + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); } - Upwind() + AUSMPlus() :dynamicalViscosity( 1.0 ) {} bool setup( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters, const String& prefix = "" ) { + std::cout << "AUSMPlus" << std::endl; this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); diff --git a/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusContinuity.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..12d85ac85a9d621edff0ad57c293ef81c06e3f2d --- /dev/null +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusContinuity.h @@ -0,0 +1,401 @@ +/*************************************************************************** + AUSMPlusContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusContinuity< " ) + + 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 DensityFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity + MachBorderMinus * RightDensity ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ] , u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->DensityFlux( u[ west ] , u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ] , u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->DensityFlux( u[ down ] , u[ center ], velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->DensityFlux( u[ center ], u[ up ] , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusEnergy.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..f5e04f9daee0e35f64b7b1db0b8796963a8eced3 --- /dev/null +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusEnergy.h @@ -0,0 +1,511 @@ +/*************************************************************************** + AUSMPlusEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + AUSMPlusEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "AUSMPlusEnergy< " ) + + 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; + this->rightHandSide.setVelocity(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; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + RealType EnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftEnergy, + const RealType& RightEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * ( LeftEnergy + LeftPressure) + MachBorderMinus * ( RightEnergy + RightPressure ) ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->EnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ], u[ center ] ) + - this->EnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumBase.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..6c6c341197e3497b7109948977678164cf22c3d2 --- /dev/null +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumBase.h @@ -0,0 +1,195 @@ +/*************************************************************************** + AUSMPlusMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(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; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + RealType MainMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + RealType PressureSplitingPlus = 0; + RealType PressureSplitingMinus = 0; + RealType PressureBorder = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + PressureSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + PressureSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) * (2.0 - LeftMachNumber ) + + 3.0 / 16.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + PressureSplitingPlus = 1.0; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + PressureSplitingMinus = 1.0; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + PressureSplitingMinus = 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) * (2.0 + RightMachNumber ) + - 3.0 / 16.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + PressureSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + PressureBorder = PressureSplitingPlus * LeftPressure + PressureSplitingMinus * RightPressure; + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftVelocity + MachBorderMinus * RightDensity * RightVelocity ) + PressureBorder; + } + + RealType OtherMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftOtherVelocity, + const RealType& RightOtherVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftOtherVelocity + MachBorderMinus * RightDensity * RightOtherVelocity ); + } + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumX.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..24f4c5e780ecb2d640b65ec8bd139f3207efd9c9 --- /dev/null +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumX.h @@ -0,0 +1,398 @@ +/*************************************************************************** + AUSMPlusMomentumX.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_x_down , velocity_x_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_x_center, velocity_x_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumY.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..d1a8d43041623a06152ac07c2fb114d2095e73ab --- /dev/null +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumY.h @@ -0,0 +1,371 @@ +/*************************************************************************** + AUSMPlusMomentumY.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_y_down , velocity_y_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_y_center, velocity_y_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumZ.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..8915da35c870f05f85e91fa38afda392ad29b23b --- /dev/null +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumZ.h @@ -0,0 +1,316 @@ +/*************************************************************************** + AUSMPlusMomentumZ.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_z_west , velocity_z_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_z_center, velocity_z_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_z_south , velocity_z_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_z_center, velocity_z_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->MainMomentumFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->MainMomentumFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/flow/LaxFridrichs.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h similarity index 78% rename from src/Examples/flow/LaxFridrichs.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h index 1949bfe974fb3a80c7369abfc208ad89edeb7d47..34484a086e38866b692951061be16a3bff57acec 100644 --- a/src/Examples/flow/LaxFridrichs.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h @@ -21,9 +21,12 @@ #include "LaxFridrichsMomentumY.h" #include "LaxFridrichsMomentumZ.h" +#include "Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" + namespace TNL { template< typename Mesh, + typename OperatorRightHandSide = NullOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichs @@ -36,12 +39,18 @@ class LaxFridrichs typedef Functions::MeshFunction< Mesh > MeshFunctionType; static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; - 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 LaxFridrichsContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef LaxFridrichsMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef LaxFridrichsMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef LaxFridrichsMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef LaxFridrichsEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; @@ -67,6 +76,7 @@ class LaxFridrichs const Config::ParameterContainer& parameters, const String& prefix = "" ) { + std::cout << "Lax-Friedrichs" << std::endl; this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); @@ -90,6 +100,10 @@ class LaxFridrichs this->momentumZOperatorPointer->setTau( tau ); this->energyOperatorPointer->setTau( tau ); } + + void setGamma( const RealType& gamma ) + { + } void setPressure( const MeshFunctionPointer& pressure ) { @@ -98,6 +112,10 @@ class LaxFridrichs this->momentumZOperatorPointer->setPressure( pressure ); this->energyOperatorPointer->setPressure( pressure ); } + + void setDensity( const MeshFunctionPointer& density ) + { + } void setVelocity( const VectorFieldPointer& velocity ) { diff --git a/src/Examples/flow/LaxFridrichsContinuity.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsContinuity.h similarity index 76% rename from src/Examples/flow/LaxFridrichsContinuity.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsContinuity.h index bf3cc45ece7877291a53cb460dd874fa77bbd250..e82c9d4242d426adb2f21b238b05f0773e3b1c3b 100644 --- a/src/Examples/flow/LaxFridrichsContinuity.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsContinuity.h @@ -20,6 +20,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuityBase @@ -35,6 +36,7 @@ class LaxFridrichsContinuityBase static const int Dimensions = MeshType::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsContinuityBase() : artificialViscosity( 1.0 ){}; @@ -68,12 +70,15 @@ class LaxFridrichsContinuityBase RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; RealType artificialViscosity; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuity @@ -85,14 +90,15 @@ class LaxFridrichsContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -114,15 +120,20 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re 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 ]; + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + // return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) // - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) - - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse; + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -146,14 +157,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -177,19 +189,23 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re //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 ]; + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -213,14 +229,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -244,27 +261,30 @@ class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Re //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 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 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 ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ up ] * velocity_z_up - u[ down ] * velocity_z_down ) * hzInverse ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/flow/LaxFridrichsEnergyEuler.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsEnergy.h similarity index 71% rename from src/Examples/flow/LaxFridrichsEnergyEuler.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsEnergy.h index 30180639d18c4d36b688eb60d597a571e5647115..0732aaf5cbd296dce917fca47616a5f29146a053 100644 --- a/src/Examples/flow/LaxFridrichsEnergyEuler.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsEnergy.h @@ -16,6 +16,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergyBase @@ -32,6 +33,7 @@ class LaxFridrichsEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsEnergyBase() : artificialViscosity( 1.0 ){}; @@ -52,6 +54,7 @@ class LaxFridrichsEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -63,12 +66,19 @@ class LaxFridrichsEnergyBase { this->artificialViscosity = artificialViscosity; } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } protected: RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; @@ -76,6 +86,7 @@ class LaxFridrichsEnergyBase }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergy @@ -85,15 +96,16 @@ class LaxFridrichsEnergy template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -115,18 +127,23 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, 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& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; - + - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -150,14 +167,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -180,27 +198,33 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -224,14 +248,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -253,16 +278,17 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; @@ -270,13 +296,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ] ) @@ -285,7 +313,9 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, + ( ( ( 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 ); + -( ( e[ down ] + pressure_down ) * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow/LaxFridrichsMomentumBase.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumBase.h similarity index 87% rename from src/Examples/flow/LaxFridrichsMomentumBase.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumBase.h index 79005b55e04d27c88dfadbfd28d5171483f601a4..5fe1b6598c79d4dd3a874171b1f9898f7b0cefd6 100644 --- a/src/Examples/flow/LaxFridrichsMomentumBase.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumBase.h @@ -14,6 +14,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumBase @@ -30,6 +31,7 @@ class LaxFridrichsMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsMomentumBase() : artificialViscosity( 1.0 ){}; @@ -42,6 +44,7 @@ class LaxFridrichsMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -56,7 +59,7 @@ class LaxFridrichsMomentumBase void setDynamicalViscosity( const RealType& dynamicalViscosity ) { - this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); } protected: @@ -64,10 +67,12 @@ class LaxFridrichsMomentumBase RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; - RealType artificialViscosity, dynamicalViscosity; + RealType artificialViscosity; }; } //namespace TNL diff --git a/src/Examples/flow-vl/LaxFridrichsMomentumX.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumX.h similarity index 70% rename from src/Examples/flow-vl/LaxFridrichsMomentumX.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumX.h index 63def12d315188b82e82402635fca863d1b9a629..57258d1a534721a5887ad8affb0e60acdf66943d 100644 --- a/src/Examples/flow-vl/LaxFridrichsMomentumX.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumX.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumX @@ -27,15 +28,16 @@ class LaxFridrichsMomentumX template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -67,17 +69,22 @@ 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 IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; + -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -101,14 +108,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -139,26 +147,34 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -182,14 +198,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -219,30 +236,30 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -250,7 +267,9 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_u[ down ] * velocity_z_down ) )* hzInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-sw/LaxFridrichsMomentumY.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumY.h similarity index 69% rename from src/Examples/flow-sw/LaxFridrichsMomentumY.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumY.h index 8ce42282dd4c74d5ed72d2abbd661235b95dc160..4cca02779d04d1395051035156d30b8a998ffa64 100644 --- a/src/Examples/flow-sw/LaxFridrichsMomentumY.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumY.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumY @@ -27,15 +28,16 @@ class LaxFridrichsMomentumY template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -128,26 +131,32 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > @@ -171,14 +180,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -207,34 +217,44 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 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 * + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ down ] * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-sw/LaxFridrichsMomentumZ.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumZ.h similarity index 78% rename from src/Examples/flow-sw/LaxFridrichsMomentumZ.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumZ.h index a67e862ceffd78d4fd770d7b1a07e9f05af349d8..1f394bfef12c16125be4a674d08f2defbc455f12 100644 --- a/src/Examples/flow-sw/LaxFridrichsMomentumZ.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumZ.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumZ @@ -27,15 +28,16 @@ class LaxFridrichsMomentumZ template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -151,14 +154,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -188,25 +192,30 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -214,7 +223,9 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_w[ down ] * velocity_z_down + pressure_down ) )* hzInverse ) + + + this->rightHandSide(rho_w, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-vl/Upwind.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h similarity index 67% rename from src/Examples/inviscid-flow-vl/Upwind.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h index 529e0aadf7e68c86c97393e122927142014c8c45..3f1c70d3cc8ae2a19d8520799fc4be94286dedf0 100644 --- a/src/Examples/inviscid-flow-vl/Upwind.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h @@ -1,5 +1,5 @@ /*************************************************************************** - Upwind.h - description + StegerWarming.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -15,18 +15,21 @@ #include #include -#include "UpwindContinuity.h" -#include "UpwindEnergy.h" -#include "UpwindMomentumX.h" -#include "UpwindMomentumY.h" -#include "UpwindMomentumZ.h" +#include "StegerWarmingContinuity.h" +#include "StegerWarmingEnergy.h" +#include "StegerWarmingMomentumX.h" +#include "StegerWarmingMomentumY.h" +#include "StegerWarmingMomentumZ.h" + +#include "Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide = NullOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class Upwind +class StegerWarming { public: typedef Mesh MeshType; @@ -36,12 +39,18 @@ class Upwind typedef Functions::MeshFunction< Mesh > MeshFunctionType; static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; - 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 StegerWarmingContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef StegerWarmingMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef StegerWarmingMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef StegerWarmingMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef StegerWarmingEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; @@ -56,15 +65,23 @@ class Upwind 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() - : artificialViscosity( 1.0 ) {} + StegerWarming() + :dynamicalViscosity( 1.0 ) {} bool setup( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters, const String& prefix = "" ) { + std::cout << "Steger-Warming"<< std::endl; + 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; } @@ -145,7 +162,7 @@ class Upwind MomentumZOperatorPointer momentumZOperatorPointer; EnergyOperatorPointer energyOperatorPointer; - RealType artificialViscosity; + RealType dynamicalViscosity; }; } //namespace TNL diff --git a/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingContinuity.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..a27d3e1399f2633c0e0f6b01a29ec516c8763df1 --- /dev/null +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingContinuity.h @@ -0,0 +1,396 @@ +/*************************************************************************** + StegerWarmingContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingContinuity< " ) + + 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/inviscid-flow-sw/UpwindEnergy.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingEnergy.h similarity index 74% rename from src/Examples/inviscid-flow-sw/UpwindEnergy.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingEnergy.h index 39f6090064075b0dd688e6105ffac94c14421cde..2f8f7696afd9bce92d0c19b27710f13cf2c8fcd0 100644 --- a/src/Examples/inviscid-flow-sw/UpwindEnergy.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingEnergy.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindEnergy.h - description + StegerWarmingEnergy.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -16,9 +16,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergyBase +class StegerWarmingEnergyBase { public: @@ -32,13 +33,11 @@ class UpwindEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; - UpwindEnergyBase() - : artificialViscosity( 1.0 ){}; - static String getType() { - return String( "UpwindEnergy< " ) + + return String( "StegerWarmingEnergy< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -57,6 +56,7 @@ class UpwindEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -68,11 +68,11 @@ class UpwindEnergyBase { this->density = density; }; - - void setArtificialViscosity( const RealType& artificialViscosity ) + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) { - this->artificialViscosity = artificialViscosity; - }; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } protected: @@ -81,33 +81,35 @@ class UpwindEnergyBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; - - RealType artificialViscosity; MeshFunctionPointer density; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergy +class StegerWarmingEnergy { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -119,7 +121,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index using typename BaseType::VelocityFieldPointer; using BaseType::Dimensions; - __cuda_callable__ RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -144,7 +145,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); }; - __cuda_callable__ RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -182,8 +182,8 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 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 ]; @@ -193,16 +193,18 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } @@ -227,14 +229,15 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -304,14 +307,14 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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& 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 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 ]; @@ -325,17 +328,17 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) @@ -348,7 +351,9 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -372,14 +377,15 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -449,18 +455,18 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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& 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 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 ]; @@ -477,29 +483,29 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) @@ -512,13 +518,15 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index - 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 ) - ); + ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-sw/UpwindMomentumBase.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumBase.h similarity index 93% rename from src/Examples/flow-sw/UpwindMomentumBase.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumBase.h index 8761467afc0143dace983dc730d0d8f41c069d6e..712cd9ee45b408a48c9c116dd1ca6c56ca26064e 100644 --- a/src/Examples/flow-sw/UpwindMomentumBase.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumBase.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumBase.h - description + StegerWarmingMomentumBase.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -14,9 +14,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumBase +class StegerWarmingMomentumBase { public: @@ -30,6 +31,7 @@ class UpwindMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; void setTau(const Real& tau) @@ -45,6 +47,7 @@ class UpwindMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setDensity( const MeshFunctionPointer& density ) @@ -59,10 +62,9 @@ class UpwindMomentumBase void setDynamicalViscosity( const RealType& dynamicalViscosity ) { - this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); } - __cuda_callable__ RealType positiveMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -77,7 +79,6 @@ class UpwindMomentumBase return density * velocity * velocity + pressure; }; - __cuda_callable__ RealType negativeMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -92,7 +93,6 @@ class UpwindMomentumBase return 0; }; - __cuda_callable__ 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 ); @@ -107,7 +107,6 @@ class UpwindMomentumBase return density * velocity_main * velocity_other; }; - __cuda_callable__ 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 ); @@ -129,11 +128,11 @@ class UpwindMomentumBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; - RealType dynamicalViscosity; - MeshFunctionPointer density; }; diff --git a/src/Examples/inviscid-flow-vl/UpwindMomentumX.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumX.h similarity index 67% rename from src/Examples/inviscid-flow-vl/UpwindMomentumX.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumX.h index ed49dda94585e64f85d820569a757d849757e6ca..c6588083cd9efdd02864d6200cff678de8d0a76d 100644 --- a/src/Examples/inviscid-flow-vl/UpwindMomentumX.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumX.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumX.h - description + StegerWarmingMomentumX.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "StegerWarmingMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumX +class StegerWarmingMomentumX { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "StegerWarmingMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -67,28 +69,31 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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& 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -112,14 +117,15 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -133,7 +139,7 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "StegerWarmingMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -151,13 +157,16 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); - const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + 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& 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 RealType& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; @@ -171,15 +180,15 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -192,7 +201,9 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } @@ -218,14 +229,15 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -239,7 +251,7 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "StegerWarmingMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -255,17 +267,17 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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& 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 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 ]; @@ -283,21 +295,21 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -316,7 +328,9 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-vl/UpwindMomentumY.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumY.h similarity index 67% rename from src/Examples/inviscid-flow-vl/UpwindMomentumY.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumY.h index c2126d43af781289f86999a5f4a7f8d24ad5c6e8..210fb60878d9da9f6f44bb55972997d73be63df7 100644 --- a/src/Examples/inviscid-flow-vl/UpwindMomentumY.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumY.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumY.h - description + StegerWarmingMomentumY.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "StegerWarmingMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumY +class StegerWarmingMomentumY { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "StegerWarmingMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "StegerWarmingMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -128,14 +131,14 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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& 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 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 ]; @@ -149,15 +152,15 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -170,7 +173,9 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -194,14 +199,15 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -215,7 +221,7 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "StegerWarmingMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -231,17 +237,17 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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& 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 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 ]; @@ -259,21 +265,21 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -292,7 +298,9 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-vl/UpwindMomentumZ.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumZ.h similarity index 71% rename from src/Examples/inviscid-flow-vl/UpwindMomentumZ.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumZ.h index 97339e804b3bda5203d0b12feeb59e30249f2327..135352d2fdf260a2310e5c6e45f2cc581d0e9ff0 100644 --- a/src/Examples/inviscid-flow-vl/UpwindMomentumZ.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumZ.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumZ.h - description + StegerWarmingMomentumZ.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "StegerWarmingMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumZ +class StegerWarmingMomentumZ { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "StegerWarmingMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "StegerWarmingMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -151,14 +154,15 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -172,7 +176,7 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "StegerWarmingMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -188,17 +192,17 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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& 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 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 ]; @@ -216,23 +220,23 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; - return -hxInverse * ( + return 0-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 ) @@ -249,7 +253,9 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/flow-sw/Upwind.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h similarity index 77% rename from src/Examples/flow-sw/Upwind.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h index 5aee91b62520fa9afd1c3427d330b6dab0e4ea98..db39578d027136b730038cc1b00007f2de0e4c4b 100644 --- a/src/Examples/flow-sw/Upwind.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h @@ -1,5 +1,5 @@ /*************************************************************************** - Upwind.h - description + VanLeer.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -15,18 +15,21 @@ #include #include -#include "UpwindContinuity.h" -#include "UpwindEnergy.h" -#include "UpwindMomentumX.h" -#include "UpwindMomentumY.h" -#include "UpwindMomentumZ.h" +#include "VanLeerContinuity.h" +#include "VanLeerEnergy.h" +#include "VanLeerMomentumX.h" +#include "VanLeerMomentumY.h" +#include "VanLeerMomentumZ.h" + +#include "Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide = NullOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class Upwind +class VanLeer { public: typedef Mesh MeshType; @@ -36,12 +39,18 @@ class Upwind typedef Functions::MeshFunction< Mesh > MeshFunctionType; static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; - 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 VanLeerContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef VanLeerMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef VanLeerMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef VanLeerMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef VanLeerEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; @@ -59,13 +68,14 @@ class Upwind config.addEntry< double >( prefix + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); } - Upwind() + VanLeer() :dynamicalViscosity( 1.0 ) {} bool setup( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters, const String& prefix = "" ) { + std::cout << "VanLeer" << std::endl; this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); diff --git a/src/Examples/flow-vl/UpwindContinuity.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerContinuity.h similarity index 83% rename from src/Examples/flow-vl/UpwindContinuity.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerContinuity.h index 20bae4fbb49fe4d1510f95f0ef4c2404873903f7..3b497125a6a291990c61c4fed6f158a73472e084 100644 --- a/src/Examples/flow-vl/UpwindContinuity.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerContinuity.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindContinuity.h - description + VanLeerContinuity.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -20,9 +20,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuityBase +class VanLeerContinuityBase { public: @@ -36,10 +37,11 @@ class UpwindContinuityBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; static String getType() { - return String( "UpwindContinuity< " ) + + return String( "VanLeerContinuity< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -65,7 +67,6 @@ class UpwindContinuityBase this->velocity = velocity; }; - __cuda_callable__ RealType positiveDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -78,7 +79,6 @@ class UpwindContinuityBase return density * velocity; }; - __cuda_callable__ RealType negativeDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -91,7 +91,6 @@ class UpwindContinuityBase return 0.0; }; - __cuda_callable__ RealType multiply (const RealType& a, const RealType& b ) const { return a * b; @@ -106,15 +105,18 @@ class UpwindContinuityBase VelocityFieldPointer velocity; + OperatorRightHandSideType rightHandSide; + MeshFunctionPointer pressure; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuity +class VanLeerContinuity { }; @@ -123,14 +125,15 @@ class UpwindContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -154,23 +157,25 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -194,14 +199,15 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -238,13 +244,13 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -257,7 +263,9 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -281,14 +289,15 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -330,17 +339,17 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -359,7 +368,9 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/inviscid-flow-vl/UpwindEnergy.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerEnergy.h similarity index 58% rename from src/Examples/inviscid-flow-vl/UpwindEnergy.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerEnergy.h index e3857cbcdf2e29110d01e3f6140a1f7da6b9f0b6..87ebdd26d326f2bbc1f70a98674d0d8901ded1a1 100644 --- a/src/Examples/inviscid-flow-vl/UpwindEnergy.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerEnergy.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindEnergy.h - description + VanLeerEnergy.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -16,9 +16,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergyBase +class VanLeerEnergyBase { public: @@ -32,13 +33,14 @@ class UpwindEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; - UpwindEnergyBase() + VanLeerEnergyBase() : artificialViscosity( 1.0 ){}; static String getType() { - return String( "UpwindEnergy< " ) + + return String( "VanLeerEnergy< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -57,6 +59,7 @@ class UpwindEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -74,6 +77,12 @@ class UpwindEnergyBase this->artificialViscosity = artificialViscosity; }; + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + protected: RealType tau; @@ -81,33 +90,37 @@ class UpwindEnergyBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; - RealType artificialViscosity; + RealType artificialViscosity, dynamicalViscosity; MeshFunctionPointer density; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergy +class VanLeerEnergy { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -119,7 +132,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index using typename BaseType::VelocityFieldPointer; using BaseType::Dimensions; - __cuda_callable__ RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -137,7 +149,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); }; - __cuda_callable__ RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -166,10 +177,12 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 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 ]; @@ -179,16 +192,18 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } @@ -213,14 +228,15 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -232,7 +248,6 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 ); @@ -245,7 +260,7 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 ) + * ( 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 ) ); @@ -263,11 +278,11 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 ) + * ( 1.0 - ( this->gamma - 1.0 ) * machNumber / 2.0 ) ); else return 0.0; - }; + }; template< typename MeshFunction, typename MeshEntity > __cuda_callable__ @@ -279,14 +294,21 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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& 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 ]; @@ -300,17 +322,25 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) @@ -323,7 +353,9 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -347,14 +379,15 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -414,18 +447,34 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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& 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& 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 ]; @@ -442,29 +491,53 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) @@ -478,12 +551,14 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index - 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 ) - ); + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-vl/UpwindMomentumBase.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumBase.h similarity index 85% rename from src/Examples/flow-vl/UpwindMomentumBase.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumBase.h index 706008b81880539d011cfcb37acb46ff289bf8f9..7ce89a972dd3063072d5cdcdd1e070f0f09a7463 100644 --- a/src/Examples/flow-vl/UpwindMomentumBase.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumBase.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumBase.h - description + VanLeerMomentumBase.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -14,9 +14,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumBase +class VanLeerMomentumBase { public: @@ -30,6 +31,7 @@ class UpwindMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; void setTau(const Real& tau) @@ -45,6 +47,7 @@ class UpwindMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setDensity( const MeshFunctionPointer& density ) @@ -60,9 +63,9 @@ class UpwindMomentumBase void setDynamicalViscosity( const RealType& dynamicalViscosity ) { this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); } - __cuda_callable__ RealType positiveMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -70,14 +73,11 @@ class UpwindMomentumBase if ( machNumber <= -1.0 ) return 0; else if ( machNumber <= 1.0 ) - return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) - * ( ( 2.0 * speedOfSound ) / this->gamma ) - * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.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; }; - __cuda_callable__ RealType negativeMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -85,14 +85,11 @@ class UpwindMomentumBase if ( machNumber <= -1.0 ) return density * velocity * velocity + pressure; else if ( machNumber <= 1.0 ) - return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) - * ( ( 2.0 * speedOfSound ) / this->gamma ) - * ( - 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.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; }; - __cuda_callable__ 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 ); @@ -105,7 +102,6 @@ class UpwindMomentumBase return density * velocity_main * velocity_other; }; - __cuda_callable__ 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 ); @@ -125,6 +121,8 @@ class UpwindMomentumBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; diff --git a/src/Examples/flow-vl/UpwindMomentumX.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumX.h similarity index 57% rename from src/Examples/flow-vl/UpwindMomentumX.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumX.h index edd3756208121de465185a84693a10671e587bac..04e41c015c6193ec3c7e45d5d737512a2762f38a 100644 --- a/src/Examples/flow-vl/UpwindMomentumX.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumX.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumX.h - description + VanLeerMomentumX.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "VanLeerMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumX +class VanLeerMomentumX { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "VanLeerMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -67,23 +69,24 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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& 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -91,10 +94,8 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -118,14 +119,15 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -139,7 +141,7 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "VanLeerMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -156,20 +158,21 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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 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 ]; @@ -183,23 +186,23 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -213,18 +216,8 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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; + + + this->rightHandSide(u, entity, time); } @@ -250,14 +243,15 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -271,7 +265,7 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "VanLeerMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -287,32 +281,33 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 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& 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& 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& 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& 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 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 ]; @@ -330,45 +325,45 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -388,26 +383,8 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-sw/UpwindMomentumY.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumY.h similarity index 57% rename from src/Examples/flow-sw/UpwindMomentumY.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumY.h index 4b5a7bcb26d049c2773790857d3f79246488b55b..65ac8482807903cb2e98f8fbc25a4627d1ef7a4b 100644 --- a/src/Examples/flow-sw/UpwindMomentumY.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumY.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumY.h - description + VanLeerMomentumY.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "VanLeerMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumY +class VanLeerMomentumY { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "VanLeerMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "VanLeerMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -128,20 +131,21 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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 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 ]; @@ -155,23 +159,23 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -185,18 +189,8 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -220,14 +214,15 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -241,7 +236,7 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "VanLeerMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -257,32 +252,33 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 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& 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& 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& 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& 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 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 ]; @@ -300,45 +296,45 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -358,26 +354,8 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-sw/UpwindMomentumZ.h b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumZ.h similarity index 59% rename from src/Examples/flow-sw/UpwindMomentumZ.h rename to src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumZ.h index 887eec977517e5850db2085835d8242d63605c96..125166cb885b65a8f14049a90dcf92449d644498 100644 --- a/src/Examples/flow-sw/UpwindMomentumZ.h +++ b/src/Examples/flows/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumZ.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumZ.h - description + VanLeerMomentumZ.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "VanLeerMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumZ +class VanLeerMomentumZ { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "VanLeerMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "VanLeerMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -151,14 +154,15 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -172,7 +176,7 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "VanLeerMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -188,32 +192,33 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 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& 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& 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& 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& 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 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 ]; @@ -231,45 +236,45 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_z_center, velocity_x_center, pressure_center ) @@ -289,29 +294,8 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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; + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesContinuityOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesContinuityOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..8c46746ef772b32ac2d1cf44e36920a95a1bfa51 --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesContinuityOperatorRightHandSide.h @@ -0,0 +1,218 @@ +/*************************************************************************** + NavierStokesContinuityOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class NavierStokesContinuityRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + protected: + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class NavierStokesContinuityRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class NavierStokesContinuityRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesContinuityRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesContinuityRightHandSideBase< 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" ); + + return 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 NavierStokesContinuityRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesContinuityRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesContinuityRightHandSideBase< 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" ); + + return 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 NavierStokesContinuityRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesContinuityRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesContinuityRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} //namespace TNL diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesEnergyOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..64fbb24299e344bd03d20450d8191ff869ad6522 --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesEnergyOperatorRightHandSide.h @@ -0,0 +1,474 @@ +/*************************************************************************** + NavierStokesEnergyOperatorRightHandSide.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 +#include + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class NavierStokesEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + NavierStokesEnergyRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + protected: + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class NavierStokesEnergyRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class NavierStokesEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 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 NavierStokesEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + - velocity_x_center * velocity_x_center + velocity_x_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_south + - velocity_x_northWest * velocity_y_north + velocity_x_southWest * velocity_y_south + ) * 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 NavierStokesEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// wT_13_x + + ( ( velocity_x_upEast * velocity_z_east - velocity_x_downEast * velocity_z_east + - velocity_x_upWest * velocity_z_west + velocity_x_downWest * velocity_z_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center - velocity_z_center * velocity_z_west + - velocity_z_center * velocity_z_center + velocity_z_west * velocity_z_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + + velocity_x_center * velocity_x_center + velocity_x_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_23_y + + ( ( velocity_y_upNorth * velocity_z_north - velocity_y_downNorth * velocity_y_north + - velocity_y_upSouth * velocity_z_south + velocity_y_downSouth * velocity_z_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center - velocity_z_center * velocity_z_south + - velocity_z_center * velocity_z_center + velocity_z_south * velocity_z_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// uT_31_z + + ( ( velocity_x_up * velocity_x_center - velocity_x_center * velocity_x_center + - velocity_x_center * velocity_x_down + velocity_x_down * velocity_x_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up - velocity_z_downEast * velocity_x_down + - velocity_z_upWest * velocity_x_up + velocity_z_downWest * velocity_x_down + ) * hxInverse * hzInverse / 4 + ) * this->dynamicalViscosity +// T_32_z + + ( ( velocity_z_upNorth * velocity_y_up - velocity_z_downNorth * velocity_y_down + - velocity_z_upSouth * velocity_y_up + velocity_z_downSouth * velocity_y_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center - velocity_x_center * velocity_y_down + - velocity_x_center * velocity_y_center + velocity_x_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/src/Examples/flow/LaxFridrichsMomentumBaseEuler.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumBaseOperatorRightHandSide.h similarity index 69% rename from src/Examples/flow/LaxFridrichsMomentumBaseEuler.h rename to src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumBaseOperatorRightHandSide.h index cc2561748968a2bd808fa434d4f3d87d41765f45..9951441b16c5386d35c5fda8938398f5cf9ba149 100644 --- a/src/Examples/flow/LaxFridrichsMomentumBaseEuler.h +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumBaseOperatorRightHandSide.h @@ -1,5 +1,5 @@ /*************************************************************************** - LaxFridrichsMomentumBase.h - description + NavierStokesMomentumRightHandSideBase.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -16,7 +16,7 @@ namespace TNL { template< typename Mesh, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class LaxFridrichsMomentumBase +class NavierStokesMomentumRightHandSideBase { public: @@ -31,38 +31,24 @@ class LaxFridrichsMomentumBase typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; - LaxFridrichsMomentumBase() - : artificialViscosity( 1.0 ){}; + NavierStokesMomentumRightHandSideBase() + : dynamicalViscosity( 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 ) + void setDynamicalViscosity( const RealType& dynamicalViscosity ) { - this->artificialViscosity = artificialViscosity; + this->dynamicalViscosity = dynamicalViscosity; } protected: - RealType tau; - VelocityFieldPointer velocity; - MeshFunctionPointer pressure; - - RealType artificialViscosity; + RealType dynamicalViscosity; }; } //namespace TNL diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumXOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumXOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..6dd2373ea39deca6d8c54c30812252e6b99f23f8 --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumXOperatorRightHandSide.h @@ -0,0 +1,362 @@ +/*************************************************************************** + NavierStokesMomentumXRightHandSide.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 +#include +#include "NavierStokesMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class NavierStokesMomentumXRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class NavierStokesMomentumXRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesMomentumRightHandSideBase< 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& 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& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 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 NavierStokesMomentumXRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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 + ) * hySquareInverse + ) * this->dynamicalViscosity; + } + + /*template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, typename Vector, typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + const MeshFunctionType& u, + Vector& b, + MatrixRow& matrixRow ) const;*/ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class NavierStokesMomentumXRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_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 + ) * hxSquareInverse + ) * this->dynamicalViscosity +// T_31_z + + ( ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse / 4 + + ( velocity_x_up - 2 * velocity_x_center + velocity_x_down + ) * hzSquareInverse + ) * 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/src/Examples/flow/LaxFridrichsMomentumY.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumYOperatorRightHandSide.h similarity index 51% rename from src/Examples/flow/LaxFridrichsMomentumY.h rename to src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumYOperatorRightHandSide.h index 0df12c5227981b42b64437a4be96a511cf1b5991..179b325fad45c45a4e67bac656dfab9464335e1a 100644 --- a/src/Examples/flow/LaxFridrichsMomentumY.h +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumYOperatorRightHandSide.h @@ -1,5 +1,5 @@ /*************************************************************************** - LaxFridrichsMomentumY.h - description + NavierStokesMomentumYRightHandSide.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,14 +13,14 @@ #include #include -#include "LaxFridrichsMomentumBase.h" +#include "NavierStokesMomentumBaseOperatorRightHandSide.h" namespace TNL { template< typename Mesh, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class LaxFridrichsMomentumY +class NavierStokesMomentumYRightHandSide { }; @@ -29,13 +29,13 @@ template< typename MeshReal, 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 > +class NavierStokesMomentumYRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -92,12 +92,12 @@ template< typename MeshReal, 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 > +class NavierStokesMomentumYRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -128,49 +128,44 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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 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& 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 IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); - const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; - const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; - - const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_y_east = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_y_west = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; - return 1.0 / ( 4.0 * this->tau ) * this->artificialViscosity * ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] - 4.0 * rho_v[ center ] ) - - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) - - ( rho_v[ west ] * velocity_x_west ) )* hxInverse - + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) - - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ) + return // 2D T_22_y - + ( 4.0 / 3.0 * ( velocity_y_north - 2 * velocity_y_center + velocity_y_south + ( 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 @@ -206,12 +201,12 @@ template< typename MeshReal, 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 > +class NavierStokesMomentumYRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -240,89 +235,80 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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 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& 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& 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& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); - const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); - const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; - const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; - const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; - const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; - - const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; - - const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; - const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; - const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; - - return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * - ( rho_v[ west ] + rho_v[ east ] + rho_v[ south ] + rho_v[ north ] + rho_v[ up ] + rho_v[ down ] - 6.0 * rho_v[ center ] ) - - 0.5 * ( ( ( rho_v[ east ] * velocity_x_east ) - - ( rho_v[ west ] * velocity_x_west ) ) * hxInverse - + ( ( rho_v[ north ] * velocity_y_north + pressure_north ) - - ( rho_v[ south ] * velocity_y_south + pressure_south ) ) * hyInverse - + ( ( rho_v[ up ] * velocity_z_up ) - - ( rho_v[ down ] * velocity_z_down ) ) * hzInverse ) + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return // T_12_y - + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ( ( 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 + + ( velocity_y_east - 2 * velocity_y_center + velocity_y_west + ) * hxSquareInverse ) * this->dynamicalViscosity // 3D T_22_y + ( 4.0 / 3.0 * ( velocity_y_north - 2 * velocity_y_center + velocity_y_south @@ -335,8 +321,8 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real // 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 + + ( velocity_y_up - 2 * velocity_y_center + velocity_y_down + ) * hzSquareInverse ) * this->dynamicalViscosity; } diff --git a/src/Examples/flow/LaxFridrichsMomentumZ.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumZOperatorRightHandSide.h similarity index 56% rename from src/Examples/flow/LaxFridrichsMomentumZ.h rename to src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumZOperatorRightHandSide.h index e4f8501ec1f3c44f1a39fb2a5aa85de5209f9635..47fb42c577cb2a770f2aa91fd1d1c9f2dc92799b 100644 --- a/src/Examples/flow/LaxFridrichsMomentumZ.h +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesMomentumZOperatorRightHandSide.h @@ -1,5 +1,5 @@ /*************************************************************************** - LaxFridrichsMomentumZ.h - description + NavierStokesMomentumZRightHandSide.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,14 +13,14 @@ #include #include -#include "LaxFridrichsMomentumBase.h" +#include "NavierStokesMomentumBaseOperatorRightHandSide.h" namespace TNL { template< typename Mesh, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class LaxFridrichsMomentumZ +class NavierStokesMomentumZRightHandSide { }; @@ -29,13 +29,13 @@ template< typename MeshReal, 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 > +class NavierStokesMomentumZRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -92,12 +92,12 @@ template< typename MeshReal, 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 > +class NavierStokesMomentumZRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -153,12 +153,12 @@ template< typename MeshReal, 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 > +class NavierStokesMomentumZRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public NavierStokesMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef NavierStokesMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -188,96 +188,87 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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 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 IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + 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& 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& 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& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); - const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); - const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); - - const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; - const RealType& pressure_east = this->pressure.template getData< DeviceType >()[ east ]; - const RealType& pressure_north = this->pressure.template getData< DeviceType >()[ north ]; - const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; - const RealType& pressure_up = this->pressure.template getData< DeviceType >()[ up ]; - const RealType& pressure_down = this->pressure.template getData< DeviceType >()[ down ]; + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); - const RealType& velocity_x_east = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ east ]; - const RealType& velocity_x_west = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ west ]; - const RealType& velocity_x_center = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_x_northWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_x_northEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_x_southWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_x_southEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_x_upWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_x_downWest = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_x_upEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_x_downEast = this->velocity.template getData< DeviceType >()[ 0 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; - const RealType& velocity_y_north = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ north ]; - const RealType& velocity_y_south = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ south ]; - const RealType& velocity_y_center = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_y_northWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northWest ]; - const RealType& velocity_y_northEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ northEast ]; - const RealType& velocity_y_southWest = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southWest ]; - const RealType& velocity_y_southEast = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ southEast ]; - const RealType& velocity_y_upNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_y_upSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_y_downNorth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_y_downSouth = this->velocity.template getData< DeviceType >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; - const RealType& velocity_z_up = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ up ]; - const RealType& velocity_z_down = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ down ]; - const RealType& velocity_z_center = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ center ]; - const RealType& velocity_z_upWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upWest ]; - const RealType& velocity_z_upEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upEast ]; - const RealType& velocity_z_upNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upNorth ]; - const RealType& velocity_z_upSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ upSouth ]; - const RealType& velocity_z_downWest = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downWest ]; - const RealType& velocity_z_downEast = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downEast ]; - const RealType& velocity_z_downNorth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downNorth ]; - const RealType& velocity_z_downSouth = this->velocity.template getData< DeviceType >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; - return 1.0 / ( 6.0 * this->tau ) * this->artificialViscosity * - ( rho_w[ west ] + rho_w[ east ] + rho_w[ south ] + rho_w[ north ] + rho_w[ up ] + rho_w[ down ] - 6.0 * rho_w[ center ] ) - -0.5 * ( ( ( rho_w[ east ] * velocity_x_east ) - - ( rho_w[ west ] * velocity_x_west ) )* hxInverse - + ( ( rho_w[ north ] * velocity_y_north ) - - ( rho_w[ south ] * velocity_y_south ) )* hyInverse - + ( ( rho_w[ up ] * velocity_z_up + pressure_up ) - - ( rho_w[ down ] * velocity_z_down + pressure_down ) )* hzInverse ) -// T_13_z - + ( ( velocity_z_up - 2 * velocity_z_center + velocity_z_down ) - * hzSquareInverse + return +// T_13_x + ( ( velocity_z_east - 2 * velocity_z_center + velocity_z_west ) + * hxSquareInverse + ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) * hxInverse * hzInverse / 4 ) * this->dynamicalViscosity -// T_23_z +// T_23_y + ( ( 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 + + ( velocity_z_north - 2 * velocity_z_center + velocity_z_south ) + * hySquareInverse ) * this->dynamicalViscosity // 3D T_33_z diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..b41a9e6a94ae835a625e1ea86f39dc9e8942e25e --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h @@ -0,0 +1,124 @@ +/*************************************************************************** + NavierStokesOpratorRightHandSide.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 +#include +#include + +#include "NavierStokesContinuityOperatorRightHandSide.h" +#include "NavierStokesEnergyOperatorRightHandSide.h" +#include "NavierStokesMomentumXOperatorRightHandSide.h" +#include "NavierStokesMomentumYOperatorRightHandSide.h" +#include "NavierStokesMomentumZOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class NavierStokesOperatorRightHandSide +{ + 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 NavierStokesContinuityRightHandSide< Mesh, Real, Index > ContinuityOperatorRightHandSideType; + typedef NavierStokesMomentumXRightHandSide< Mesh, Real, Index > MomentumXOperatorRightHandSideType; + typedef NavierStokesMomentumYRightHandSide< Mesh, Real, Index > MomentumYOperatorRightHandSideType; + typedef NavierStokesMomentumZRightHandSide< Mesh, Real, Index > MomentumZOperatorRightHandSideType; + typedef NavierStokesEnergyRightHandSide< Mesh, Real, Index > EnergyOperatorRightHandSideType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorRightHandSideType > ContinuityOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumXOperatorRightHandSideType > MomentumXOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumYOperatorRightHandSideType > MomentumYOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumZOperatorRightHandSideType > MomentumZOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< EnergyOperatorRightHandSideType > EnergyOperatorRightHandSidePointer; + + 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 ); + } + + NavierStokesOperatorRightHandSide() + : dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "N-S" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + return true; + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + std::cout << "N-S" << std::endl; + this->continuityOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumXOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumYOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumZOperatorRightHandSidePointer->setVelocity( velocity ); + this->energyOperatorRightHandSidePointer->setVelocity( velocity ); + } + + const ContinuityOperatorRightHandSidePointer& getContinuityOperatorRightHandSide() const + { + return this->continuityOperatorRightHandSidePointer; + } + + const MomentumXOperatorRightHandSidePointer& getMomentumXOperatorRightHandSide() const + { + return this->momentumXOperatorRightHandSidePointer; + } + + const MomentumYOperatorRightHandSidePointer& getMomentumYOperatorRightHandSide() const + { + return this->momentumYOperatorRightHandSidePointer; + } + + const MomentumZOperatorRightHandSidePointer& getMomentumZOperatorRightHandSide() const + { + return this->momentumZOperatorRightHandSidePointer; + } + + const EnergyOperatorRightHandSidePointer& getEnergyOperatorRightHandSide() const + { + return this->energyOperatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorRightHandSidePointer continuityOperatorPointer; + MomentumXOperatorRightHandSidePointer momentumXOperatorPointer; + MomentumYOperatorRightHandSidePointer momentumYOperatorPointer; + MomentumZOperatorRightHandSidePointer momentumZOperatorPointer; + EnergyOperatorRightHandSidePointer energyOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullContinuityOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullContinuityOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..2a7eee73f1c429e0c7f8d4f3ce81c626ac50c310 --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullContinuityOperatorRightHandSide.h @@ -0,0 +1,218 @@ +/*************************************************************************** + nullContinuityOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class nullContinuityRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + protected: + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class nullContinuityRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class nullContinuityRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public nullContinuityRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef nullContinuityRightHandSideBase< 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" ); + + return 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 nullContinuityRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public nullContinuityRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef nullContinuityRightHandSideBase< 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" ); + + return 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 nullContinuityRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public nullContinuityRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef nullContinuityRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} //namespace TNL diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullEnergyOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..8badc0518084a4f50d86655f210e3001ba7ba6f0 --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullEnergyOperatorRightHandSide.h @@ -0,0 +1,229 @@ +/*************************************************************************** + nullEnergyOperatorRightHandSide.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 +#include + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class nullEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + nullEnergyRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + protected: + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class nullEnergyRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class nullEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public nullEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef nullEnergyRightHandSideBase< 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" ); + + return 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 nullEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public nullEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef nullEnergyRightHandSideBase< 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" ); + + return 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 nullEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public nullEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef nullEnergyRightHandSideBase< 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" ); + + return 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;*/ +}; + +} //namespace TNL diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumBaseOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumBaseOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..a24c7a764901d5879a9574eec60a152eb861a31d --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumBaseOperatorRightHandSide.h @@ -0,0 +1,54 @@ +/*************************************************************************** + nullMomentumRightHandSideBase.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 nullMomentumRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + nullMomentumRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + protected: + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumXOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumXOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..81bcad971237eab180cfe38a139e5cc557c5b9e9 --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumXOperatorRightHandSide.h @@ -0,0 +1,211 @@ +/*************************************************************************** + nullMomentumXRightHandSide.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 +#include +#include "nullMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class nullMomentumXRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class nullMomentumXRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef nullMomentumRightHandSideBase< 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" ); + + return 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 nullMomentumXRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef nullMomentumRightHandSideBase< 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" ); + + return 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 nullMomentumXRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef nullMomentumRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} // namespace TNL + diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumYOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumYOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..6aa0680e3f469f0fb0541c9052aedae337cc6640 --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumYOperatorRightHandSide.h @@ -0,0 +1,213 @@ +/*************************************************************************** + nullMomentumYRightHandSide.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 +#include +#include "nullMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class nullMomentumYRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class nullMomentumYRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef nullMomentumRightHandSideBase< 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 nullMomentumYRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef nullMomentumRightHandSideBase< 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" ); + + + return 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 nullMomentumYRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef nullMomentumRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} // namespace TNL + diff --git a/src/Examples/flow/LaxFridrichsMomentumZEuler.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumZOperatorRightHandSide.h similarity index 66% rename from src/Examples/flow/LaxFridrichsMomentumZEuler.h rename to src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumZOperatorRightHandSide.h index a67e862ceffd78d4fd770d7b1a07e9f05af349d8..a6be207b4e5504c5655eada4a803f7be8ca03827 100644 --- a/src/Examples/flow/LaxFridrichsMomentumZEuler.h +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullMomentumZOperatorRightHandSide.h @@ -1,5 +1,5 @@ /*************************************************************************** - LaxFridrichsMomentumZ.h - description + nullMomentumZRightHandSide.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,14 +13,14 @@ #include #include -#include "LaxFridrichsMomentumBase.h" +#include "nullMomentumBaseOperatorRightHandSide.h" namespace TNL { template< typename Mesh, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class LaxFridrichsMomentumZ +class nullMomentumZRightHandSide { }; @@ -29,13 +29,13 @@ template< typename MeshReal, 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 > +class nullMomentumZRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef nullMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -92,12 +92,12 @@ template< typename MeshReal, 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 > +class nullMomentumZRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef nullMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -153,12 +153,12 @@ template< typename MeshReal, 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 > +class nullMomentumZRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public nullMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef nullMomentumRightHandSideBase< MeshType, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -186,35 +186,7 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real { 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 ); + return 0; } /*template< typename MeshEntity > diff --git a/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..85b8581f2bbf42869ddeac853f286ee1af57845f --- /dev/null +++ b/src/Examples/flows/DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h @@ -0,0 +1,124 @@ +/*************************************************************************** + nullOpratorRightHandSide.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 +#include +#include + +#include "nullContinuityOperatorRightHandSide.h" +#include "nullEnergyOperatorRightHandSide.h" +#include "nullMomentumXOperatorRightHandSide.h" +#include "nullMomentumYOperatorRightHandSide.h" +#include "nullMomentumZOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class NullOperatorRightHandSide +{ + 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 nullContinuityRightHandSide< Mesh, Real, Index > ContinuityOperatorRightHandSideType; + typedef nullMomentumXRightHandSide< Mesh, Real, Index > MomentumXOperatorRightHandSideType; + typedef nullMomentumYRightHandSide< Mesh, Real, Index > MomentumYOperatorRightHandSideType; + typedef nullMomentumZRightHandSide< Mesh, Real, Index > MomentumZOperatorRightHandSideType; + typedef nullEnergyRightHandSide< Mesh, Real, Index > EnergyOperatorRightHandSideType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorRightHandSideType > ContinuityOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumXOperatorRightHandSideType > MomentumXOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumYOperatorRightHandSideType > MomentumYOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumZOperatorRightHandSideType > MomentumZOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< EnergyOperatorRightHandSideType > EnergyOperatorRightHandSidePointer; + + 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 ); + } + + NullOperatorRightHandSide() + : dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "null" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + return true; + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + std::cout << "null" << std::endl; + this->continuityOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumXOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumYOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumZOperatorRightHandSidePointer->setVelocity( velocity ); + this->energyOperatorRightHandSidePointer->setVelocity( velocity ); + } + + const ContinuityOperatorRightHandSidePointer& getContinuityOperatorRightHandSide() const + { + return this->continuityOperatorRightHandSidePointer; + } + + const MomentumXOperatorRightHandSidePointer& getMomentumXOperatorRightHandSide() const + { + return this->momentumXOperatorRightHandSidePointer; + } + + const MomentumYOperatorRightHandSidePointer& getMomentumYOperatorRightHandSide() const + { + return this->momentumYOperatorRightHandSidePointer; + } + + const MomentumZOperatorRightHandSidePointer& getMomentumZOperatorRightHandSide() const + { + return this->momentumZOperatorRightHandSidePointer; + } + + const EnergyOperatorRightHandSidePointer& getEnergyOperatorRightHandSide() const + { + return this->energyOperatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorRightHandSidePointer continuityOperatorPointer; + MomentumXOperatorRightHandSidePointer momentumXOperatorPointer; + MomentumYOperatorRightHandSidePointer momentumYOperatorPointer; + MomentumZOperatorRightHandSidePointer momentumZOperatorPointer; + EnergyOperatorRightHandSidePointer energyOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/flow-vl/PhysicalVariablesGetter.h b/src/Examples/flows/PhysicalVariablesGetter.h similarity index 97% rename from src/Examples/flow-vl/PhysicalVariablesGetter.h rename to src/Examples/flows/PhysicalVariablesGetter.h index d7eeb7618657c34485b3e4842ea04e12d3ee725c..2af0a02b820db183fa32669dcecfe63f7f006990 100644 --- a/src/Examples/flow-vl/PhysicalVariablesGetter.h +++ b/src/Examples/flows/PhysicalVariablesGetter.h @@ -79,7 +79,7 @@ class PhysicalVariablesGetter { const RealType e = energy.template getData< DeviceType >()( meshEntity ); const RealType rho = density.template getData< DeviceType >()( meshEntity ); - const RealType momentumNorm = lpNorm( momentum.template getData< DeviceType >().getVector( meshEntity ), 2.0 ); + const RealType momentumNorm = momentum.template getData< DeviceType >().getVector( meshEntity ).lpNorm( 2.0 ); if( rho == 0.0 ) return 0; else diff --git a/src/Examples/flow-sw/RiemannProblemInitialCondition.h b/src/Examples/flows/RiemannProblemInitialCondition.h similarity index 99% rename from src/Examples/flow-sw/RiemannProblemInitialCondition.h rename to src/Examples/flows/RiemannProblemInitialCondition.h index dfde32625973ef72161ebed80d633a089666049f..d3d619c7203854d15f9c6ab6dd1fa82ae8dff53c 100644 --- a/src/Examples/flow-sw/RiemannProblemInitialCondition.h +++ b/src/Examples/flows/RiemannProblemInitialCondition.h @@ -919,7 +919,6 @@ class RiemannProblemInitialCondition 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, @@ -1258,9 +1257,6 @@ class RiemannProblemInitialCondition this->SEDPressure = preSEDPressure; this->SEDEnergy = Energy( SEDDensity, SEDPressure, gamma, SEDVelocity); this->SEDMomentum = SEDVelocity * SEDDensity; - - std::cout << this->SEDEnergy; - std::cout << this->SWDEnergy; } @@ -1291,7 +1287,7 @@ class RiemannProblemInitialCondition 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 ))); + case 3: energy = (Pressure / (gamma -1.0) + 0.5 * Density * (std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 2 ], 2 ))); break; // druhou mocninu ps8t jako sou4in } return energy; @@ -1342,7 +1338,7 @@ class RiemannProblemInitialCondition typedef Functions::Analytic::VectorNorm< Dimensions, RealType > VectorNormType; typedef Operators::Analytic::Sign< Dimensions, RealType > SignType; typedef Functions::OperatorFunction< SignType, VectorNormType > InitialConditionType; - typedef Pointers::SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; + typedef SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; InitialConditionPointer initialCondition; initialCondition->getFunction().setCenter( center ); diff --git a/src/Examples/flows/flowsBuildConfigTag.h b/src/Examples/flows/flowsBuildConfigTag.h new file mode 100644 index 0000000000000000000000000000000000000000..c40b793b9e237d0ad756a66c57088373cad3e41b --- /dev/null +++ b/src/Examples/flows/flowsBuildConfigTag.h @@ -0,0 +1,72 @@ +#ifndef FLOWSBUILDCONFIGTAG_H_ +#define FLOWSBUILDCONFIGTAG_H_ + +#include +#include + +namespace TNL { + +class flowsBuildConfigTag{}; + +namespace Solvers { + +/**** + * Turn off support for float and long double. + */ +template<> struct ConfigTagReal< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct ConfigTagReal< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct ConfigTagIndex< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct ConfigTagIndex< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +//template< int Dimension > struct ConfigTagDimension< flowsBuildConfigTag, 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< flowsBuildConfigTag, Meshes::Grid< Dimension, Real, Device, Index > > + { enum { enabled = ConfigTagDimension< flowsBuildConfigTag, Dimension >::enabled && + ConfigTagReal< flowsBuildConfigTag, Real >::enabled && + ConfigTagDevice< flowsBuildConfigTag, Device >::enabled && + ConfigTagIndex< flowsBuildConfigTag, Index >::enabled }; }; +*/ +/**** + * Please, chose your preferred time discretisation here. + */ +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ExplicitTimeDiscretisationTag >{ enum { enabled = true }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, SemiImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; + +/**** + * Only the Runge-Kutta-Merson solver is enabled by default. + */ +template<> struct ConfigTagExplicitSolver< flowsBuildConfigTag, ExplicitEulerSolverTag >{ enum { enabled = true }; }; + +} // namespace Solvers + +namespace Meshes { +namespace BuildConfigTags { + +template< int Dimensions > struct GridDimensionTag< flowsBuildConfigTag, Dimensions >{ enum { enabled = true }; }; + +/**** + * Turn off support for float and long double. + */ +template<> struct GridRealTag< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct GridRealTag< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct GridIndexTag< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct GridIndexTag< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +} // namespace BuildConfigTags +} // namespace Meshes +} // namespace TNL + +#endif /* FLOWSBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/inviscid-flow-vl/eulerRhs.h b/src/Examples/flows/flowsRhs.h similarity index 71% rename from src/Examples/inviscid-flow-vl/eulerRhs.h rename to src/Examples/flows/flowsRhs.h index 51d4e024398d579f49c158292e2890536a1e319c..e0b8c7fac887f2b8ea588020ede105d9c8950888 100644 --- a/src/Examples/inviscid-flow-vl/eulerRhs.h +++ b/src/Examples/flows/flowsRhs.h @@ -1,11 +1,11 @@ -#ifndef eulerRHS_H_ -#define eulerRHS_H_ +#ifndef FLOWSRHS_H_ +#define FLOWSRHS_H_ #include namespace TNL { -template< typename Mesh, typename Real >class eulerRhs +template< typename Mesh, typename Real >class flowsRhs : public Functions::Domain< Mesh::getMeshDimension(), Functions::MeshDomain > { public: @@ -24,12 +24,12 @@ template< typename Mesh, typename Real >class eulerRhs Real operator()( const MeshEntity& entity, const Real& time = 0.0 ) const { - typedef typename MeshEntity::MeshType::PointType PointType; - PointType v = entity.getCenter(); +// typedef typename MeshEntity::MeshType::PointType PointType; +// PointType v = entity.getCenter(); return 0.0; } }; } //namespace TNL -#endif /* eulerRHS_H_ */ +#endif /* FLOWSRHS_H_ */ diff --git a/src/Examples/flow-sw/navierStokes.cpp b/src/Examples/flows/navierStokes.cpp similarity index 100% rename from src/Examples/flow-sw/navierStokes.cpp rename to src/Examples/flows/navierStokes.cpp diff --git a/src/Examples/flow-sw/navierStokes.cu b/src/Examples/flows/navierStokes.cu similarity index 100% rename from src/Examples/flow-sw/navierStokes.cu rename to src/Examples/flows/navierStokes.cu diff --git a/src/Examples/flows/navierStokes.h b/src/Examples/flows/navierStokes.h new file mode 100644 index 0000000000000000000000000000000000000000..18ca18996f79b87cd44d91589a1bbe212bafc663 --- /dev/null +++ b/src/Examples/flows/navierStokes.h @@ -0,0 +1,456 @@ +#include +#include +#include +#include +#include +#include "navierStokesProblem.h" +#include "DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h" +#include "DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h" +#include "DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h" +#include "DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h" +#include "DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "differential-operator", "Choose the differential operator.", "Lax-Friedrichs"); + config.addEntryEnum< String >( "Lax-Friedrichs" ); + config.addEntryEnum< String >( "Steger-Warming" ); + config.addEntryEnum< String >( "VanLeer" ); + config.addEntryEnum< String >( "AUSMPlus" ); + config.addEntry< String >( "operator-right-hand-side", "Choose equation type.", "Euler"); + config.addEntryEnum< String >( "Euler" ); + config.addEntryEnum< String >( "Navier-Stokes" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class navierStokesSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + String operatorRightHandSideType = parameters.getParameter< String >( "operator-right-hand-side"); + if( operatorRightHandSideType == "Euler" ) + { + typedef NullOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + String differentialOperatorType = parameters.getParameter< String >( "differential-operator"); + if( differentialOperatorType == "Lax-Friedrichs" ) + { + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "Steger-Warming" ) + { + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "VanLeer" ) + { + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "AUSMPlus" ) + { + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + } + if( operatorRightHandSideType == "Navier-Stokes" ) + { + typedef NavierStokesOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + String differentialOperatorType = parameters.getParameter< String >( "differential-operator"); + if( differentialOperatorType == "Lax-Friedrichs" ) + { + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "Steger-Warming" ) + { + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "VanLeer" ) + { + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "AUSMPlus" ) + { + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, 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/src/Examples/flows/navierStokesAUSMPlus.cpp b/src/Examples/flows/navierStokesAUSMPlus.cpp new file mode 100644 index 0000000000000000000000000000000000000000..461c91191077e3d34920a961b88f07ae226fd6b1 --- /dev/null +++ b/src/Examples/flows/navierStokesAUSMPlus.cpp @@ -0,0 +1 @@ +#include "navierStokesAUSMPlus.h" diff --git a/src/Examples/flows/navierStokesAUSMPlus.cu b/src/Examples/flows/navierStokesAUSMPlus.cu new file mode 100644 index 0000000000000000000000000000000000000000..461c91191077e3d34920a961b88f07ae226fd6b1 --- /dev/null +++ b/src/Examples/flows/navierStokesAUSMPlus.cu @@ -0,0 +1 @@ +#include "navierStokesAUSMPlus.h" diff --git a/src/Examples/flows/navierStokesAUSMPlus.h b/src/Examples/flows/navierStokesAUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..9330335413c93e40cc8ad1d1bceb5a8d5fe587a6 --- /dev/null +++ b/src/Examples/flows/navierStokesAUSMPlus.h @@ -0,0 +1,189 @@ +//#include +#include +#include +#include +#include +#include +#include "navierStokesProblem.h" +#include "DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h" +#include "DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "operator-right-hand-side", "Choose equation type.", "Euler"); + config.addEntryEnum< String >( "Euler" ); + config.addEntryEnum< String >( "Navier-Stokes" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + AUSMPlus< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class navierStokesSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + String operatorRightHandSideType = parameters.getParameter< String >( "operator-right-hand-side"); + if( operatorRightHandSideType == "Euler" ) + { + typedef NullOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( operatorRightHandSideType == "Navier-Stokes" ) + { + typedef NavierStokesOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, 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/src/Examples/flows/navierStokesLaxFriedrichs.cpp b/src/Examples/flows/navierStokesLaxFriedrichs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d23adec9ca339c8d4e3c8d33f6914c6d3bd509dd --- /dev/null +++ b/src/Examples/flows/navierStokesLaxFriedrichs.cpp @@ -0,0 +1 @@ +#include "navierStokesLaxFriedrichs.h" diff --git a/src/Examples/flows/navierStokesLaxFriedrichs.cu b/src/Examples/flows/navierStokesLaxFriedrichs.cu new file mode 100644 index 0000000000000000000000000000000000000000..d23adec9ca339c8d4e3c8d33f6914c6d3bd509dd --- /dev/null +++ b/src/Examples/flows/navierStokesLaxFriedrichs.cu @@ -0,0 +1 @@ +#include "navierStokesLaxFriedrichs.h" diff --git a/src/Examples/flows/navierStokesLaxFriedrichs.h b/src/Examples/flows/navierStokesLaxFriedrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..6aabedd7d60af45685231fb18f7c5df9cd078ce8 --- /dev/null +++ b/src/Examples/flows/navierStokesLaxFriedrichs.h @@ -0,0 +1,189 @@ +//#include +#include +#include +#include +#include +#include +#include "navierStokesProblem.h" +#include "DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h" +#include "DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "operator-right-hand-side", "Choose equation type.", "Euler"); + config.addEntryEnum< String >( "Euler" ); + config.addEntryEnum< String >( "Navier-Stokes" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class navierStokesSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + String operatorRightHandSideType = parameters.getParameter< String >( "operator-right-hand-side"); + if( operatorRightHandSideType == "Euler" ) + { + typedef NullOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( operatorRightHandSideType == "Navier-Stokes" ) + { + typedef NavierStokesOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, 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/src/Examples/flow-vl/navierStokesProblem.h b/src/Examples/flows/navierStokesProblem.h similarity index 73% rename from src/Examples/flow-vl/navierStokesProblem.h rename to src/Examples/flows/navierStokesProblem.h index 51cc5f014f40fb51f45782c5332baf868487fa2e..7fed439bf811ffdc5bffe13c321eecc939654cd9 100644 --- a/src/Examples/flow-vl/navierStokesProblem.h +++ b/src/Examples/flows/navierStokesProblem.h @@ -12,7 +12,7 @@ #include #include -#include +#include #include "CompressibleConservativeVariables.h" @@ -23,8 +23,8 @@ namespace TNL { template< typename Mesh, typename BoundaryCondition, typename RightHandSide, - typename InviscidOperators, - typename Communicator > + typename Communicator, + typename InviscidOperators > class navierStokesProblem: public PDEProblem< Mesh, Communicator, @@ -38,12 +38,13 @@ class navierStokesProblem: typedef typename Mesh::DeviceType DeviceType; typedef typename InviscidOperators::IndexType IndexType; typedef PDEProblem< Mesh, Communicator, RealType, DeviceType, IndexType > BaseType; + + typedef Communicator CommunicatorType; using typename BaseType::MeshType; using typename BaseType::MeshPointer; using typename BaseType::DofVectorType; using typename BaseType::DofVectorPointer; - static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::MeshFunction< Mesh > MeshFunctionType; @@ -55,9 +56,8 @@ class navierStokesProblem: typedef Pointers::SharedPointer< InviscidOperators > InviscidOperatorsPointer; typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - using CommunicatorType = Communicator; - static String getTypeStatic(); + static String getType(); String getPrologHeader() const; @@ -85,12 +85,10 @@ class navierStokesProblem: const RealType& tau, DofVectorPointer& _u, DofVectorPointer& _fu ); + void applyBoundaryConditions( const RealType& time, - DofVectorPointer& dofs ) - { - throw Exceptions::NotImplementedError("TODO:Implement"); - } + DofVectorPointer& dofs ); template< typename Matrix > void assemblyLinearSystem( const RealType& time, @@ -112,6 +110,13 @@ class navierStokesProblem: ConservativeVariablesPointer conservativeVariables, conservativeVariablesRHS; + + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::ContinuityOperatorType, typename BoundaryCondition::DensityBoundaryConditionsType, RightHandSide > explicitUpdaterContinuity; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumXOperatorType, typename BoundaryCondition::MomentumXBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumX; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumYOperatorType, typename BoundaryCondition::MomentumYBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumY; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumZOperatorType, typename BoundaryCondition::MomentumZBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumZ; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::EnergyOperatorType, typename BoundaryCondition::EnergyBoundaryConditionsType, RightHandSide > explicitUpdaterEnergy; + VelocityFieldPointer velocity; MeshFunctionPointer pressure; @@ -119,7 +124,12 @@ class navierStokesProblem: RealType gamma; RealType speedIncrement; RealType cavitySpeed; - RealType speedIncrementUntil; + RealType speedIncrementUntil; + RealType finalSpeed; + RealType startSpeed; + RealType speedIncrementUntilHThrottle; + RealType finalSpeedHThrottle; + RealType startSpeedHThrottle; }; } // namespace TNL diff --git a/src/Examples/inviscid-flow/eulerProblem_impl.h b/src/Examples/flows/navierStokesProblem_impl.h similarity index 60% rename from src/Examples/inviscid-flow/eulerProblem_impl.h rename to src/Examples/flows/navierStokesProblem_impl.h index fd64ae2846e347bdadd878c0a3f4052fdbefc522..d07de0c200ed52e9771bb33ead5850ee265f0639 100644 --- a/src/Examples/inviscid-flow/eulerProblem_impl.h +++ b/src/Examples/flows/navierStokesProblem_impl.h @@ -1,5 +1,5 @@ /*************************************************************************** - eulerProblem_impl.h - description + navierStokesProblem_impl.h - description ------------------- begin : Feb 13, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -16,18 +16,11 @@ #include #include #include -#include #include "RiemannProblemInitialCondition.h" #include "CompressibleConservativeVariables.h" #include "PhysicalVariablesGetter.h" -#include "eulerProblem.h" - -#include "LaxFridrichsContinuity.h" -#include "LaxFridrichsEnergy.h" -#include "LaxFridrichsMomentumX.h" -#include "LaxFridrichsMomentumY.h" -#include "LaxFridrichsMomentumZ.h" +#include "navierStokesProblem.h" namespace TNL { @@ -37,10 +30,10 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: getType() { - return String( "eulerProblem< " ) + Mesh :: getType() + " >"; + return String( "navierStokesProblem< " ) + Mesh :: getType() + " >"; } template< typename Mesh, @@ -49,10 +42,10 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: getPrologHeader() const { - return String( "Inviscid flow solver" ); + return String( "flow solver" ); } template< typename Mesh, @@ -61,7 +54,7 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: writeProlog( Logger& logger, const Config::ParameterContainer& parameters ) const { /**** @@ -76,7 +69,7 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: setup( const Config::ParameterContainer& parameters, const String& prefix ) { @@ -85,8 +78,59 @@ setup( const Config::ParameterContainer& parameters, ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) return false; this->gamma = parameters.getParameter< double >( "gamma" ); + this->startSpeed = parameters.getParameter< double >( "start-speed" ); + this->finalSpeed = parameters.getParameter< double >( "final-speed" ); + this->speedIncrementUntil = parameters.getParameter< RealType >( "speed-increment-until" ); + this->startSpeedHThrottle = parameters.getParameter< double >( "start-speed-h-throttle" ); + this->finalSpeedHThrottle = parameters.getParameter< double >( "final-speed-h-throttle" ); + this->speedIncrementUntilHThrottle = parameters.getParameter< RealType >( "speed-increment-until-h-throttle" ); velocity->setMesh( this->getMesh() ); pressure->setMesh( this->getMesh() ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setVelocity( this->velocity ); + this->inviscidOperatorsPointer->setPressure( this->pressure ); + this->inviscidOperatorsPointer->setDensity( this->conservativeVariables->getDensity() ); + this->inviscidOperatorsPointer->setGamma( this->gamma ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); + this->explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer->getDensityBoundaryCondition() ); + this->explicitUpdaterContinuity.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumXOperator() ); + this->explicitUpdaterMomentumX.setBoundaryConditions( this->boundaryConditionPointer->getMomentumXBoundaryCondition() ); + this->explicitUpdaterMomentumX.setRightHandSide( this->rightHandSidePointer ); + + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumYOperator() ); + this->explicitUpdaterMomentumY.setBoundaryConditions( this->boundaryConditionPointer->getMomentumYBoundaryCondition() ); + this->explicitUpdaterMomentumY.setRightHandSide( this->rightHandSidePointer ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumZOperator() ); + this->explicitUpdaterMomentumZ.setBoundaryConditions( this->boundaryConditionPointer->getMomentumZBoundaryCondition() ); + this->explicitUpdaterMomentumZ.setRightHandSide( this->rightHandSidePointer ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getEnergyOperator() ); + this->explicitUpdaterEnergy.setBoundaryConditions( this->boundaryConditionPointer->getEnergyBoundaryCondition() ); + this->explicitUpdaterEnergy.setRightHandSide( this->rightHandSidePointer ); + return true; } @@ -95,8 +139,8 @@ template< typename Mesh, typename RightHandSide, typename Communicator, typename InviscidOperators > -typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >::IndexType -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +typename navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >::IndexType +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: getDofs() const { /**** @@ -112,7 +156,7 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: bindDofs( DofVectorPointer& dofVector ) { this->conservativeVariables->bind( this->getMesh(), dofVector ); @@ -124,13 +168,16 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: setInitialCondition( const Config::ParameterContainer& parameters, DofVectorPointer& dofs ) { CompressibleConservativeVariables< MeshType > conservativeVariables; conservativeVariables.bind( this->getMesh(), 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; @@ -150,7 +197,7 @@ template< typename Mesh, typename InviscidOperators > template< typename Matrix > bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: setupLinearSystem( Matrix& matrix ) { /* const IndexType dofs = this->getDofs(); @@ -175,7 +222,7 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: makeSnapshot( const RealType& time, const IndexType& step, DofVectorPointer& dofs ) @@ -191,17 +238,24 @@ makeSnapshot( const RealType& time, fileName.setExtension( "tnl" ); fileName.setIndex( step ); fileName.setFileNameBase( "density-" ); +// if( ! this->conservativeVariables->getDensity()->save( fileName.getFileName() ) ) this->conservativeVariables->getDensity()->save( fileName.getFileName() ); +// return false; fileName.setFileNameBase( "velocity-" ); +// if( ! this->velocity->save( fileName.getFileName() ) ) this->velocity->save( fileName.getFileName() ); +// return false; fileName.setFileNameBase( "pressure-" ); +// if( ! this->pressure->save( fileName.getFileName() ) ) this->pressure->save( fileName.getFileName() ); +// return false; fileName.setFileNameBase( "energy-" ); +// if( ! this->conservativeVariables->getEnergy()->save( fileName.getFileName() ) ) this->conservativeVariables->getEnergy()->save( fileName.getFileName() ); - +// return false; return true; } @@ -211,7 +265,7 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: getExplicitUpdate( const RealType& time, const RealType& tau, DofVectorPointer& _u, @@ -224,8 +278,6 @@ getExplicitUpdate( const RealType& time, */ this->conservativeVariables->bind( this->getMesh(), _u ); this->conservativeVariablesRHS->bind( this->getMesh(), _fu ); - this->velocity->setMesh( this->getMesh() ); - this->pressure->setMesh( this->getMesh() ); /**** * Resolve the physical variables @@ -233,73 +285,47 @@ getExplicitUpdate( const RealType& time, 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->setTau( tau ); - this->inviscidOperatorsPointer->setVelocity( this->velocity ); - this->inviscidOperatorsPointer->setPressure( this->pressure ); - /**** * Continuity equation */ - Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, ContinuityOperatorType, BoundaryCondition, RightHandSide > explicitUpdaterContinuity; - explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); - explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer ); - explicitUpdaterContinuity.setRightHandSide( this->rightHandSidePointer ); - explicitUpdaterContinuity.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->explicitUpdaterContinuity.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), this->conservativeVariables->getDensity(), this->conservativeVariablesRHS->getDensity() ); +// this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, +// this->conservativeVariables->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, Communicator >( time, tau, this->getMesh(), + */ + this->explicitUpdaterMomentumX.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), ( *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, Communicator >( time, tau, this->getMesh(), + { + this->explicitUpdaterMomentumY.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), ( *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, Communicator >( time, tau, this->getMesh(), + { + this->explicitUpdaterMomentumZ.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), ( *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, Communicator >( time, tau, this->getMesh(), + */ + this->explicitUpdaterEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), this->conservativeVariables->getEnergy(), // uRhoVelocityX, this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); @@ -316,13 +342,66 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: applyBoundaryConditions( const RealType& time, DofVectorPointer& dofs ) { - this->bindDofs( dofs ); - throw Exceptions::NotImplementedError( "TODO: implement BC ... see HeatEquationProblem" ); -} + /**** + * 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); + this->boundaryConditionPointer->setVerticalThrottleSpeed( startSpeed, finalSpeed, time, speedIncrementUntil ); + this->boundaryConditionPointer->setHorizontalThrottleSpeed( startSpeedHThrottle, finalSpeedHThrottle, time, speedIncrementUntilHThrottle ); + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), dofs ); +// this->conservativeVariables->getDensity()->write( "density", "gnuplot" ); +// this->conservativeVariables->getEnergy()->write( "energy", "gnuplot" ); +// this->conservativeVariables->getMomentum()->write( "momentum", "gnuplot", 0.05 ); +// dofs->save("dofs.tnl"); +// getchar(); +// std::cout <<"applyBCC" << std::endl; + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getDensity() ); + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 0 ] ); // uRhoVelocityX, + if( Dimensions > 1 ) + { + + this->explicitUpdaterMomentumY.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 1 ] ); // uRhoVelocityX, + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 2 ] ); // uRhoVelocityX, + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getEnergy() ); // uRhoVelocityX, +} template< typename Mesh, typename BoundaryCondition, @@ -331,7 +410,7 @@ template< typename Mesh, typename InviscidOperators > template< typename Matrix > void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: assemblyLinearSystem( const RealType& time, const RealType& tau, DofVectorPointer& _u, @@ -364,7 +443,7 @@ template< typename Mesh, typename Communicator, typename InviscidOperators > bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +navierStokesProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: postIterate( const RealType& time, const RealType& tau, DofVectorPointer& dofs ) diff --git a/src/Examples/flows/navierStokesStegerWarming.cpp b/src/Examples/flows/navierStokesStegerWarming.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bce6dd559cd759d177297478162da1a1d3ca23d2 --- /dev/null +++ b/src/Examples/flows/navierStokesStegerWarming.cpp @@ -0,0 +1 @@ +#include "navierStokesStegerWarming.h" diff --git a/src/Examples/flows/navierStokesStegerWarming.cu b/src/Examples/flows/navierStokesStegerWarming.cu new file mode 100644 index 0000000000000000000000000000000000000000..bce6dd559cd759d177297478162da1a1d3ca23d2 --- /dev/null +++ b/src/Examples/flows/navierStokesStegerWarming.cu @@ -0,0 +1 @@ +#include "navierStokesStegerWarming.h" diff --git a/src/Examples/flows/navierStokesStegerWarming.h b/src/Examples/flows/navierStokesStegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..f7a1df06a78c4665aa3cce6ca13544c20ad4db0e --- /dev/null +++ b/src/Examples/flows/navierStokesStegerWarming.h @@ -0,0 +1,189 @@ +//#include +#include +#include +#include +#include +#include +#include "navierStokesProblem.h" +#include "DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h" +#include "DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "operator-right-hand-side", "Choose equation type.", "Euler"); + config.addEntryEnum< String >( "Euler" ); + config.addEntryEnum< String >( "Navier-Stokes" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + StegerWarming< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class navierStokesSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + String operatorRightHandSideType = parameters.getParameter< String >( "operator-right-hand-side"); + if( operatorRightHandSideType == "Euler" ) + { + typedef NullOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( operatorRightHandSideType == "Navier-Stokes" ) + { + typedef NavierStokesOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, 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/src/Examples/flows/navierStokesVanLeer.cpp b/src/Examples/flows/navierStokesVanLeer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..968b16596ba782f222339af3fe963ec6b3fdcc32 --- /dev/null +++ b/src/Examples/flows/navierStokesVanLeer.cpp @@ -0,0 +1 @@ +#include "navierStokesVanLeer.h" diff --git a/src/Examples/flow-vl/navierStokes.cpp b/src/Examples/flows/navierStokesVanLeer.cu similarity index 100% rename from src/Examples/flow-vl/navierStokes.cpp rename to src/Examples/flows/navierStokesVanLeer.cu diff --git a/src/Examples/flows/navierStokesVanLeer.h b/src/Examples/flows/navierStokesVanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..ed6c73714e7f55874620f1fe1f352437a8ba7d35 --- /dev/null +++ b/src/Examples/flows/navierStokesVanLeer.h @@ -0,0 +1,189 @@ +//#include +#include +#include +#include +#include +#include +#include "navierStokesProblem.h" +#include "DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/NavierStokesRightHandSide/NavierStokesOperatorRightHandSide.h" +#include "DifferentialOperatorsRightHandSide/nullRightHandSide/nullOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "operator-right-hand-side", "Choose equation type.", "Euler"); + config.addEntryEnum< String >( "Euler" ); + config.addEntryEnum< String >( "Navier-Stokes" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + VanLeer< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class navierStokesSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + String operatorRightHandSideType = parameters.getParameter< String >( "operator-right-hand-side"); + if( operatorRightHandSideType == "Euler" ) + { + typedef NullOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( operatorRightHandSideType == "Navier-Stokes" ) + { + typedef NavierStokesOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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, CommunicatorType, 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, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef navierStokesProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, 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/src/Examples/flows/run-navier-stokes b/src/Examples/flows/run-navier-stokes new file mode 100644 index 0000000000000000000000000000000000000000..cd0c1bbb1426405814d32e2e1f3222e79bb11c8d --- /dev/null +++ b/src/Examples/flows/run-navier-stokes @@ -0,0 +1,40 @@ +#!/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-euler-navier-stokes + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --differential-operator Steger-Warming \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/flows/run-navier-stokes-AUSM-plus b/src/Examples/flows/run-navier-stokes-AUSM-plus new file mode 100644 index 0000000000000000000000000000000000000000..faaad26b48f1fbea1002c066b6bfce61e323b7e7 --- /dev/null +++ b/src/Examples/flows/run-navier-stokes-AUSM-plus @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Ausm-Plus + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/flows/run-navier-stokes-Lax-Friedrichs b/src/Examples/flows/run-navier-stokes-Lax-Friedrichs new file mode 100644 index 0000000000000000000000000000000000000000..5f7bfbdc6d6e7ebe6dd69663eeea28a5c6dc770f --- /dev/null +++ b/src/Examples/flows/run-navier-stokes-Lax-Friedrichs @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Lax-Friedrichs + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/flows/run-navier-stokes-Steger-Warming b/src/Examples/flows/run-navier-stokes-Steger-Warming new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/flows/run-navier-stokes-Steger-Warming @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/flows/run-navier-stokes-Van-Leer b/src/Examples/flows/run-navier-stokes-Van-Leer new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/flows/run-navier-stokes-Van-Leer @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/inviscid-flow-sw/CMakeLists.txt b/src/Examples/inviscid-flow-sw/CMakeLists.txt deleted file mode 100644 index 427def1267f5e5e8f67c803bd0ca217c6246d202..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -set( tnl_inviscid_flow_sw_HEADERS - CompressibleConservativeVariables.h ) - -set( tnl_inviscid_flow_sw_SOURCES - euler.cpp - euler.cu ) - -IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE(tnl-euler-sw euler.cu) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE(tnl-euler-sw${debugExt} euler.cpp) -ENDIF( BUILD_CUDA ) - - -INSTALL( TARGETS tnl-euler-sw - RUNTIME DESTINATION bin - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) - -INSTALL( FILES run-euler-sw - ${tnl_inviscid_flow_SOURCES} - DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/inviscid-flow-sw ) diff --git a/src/Examples/inviscid-flow-sw/LaxFridrichs.h b/src/Examples/inviscid-flow-sw/LaxFridrichs.h deleted file mode 100644 index c56d20aed9947bd16796a5bf7ceb22adb237bf0c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/LaxFridrichs.h +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - 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 -#include -#include - -#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; - typedef Pointers::SharedPointer< MeshType > MeshPointer; - - typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; - typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; - typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; - typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; - typedef Pointers::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/src/Examples/inviscid-flow-sw/LaxFridrichsContinuity.h b/src/Examples/inviscid-flow-sw/LaxFridrichsContinuity.h deleted file mode 100644 index 82747cd18220efc01bc2d68e0247c01723c29fd0..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/LaxFridrichsContinuity.h +++ /dev/null @@ -1,288 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow-sw/PhysicalVariablesGetter.h b/src/Examples/inviscid-flow-sw/PhysicalVariablesGetter.h deleted file mode 100644 index d7eeb7618657c34485b3e4842ea04e12d3ee725c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/PhysicalVariablesGetter.h +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; - typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; - typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; - typedef Pointers::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 = lpNorm( momentum.template getData< DeviceType >().getVector( meshEntity ), 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++ ) - { - Pointers::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; - Pointers::SharedPointer< PressureGetter, DeviceType > pressureGetter( conservativeVariables->getDensity(), - conservativeVariables->getEnergy(), - conservativeVariables->getMomentum(), - gamma ); - evaluator.evaluate( pressure, pressureGetter ); - } - -}; - -} //namespace TNL diff --git a/src/Examples/inviscid-flow-sw/euler.cpp b/src/Examples/inviscid-flow-sw/euler.cpp deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/euler.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow-sw/euler.cu b/src/Examples/inviscid-flow-sw/euler.cu deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/euler.cu +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow-sw/euler.h b/src/Examples/inviscid-flow-sw/euler.h deleted file mode 100644 index 75279e605d9afa4d25531e7e63a91e33424c2c9f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/euler.h +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include -#include "eulerProblem.h" -#include "Upwind.h" -#include "eulerRhs.h" -#include "eulerBuildConfigTag.h" - -#include "RiemannProblemInitialCondition.h" - -using namespace TNL; - -typedef eulerBuildConfigTag 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 eulerConfig -{ - public: - static void configSetup( Config::ConfigDescription & config ) - { - config.addDelimiter( "Inviscid flow settings:" ); - config.addEntry< String >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); - config.addEntryEnum< String >( "dirichlet" ); - config.addEntryEnum< String >( "neumann" ); - config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); - typedef Meshes::Grid< 3 > Mesh; - 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, - typename Communicator > -class eulerSetter -{ - 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 eulerRhs< MeshType, Real > RightHandSide; - typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; - - /**** - * Resolve the template arguments of your solver here. - * The following code is for the Dirichlet and the Neumann boundary conditions. - * Both can be constant or defined as descrete values of Vector. - */ - String boundaryConditionsType = parameters.getParameter< String >( "boundary-conditions-type" ); - if( parameters.checkParameter( "boundary-conditions-constant" ) ) - { - typedef Functions::Analytic::Constant< Dimension, Real > Constant; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator, Communicator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - typedef Operators::NeumannBoundaryConditions< MeshType, Constant, Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator, Communicator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - typedef Functions::MeshFunction< MeshType > MeshFunction; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator, Communicator > 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, Communicator > 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/src/Examples/inviscid-flow-sw/eulerBuildConfigTag.h b/src/Examples/inviscid-flow-sw/eulerBuildConfigTag.h deleted file mode 100644 index da06124626c8f26dbaa8724f2198645571e986e1..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/eulerBuildConfigTag.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include - -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 }; }; - -/**** - * 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, ExplicitEulerSolverTag >{ enum { enabled = true }; }; - -} // namespace Solvers - -namespace Meshes { -namespace BuildConfigTags { - -template< int Dimensions > struct GridDimensionTag< eulerBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 1 ) }; }; - -/**** - * Turn off support for float and long double. - */ -template<> struct GridRealTag< eulerBuildConfigTag, float > { enum { enabled = false }; }; -template<> struct GridRealTag< eulerBuildConfigTag, long double > { enum { enabled = false }; }; - -/**** - * Turn off support for short int and long int indexing. - */ -template<> struct GridIndexTag< eulerBuildConfigTag, short int >{ enum { enabled = false }; }; -template<> struct GridIndexTag< eulerBuildConfigTag, long int >{ enum { enabled = false }; }; - -} // namespace BuildConfigTags -} // namespace Meshes -} // namespace TNL diff --git a/src/Examples/inviscid-flow-sw/eulerProblem_impl.h b/src/Examples/inviscid-flow-sw/eulerProblem_impl.h deleted file mode 100644 index e0382e9c2485bbec5740df99af47b87a28122139..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/eulerProblem_impl.h +++ /dev/null @@ -1,428 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include -#include - -#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, - typename Communicator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getTypeStatic() -{ - return String( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getPrologHeader() const -{ - return String( "Inviscid flow solver" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -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, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || - ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - this->gamma = parameters.getParameter< double >( "gamma" ); - velocity->setMesh( this->getMesh() ); - pressure->setMesh( this->getMesh() ); - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >::IndexType -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getDofs() const -{ - /**** - * Return number of DOFs (degrees of freedom) i.e. number - * of unknowns to be resolved by the main solver. - */ - return this->conservativeVariables->getDofs( this->getMesh() ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -bindDofs( DofVectorPointer& dofVector ) -{ - this->conservativeVariables->bind( this->getMesh(), dofVector ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - DofVectorPointer& dofs ) -{ - CompressibleConservativeVariables< MeshType > conservativeVariables; - conservativeVariables.bind( this->getMesh(), 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, - typename Communicator > - template< typename Matrix > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setupLinearSystem( 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, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -makeSnapshot( const RealType& time, - const IndexType& step, - DofVectorPointer& dofs ) -{ - std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; - - this->bindDofs( 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-" ); - this->conservativeVariables->getDensity()->save( fileName.getFileName() ); - - fileName.setFileNameBase( "velocity-" ); - this->velocity->save( fileName.getFileName() ); - - fileName.setFileNameBase( "pressure-" ); - this->pressure->save( fileName.getFileName() ); - - fileName.setFileNameBase( "energy-" ); - this->conservativeVariables->getEnergy()->save( fileName.getFileName() ); - - fileName.setFileNameBase( "momentum-" ); - this->conservativeVariables->getMomentum()->save( fileName.getFileName() ); - - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getExplicitUpdate( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - DofVectorPointer& _fu ) -{ - typedef typename MeshType::Cell Cell; - const MeshPointer& mesh = this->getMesh(); - - /**** - * 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, - typename Communicator > - template< typename Matrix > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b ) -{ -/* 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, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -postIterate( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs ) -{ - /* - 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/src/Examples/inviscid-flow-sw/run-euler-sw b/src/Examples/inviscid-flow-sw/run-euler-sw deleted file mode 100644 index 9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-sw/run-euler-sw +++ /dev/null @@ -1,25 +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 -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/src/Examples/inviscid-flow-vl/CMakeLists.txt b/src/Examples/inviscid-flow-vl/CMakeLists.txt deleted file mode 100644 index d0111a5a130efc93dc357300700cfade296835fc..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -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 euler.cu) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE(tnl-euler-vl euler.cpp) -ENDIF( BUILD_CUDA ) - - -INSTALL( TARGETS tnl-euler-vl - 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 ${TNL_TARGET_DATA_DIRECTORY}/examples/inviscid-flow-vl ) diff --git a/src/Examples/inviscid-flow-vl/CompressibleConservativeVariables.h b/src/Examples/inviscid-flow-vl/CompressibleConservativeVariables.h deleted file mode 100644 index 01e820686e98781a3267c4526e8e7c6449218415..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/CompressibleConservativeVariables.h +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************** - 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 -#include -#include - -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 Pointers::SharedPointer< MeshType > MeshPointer; - typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::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 diff --git a/src/Examples/inviscid-flow-vl/LaxFridrichs.h b/src/Examples/inviscid-flow-vl/LaxFridrichs.h deleted file mode 100644 index c56d20aed9947bd16796a5bf7ceb22adb237bf0c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/LaxFridrichs.h +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - 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 -#include -#include - -#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; - typedef Pointers::SharedPointer< MeshType > MeshPointer; - - typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; - typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; - typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; - typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; - typedef Pointers::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/src/Examples/inviscid-flow-vl/LaxFridrichsContinuity.h b/src/Examples/inviscid-flow-vl/LaxFridrichsContinuity.h deleted file mode 100644 index 82747cd18220efc01bc2d68e0247c01723c29fd0..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/LaxFridrichsContinuity.h +++ /dev/null @@ -1,288 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow-vl/LaxFridrichsEnergy.h b/src/Examples/inviscid-flow-vl/LaxFridrichsEnergy.h deleted file mode 100644 index 03019ed23c85f82ee489c95d8173c0f100cff3c8..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/LaxFridrichsEnergy.h +++ /dev/null @@ -1,309 +0,0 @@ -/*************************************************************************** - 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 -#include - -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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::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/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumBase.h b/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumBase.h deleted file mode 100644 index cc2561748968a2bd808fa434d4f3d87d41765f45..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumBase.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::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/src/Examples/inviscid-flow-vl/PhysicalVariablesGetter.h b/src/Examples/inviscid-flow-vl/PhysicalVariablesGetter.h deleted file mode 100644 index d7eeb7618657c34485b3e4842ea04e12d3ee725c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/PhysicalVariablesGetter.h +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; - typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; - typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; - typedef Pointers::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 = lpNorm( momentum.template getData< DeviceType >().getVector( meshEntity ), 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++ ) - { - Pointers::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; - Pointers::SharedPointer< PressureGetter, DeviceType > pressureGetter( conservativeVariables->getDensity(), - conservativeVariables->getEnergy(), - conservativeVariables->getMomentum(), - gamma ); - evaluator.evaluate( pressure, pressureGetter ); - } - -}; - -} //namespace TNL diff --git a/src/Examples/inviscid-flow-vl/RiemannProblemInitialCondition.h b/src/Examples/inviscid-flow-vl/RiemannProblemInitialCondition.h deleted file mode 100644 index b8e53d60178f44111018dcc67fe5e244eda942d5..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/RiemannProblemInitialCondition.h +++ /dev/null @@ -1,1417 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include -#include "CompressibleConservativeVariables.h" - -namespace TNL { -template -class RiemannProblemInitialConditionSetter -{ - -}; - -template -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 Pointers::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 -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 Pointers::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 -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 Pointers::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 Pointers::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* variablesSetter = new RiemannProblemInitialConditionSetter; - 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 Pointers::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/src/Examples/inviscid-flow-vl/euler.cpp b/src/Examples/inviscid-flow-vl/euler.cpp deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/euler.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow-vl/euler.cu b/src/Examples/inviscid-flow-vl/euler.cu deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/euler.cu +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow-vl/euler.h b/src/Examples/inviscid-flow-vl/euler.h deleted file mode 100644 index 75279e605d9afa4d25531e7e63a91e33424c2c9f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/euler.h +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include -#include "eulerProblem.h" -#include "Upwind.h" -#include "eulerRhs.h" -#include "eulerBuildConfigTag.h" - -#include "RiemannProblemInitialCondition.h" - -using namespace TNL; - -typedef eulerBuildConfigTag 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 eulerConfig -{ - public: - static void configSetup( Config::ConfigDescription & config ) - { - config.addDelimiter( "Inviscid flow settings:" ); - config.addEntry< String >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); - config.addEntryEnum< String >( "dirichlet" ); - config.addEntryEnum< String >( "neumann" ); - config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); - typedef Meshes::Grid< 3 > Mesh; - 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, - typename Communicator > -class eulerSetter -{ - 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 eulerRhs< MeshType, Real > RightHandSide; - typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; - - /**** - * Resolve the template arguments of your solver here. - * The following code is for the Dirichlet and the Neumann boundary conditions. - * Both can be constant or defined as descrete values of Vector. - */ - String boundaryConditionsType = parameters.getParameter< String >( "boundary-conditions-type" ); - if( parameters.checkParameter( "boundary-conditions-constant" ) ) - { - typedef Functions::Analytic::Constant< Dimension, Real > Constant; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator, Communicator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - typedef Operators::NeumannBoundaryConditions< MeshType, Constant, Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator, Communicator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - typedef Functions::MeshFunction< MeshType > MeshFunction; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator, Communicator > 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, Communicator > 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/src/Examples/inviscid-flow-vl/eulerBuildConfigTag.h b/src/Examples/inviscid-flow-vl/eulerBuildConfigTag.h deleted file mode 100644 index 4b5d7d63882f274b68b08ff131b693d0a3643108..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/eulerBuildConfigTag.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include - -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 }; }; - -/**** - * 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, ExplicitEulerSolverTag >{ enum { enabled = true }; }; - -} // namespace Solvers - -namespace Meshes { -namespace BuildConfigTags { - -template< int Dimensions > struct GridDimensionTag< eulerBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 1 ) }; }; - -/**** - * Turn off support for float and long double. - */ -template<> struct GridRealTag< eulerBuildConfigTag, float > { enum { enabled = false }; }; -template<> struct GridRealTag< eulerBuildConfigTag, long double > { enum { enabled = false }; }; - -/**** - * Turn off support for short int and long int indexing. - */ -template<> struct GridIndexTag< eulerBuildConfigTag, short int >{ enum { enabled = false }; }; -template<> struct GridIndexTag< eulerBuildConfigTag, long int >{ enum { enabled = false }; }; - -} // namespace BuildConfigTags -} // namespace Meshes -} // namespace TNL \ No newline at end of file diff --git a/src/Examples/inviscid-flow-vl/eulerProblem.h b/src/Examples/inviscid-flow-vl/eulerProblem.h deleted file mode 100644 index a91e56176dbe8e5b507a61a8d27aaa5050855693..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/eulerProblem.h +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include "CompressibleConservativeVariables.h" - - -using namespace TNL::Problems; - -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -class eulerProblem: - public PDEProblem< Mesh, - Communicator, - typename InviscidOperators::RealType, - typename Mesh::DeviceType, - typename InviscidOperators::IndexType > -{ - public: - - typedef typename InviscidOperators::RealType RealType; - typedef typename Mesh::DeviceType DeviceType; - typedef typename InviscidOperators::IndexType IndexType; - typedef PDEProblem< Mesh, Communicator, RealType, DeviceType, IndexType > BaseType; - - using typename BaseType::MeshType; - using typename BaseType::MeshPointer; - using typename BaseType::DofVectorType; - using typename BaseType::DofVectorPointer; - - static const int Dimensions = Mesh::getMeshDimension(); - - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; - typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; - typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; - typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; - typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; - typedef Pointers::SharedPointer< InviscidOperators > InviscidOperatorsPointer; - typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; - typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - using CommunicatorType = Communicator; - - static String getTypeStatic(); - - String getPrologHeader() const; - - void writeProlog( Logger& logger, - const Config::ParameterContainer& parameters ) const; - - bool setup( const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - bool setInitialCondition( const Config::ParameterContainer& parameters, - DofVectorPointer& dofs ); - - template< typename Matrix > - bool setupLinearSystem( Matrix& matrix ); - - bool makeSnapshot( const RealType& time, - const IndexType& step, - DofVectorPointer& dofs ); - - IndexType getDofs() const; - - void bindDofs( DofVectorPointer& dofs ); - - void getExplicitUpdate( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - DofVectorPointer& _fu ); - - void applyBoundaryConditions( const RealType& time, - DofVectorPointer& dofs ) - { - throw Exceptions::NotImplementedError( "TODO: implement BC ... see HeatEquationProblem" ); - } - - template< typename Matrix > - void assemblyLinearSystem( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs, - Matrix& matrix, - DofVectorPointer& rightHandSide ); - - bool postIterate( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs ); - - protected: - - InviscidOperatorsPointer inviscidOperatorsPointer; - - BoundaryConditionPointer boundaryConditionPointer; - RightHandSidePointer rightHandSidePointer; - - ConservativeVariablesPointer conservativeVariables, - conservativeVariablesRHS; - - VelocityFieldPointer velocity; - MeshFunctionPointer pressure; - - RealType gamma; -}; - -} // namespace TNL - -#include "eulerProblem_impl.h" - diff --git a/src/Examples/inviscid-flow-vl/eulerProblem_impl.h b/src/Examples/inviscid-flow-vl/eulerProblem_impl.h deleted file mode 100644 index e0382e9c2485bbec5740df99af47b87a28122139..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/eulerProblem_impl.h +++ /dev/null @@ -1,428 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include -#include - -#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, - typename Communicator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getTypeStatic() -{ - return String( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >"; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -String -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getPrologHeader() const -{ - return String( "Inviscid flow solver" ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -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, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || - ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || - ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) - return false; - this->gamma = parameters.getParameter< double >( "gamma" ); - velocity->setMesh( this->getMesh() ); - pressure->setMesh( this->getMesh() ); - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >::IndexType -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getDofs() const -{ - /**** - * Return number of DOFs (degrees of freedom) i.e. number - * of unknowns to be resolved by the main solver. - */ - return this->conservativeVariables->getDofs( this->getMesh() ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -bindDofs( DofVectorPointer& dofVector ) -{ - this->conservativeVariables->bind( this->getMesh(), dofVector ); -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setInitialCondition( const Config::ParameterContainer& parameters, - DofVectorPointer& dofs ) -{ - CompressibleConservativeVariables< MeshType > conservativeVariables; - conservativeVariables.bind( this->getMesh(), 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, - typename Communicator > - template< typename Matrix > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -setupLinearSystem( 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, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -makeSnapshot( const RealType& time, - const IndexType& step, - DofVectorPointer& dofs ) -{ - std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; - - this->bindDofs( 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-" ); - this->conservativeVariables->getDensity()->save( fileName.getFileName() ); - - fileName.setFileNameBase( "velocity-" ); - this->velocity->save( fileName.getFileName() ); - - fileName.setFileNameBase( "pressure-" ); - this->pressure->save( fileName.getFileName() ); - - fileName.setFileNameBase( "energy-" ); - this->conservativeVariables->getEnergy()->save( fileName.getFileName() ); - - fileName.setFileNameBase( "momentum-" ); - this->conservativeVariables->getMomentum()->save( fileName.getFileName() ); - - return true; -} - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename InviscidOperators, - typename Communicator > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -getExplicitUpdate( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - DofVectorPointer& _fu ) -{ - typedef typename MeshType::Cell Cell; - const MeshPointer& mesh = this->getMesh(); - - /**** - * 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, CommunicatorType >( - 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, - typename Communicator > - template< typename Matrix > -void -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -assemblyLinearSystem( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - Matrix& matrix, - DofVectorPointer& b ) -{ -/* 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, - typename Communicator > -bool -eulerProblem< Mesh, BoundaryCondition, RightHandSide, InviscidOperators, Communicator >:: -postIterate( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs ) -{ - /* - 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/src/Examples/inviscid-flow-vl/run-euler-vl b/src/Examples/inviscid-flow-vl/run-euler-vl deleted file mode 100644 index 9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow-vl/run-euler-vl +++ /dev/null @@ -1,25 +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 -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/src/Examples/inviscid-flow/1d/MyMixedBoundaryConditions.h b/src/Examples/inviscid-flow/1d/MyMixedBoundaryConditions.h deleted file mode 100644 index 218805fa13a57b66acc38d4d264a196b001fb3f7..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow/1d/MyNeumannBoundaryConditions.h b/src/Examples/inviscid-flow/1d/MyNeumannBoundaryConditions.h deleted file mode 100644 index 204be5a3fd4a85dae693fa97354fd2f02e429660..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow/1d/tnl-run-euler-1d b/src/Examples/inviscid-flow/1d/tnl-run-euler-1d deleted file mode 100644 index 4829c27d0e0abfd000ce44e15687a8e85470ba0e..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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/src/Examples/inviscid-flow/2d/Euler2DVelXGetter.h b/src/Examples/inviscid-flow/2d/Euler2DVelXGetter.h deleted file mode 100644 index 2e79798a31a7073241903891d0317502c8494a60..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/2d/Euler2DVelXGetter.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef EulerVelXGetter_H -#define EulerVelXGetter_H - -#include -#include - -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/src/Examples/inviscid-flow/2d/MyMixedBoundaryConditions.h b/src/Examples/inviscid-flow/2d/MyMixedBoundaryConditions.h deleted file mode 100644 index dbcd6b5d21834919a5d2ef25245dd82786d656e2..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow/2d/MyNeumannBoundaryConditions.h b/src/Examples/inviscid-flow/2d/MyNeumannBoundaryConditions.h deleted file mode 100644 index 1db632bf5a7a1c1519f5b6c31a16719139bdd555..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow/2d/tnl-run-euler-2d b/src/Examples/inviscid-flow/2d/tnl-run-euler-2d deleted file mode 100644 index 463dd3506a739fb8239abcf8d544dc0ac94610bd..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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/src/Examples/inviscid-flow/3d/CMakeLists.txt b/src/Examples/inviscid-flow/3d/CMakeLists.txt deleted file mode 100644 index 41096a73a7a5070d15e56d2da7111cbbf85ebf2d..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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/src/Examples/inviscid-flow/3d/Euler2DVelXGetter.h b/src/Examples/inviscid-flow/3d/Euler2DVelXGetter.h deleted file mode 100644 index 2e79798a31a7073241903891d0317502c8494a60..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/Euler2DVelXGetter.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef EulerVelXGetter_H -#define EulerVelXGetter_H - -#include -#include - -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/src/Examples/inviscid-flow/3d/EulerPressureGetter.h b/src/Examples/inviscid-flow/3d/EulerPressureGetter.h deleted file mode 100644 index 45611c64754aa161274bdabe95cd0c60565ef2c1..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/EulerPressureGetter.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef EulerPressureGetter_H -#define EulerPressureGetter_H - -#include -#include -#include - -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/src/Examples/inviscid-flow/3d/EulerVelGetter.h b/src/Examples/inviscid-flow/3d/EulerVelGetter.h deleted file mode 100644 index 24d06eaf5f0ce322c17086ea2cf04495c96bd3e7..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/EulerVelGetter.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef EulerVelGetter_H -#define EulerVelGetter_H - -#include -#include - -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/src/Examples/inviscid-flow/3d/LaxFridrichs3D.h b/src/Examples/inviscid-flow/3d/LaxFridrichs3D.h deleted file mode 100644 index 57c9fe6b4e676a0fe2c352823be5b1c1b26cd71e..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/LaxFridrichs3D.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef LaxFridrichs3D_H -#define LaxFridrichs3D_H - -#include -#include -#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/src/Examples/inviscid-flow/3d/LaxFridrichsContinuity_impl .h b/src/Examples/inviscid-flow/3d/LaxFridrichsContinuity_impl .h deleted file mode 100644 index ac469a52407477aab2d8a60c3eca92e5d168a253..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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/src/Examples/inviscid-flow/3d/LaxFridrichsEnergy.h b/src/Examples/inviscid-flow/3d/LaxFridrichsEnergy.h deleted file mode 100644 index 9083970ae4bb036b2be46e8556dab2e4f8eb2607..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/LaxFridrichsEnergy.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef LaxFridrichsEnergy_H -#define LaxFridrichsEnergy_H - -#include -#include - -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/src/Examples/inviscid-flow/3d/LaxFridrichsMomentumX.h b/src/Examples/inviscid-flow/3d/LaxFridrichsMomentumX.h deleted file mode 100644 index 5d1cf919252d85f00f08657e7e2944402940615a..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/LaxFridrichsMomentumX.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef LaxFridrichsMomentumX_H -#define LaxFridrichsMomentumX_H - -#include -#include - -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/src/Examples/inviscid-flow/3d/LaxFridrichsMomentumZ.h b/src/Examples/inviscid-flow/3d/LaxFridrichsMomentumZ.h deleted file mode 100644 index 0d7882f6deaf9d5009775ffa2c9a1ca57d4261db..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/LaxFridrichsMomentumZ.h +++ /dev/null @@ -1,236 +0,0 @@ -#ifndef LaxFridrichsMomentumZ_H -#define LaxFridrichsMomentumZ_H - -#include -#include - -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/src/Examples/inviscid-flow/3d/MyMixedBoundaryConditions.h b/src/Examples/inviscid-flow/3d/MyMixedBoundaryConditions.h deleted file mode 100644 index dbcd6b5d21834919a5d2ef25245dd82786d656e2..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow/3d/MyNeumannBoundaryConditions.h b/src/Examples/inviscid-flow/3d/MyNeumannBoundaryConditions.h deleted file mode 100644 index d56b8210f14a40ea69cf92bd3bf19287be61d7d9..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow/3d/euler-cuda.cu b/src/Examples/inviscid-flow/3d/euler-cuda.cu deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/euler-cuda.cu +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow/3d/euler.cpp b/src/Examples/inviscid-flow/3d/euler.cpp deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/euler.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow/3d/euler.h b/src/Examples/inviscid-flow/3d/euler.h deleted file mode 100644 index 3160fe898bfdb2c37fa451ff19090e99b6f46dcb..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/euler.h +++ /dev/null @@ -1,169 +0,0 @@ -#include -#include -#include -#include -#include -#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/src/Examples/inviscid-flow/3d/eulerBuildConfigTag.h b/src/Examples/inviscid-flow/3d/eulerBuildConfigTag.h deleted file mode 100644 index b3727450de5e7030b04bed15f31bfd5ab8a6fbe9..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/eulerBuildConfigTag.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef eulerBUILDCONFIGTAG_H_ -#define eulerBUILDCONFIGTAG_H_ - -#include - -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, ExplicitEulerSolverTag >{ enum { enabled = true }; }; - -} // namespace Solvers -} // namespace TNL - - -#endif /* eulerBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/inviscid-flow/3d/eulerProblem.h b/src/Examples/inviscid-flow/3d/eulerProblem.h deleted file mode 100644 index d2ff1fc109c6d548ac503d82e398aa7c5b19c066..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/eulerProblem.h +++ /dev/null @@ -1,119 +0,0 @@ -#pragma once - -#include -#include - -using namespace TNL::Problems; - -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename DifferentialOperator > -class eulerProblem: - public PDEProblem< Mesh, - typename DifferentialOperator::RealType, - typename Mesh::DeviceType, - typename DifferentialOperator::IndexType > -{ - public: - - typedef typename DifferentialOperator::RealType RealType; - typedef typename Mesh::DeviceType DeviceType; - typedef typename DifferentialOperator::IndexType IndexType; - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; - typedef Pointers::SharedPointer< DifferentialOperator > DifferentialOperatorPointer; - typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; - typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - typedef PDEProblem< Mesh, RealType, DeviceType, IndexType > BaseType; - - using typename BaseType::MeshType; - using typename BaseType::MeshPointer; - using typename BaseType::DofVectorType; - using typename BaseType::DofVectorPointer; - using typename BaseType::MeshDependentDataType; - using typename BaseType::MeshDependentDataPointer; - - 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 String getTypeStatic(); - - String getPrologHeader() const; - - void writeProlog( Logger& logger, - const Config::ParameterContainer& parameters ) const; - - bool setup( const MeshPointer& meshPointer, - const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - bool setInitialCondition( const Config::ParameterContainer& parameters, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ); - - template< typename Matrix > - bool setupLinearSystem( const MeshPointer& mesh, - Matrix& matrix ); - - bool makeSnapshot( const RealType& time, - const IndexType& step, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ); - - IndexType getDofs( const MeshPointer& mesh ) const; - - void bindDofs( const MeshPointer& mesh, - DofVectorPointer& dofs ); - - void getExplicitRHS( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& _u, - DofVectorPointer& _fu, - MeshDependentDataPointer& meshDependentData ); - - template< typename Matrix > - void assemblyLinearSystem( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& dofs, - Matrix& matrix, - DofVectorPointer& rightHandSide, - MeshDependentDataPointer& meshDependentData ); - - bool postIterate( const RealType& time, - const RealType& tau, - const MeshPointer& mesh, - DofVectorPointer& dofs, - MeshDependentDataPointer& meshDependentData ); - - protected: - - DifferentialOperatorPointer differentialOperatorPointer; - BoundaryConditionPointer boundaryConditionPointer; - RightHandSidePointer rightHandSidePointer; - - MeshFunctionPointer uRho, uRhoVelocityX, uRhoVelocityY, uRhoVelocityZ, uEnergy; - MeshFunctionPointer fuRho, fuRhoVelocityX, fuRhoVelocityY, fuRhoVelocityZ, fuEnergy; - - MeshFunctionPointer pressure, velocity, velocityX, velocityY, velocityZ; - - RealType gamma; - -}; - -} // namespace TNL - -#include "eulerProblem_impl.h" - diff --git a/src/Examples/inviscid-flow/3d/eulerProblem_impl.h b/src/Examples/inviscid-flow/3d/eulerProblem_impl.h deleted file mode 100644 index b01979b87c6218f6e0ff1018caa8f05467bdfd1c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/eulerProblem_impl.h +++ /dev/null @@ -1,579 +0,0 @@ -#include -#include -#include -#include -#include -#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/src/Examples/inviscid-flow/3d/eulerRhs.h b/src/Examples/inviscid-flow/3d/eulerRhs.h deleted file mode 100644 index 1b46dc831fe9daa6133ff32ee4bea5faf4eb8d1c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/3d/eulerRhs.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef eulerRHS_H_ -#define eulerRHS_H_ - -#include - -namespace TNL { - -template< typename Mesh, typename Real >class eulerRhs - : public Functions::Domain< Mesh::meshDimensions, 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::VertexType VertexType; - VertexType v = entity.getCenter(); - return 0.0; - } -}; - -} //namespace TNL - -#endif /* eulerRHS_H_ */ diff --git a/src/Examples/inviscid-flow/3d/run-euler b/src/Examples/inviscid-flow/3d/run-euler deleted file mode 100644 index f68b98a8406dea2f2142526283ec60248551c56d..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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/src/Examples/inviscid-flow/3d/tnl-run-euler-2d b/src/Examples/inviscid-flow/3d/tnl-run-euler-2d deleted file mode 100644 index 5af33a1a7943e44d0037deff948b4ecfdafedde8..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/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/src/Examples/inviscid-flow/CMakeLists.txt b/src/Examples/inviscid-flow/CMakeLists.txt deleted file mode 100644 index dbfe2024d4cf6c8639593e754ca40c884f7604b3..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -set( tnl_inviscid_flow_HEADERS - CompressibleConservativeVariables.h ) - -set( tnl_inviscid_flow_SOURCES - euler.cpp - euler.cu ) - -IF( BUILD_CUDA ) - CUDA_ADD_EXECUTABLE(tnl-euler euler.cu) - target_link_libraries (tnl-euler ${CUSPARSE_LIBRARY} ) -ELSE( BUILD_CUDA ) - ADD_EXECUTABLE(tnl-euler euler.cpp) -ENDIF( BUILD_CUDA ) - - -INSTALL( TARGETS tnl-euler - RUNTIME DESTINATION bin - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) - -INSTALL( FILES run-euler - ${tnl_inviscid_flow_SOURCES} - DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/inviscid-flow ) - diff --git a/src/Examples/inviscid-flow/CompressibleConservativeVariables.h b/src/Examples/inviscid-flow/CompressibleConservativeVariables.h deleted file mode 100644 index ca77bb281ffef853a96172e9da57749247b4a456..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/CompressibleConservativeVariables.h +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************** - 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 -#include -#include - -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 Pointers::SharedPointer< MeshType > MeshPointer; - typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::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/src/Examples/inviscid-flow/LaxFridrichs.h b/src/Examples/inviscid-flow/LaxFridrichs.h deleted file mode 100644 index 1a648234a89be3f4e391cce6d7317a64a3114b33..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/LaxFridrichs.h +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - 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 -#include -#include - -#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; - typedef Pointers::SharedPointer< MeshType > MeshPointer; - - typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; - typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; - typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; - typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; - typedef Pointers::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/src/Examples/inviscid-flow/LaxFridrichsContinuity.h b/src/Examples/inviscid-flow/LaxFridrichsContinuity.h deleted file mode 100644 index 0ae10b4f9399fc41c97d5ad35fba4748f98bef95..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/LaxFridrichsContinuity.h +++ /dev/null @@ -1,288 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include - -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 Pointers::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/src/Examples/inviscid-flow/LaxFridrichsEnergy.h b/src/Examples/inviscid-flow/LaxFridrichsEnergy.h deleted file mode 100644 index 8c6791cd17516d877a206adff346900fc80d2462..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/LaxFridrichsEnergy.h +++ /dev/null @@ -1,309 +0,0 @@ -/*************************************************************************** - 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 -#include - -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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::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/src/Examples/inviscid-flow/LaxFridrichsMomentumBase.h b/src/Examples/inviscid-flow/LaxFridrichsMomentumBase.h deleted file mode 100644 index 96488da1a8acc65b6c7a07f04fc0f835bba5282f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/LaxFridrichsMomentumBase.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef Pointers::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/src/Examples/inviscid-flow/LaxFridrichsMomentumX.h b/src/Examples/inviscid-flow/LaxFridrichsMomentumX.h deleted file mode 100644 index 63def12d315188b82e82402635fca863d1b9a629..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/LaxFridrichsMomentumX.h +++ /dev/null @@ -1,276 +0,0 @@ -/*************************************************************************** - 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 -#include -#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/src/Examples/inviscid-flow/LaxFridrichsMomentumY.h b/src/Examples/inviscid-flow/LaxFridrichsMomentumY.h deleted file mode 100644 index 8ce42282dd4c74d5ed72d2abbd661235b95dc160..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/LaxFridrichsMomentumY.h +++ /dev/null @@ -1,260 +0,0 @@ -/*************************************************************************** - 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 -#include -#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/src/Examples/inviscid-flow/LaxFridrichsMomentumZ.h b/src/Examples/inviscid-flow/LaxFridrichsMomentumZ.h deleted file mode 100644 index a67e862ceffd78d4fd770d7b1a07e9f05af349d8..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/LaxFridrichsMomentumZ.h +++ /dev/null @@ -1,240 +0,0 @@ -/*************************************************************************** - 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 -#include -#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/src/Examples/inviscid-flow/PhysicalVariablesGetter.h b/src/Examples/inviscid-flow/PhysicalVariablesGetter.h deleted file mode 100644 index a0a7f672d2ee2a14f9357343c7ba8a08d45b63d3..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/PhysicalVariablesGetter.h +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; - typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; - typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; - typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; - typedef Pointers::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 = lpNorm( momentum.template getData< DeviceType >().getVector( meshEntity ), 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++ ) - { - Pointers::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; - Pointers::SharedPointer< PressureGetter, DeviceType > pressureGetter( conservativeVariables->getDensity(), - conservativeVariables->getEnergy(), - conservativeVariables->getMomentum(), - gamma ); - evaluator.evaluate( pressure, pressureGetter ); - } - -}; - -} //namespace TNL diff --git a/src/Examples/inviscid-flow/euler.cpp b/src/Examples/inviscid-flow/euler.cpp deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/euler.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow/euler.cu b/src/Examples/inviscid-flow/euler.cu deleted file mode 100644 index 4d76005cb1f70724be978ff0fa6fec63c4a8a76f..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/euler.cu +++ /dev/null @@ -1 +0,0 @@ -#include "euler.h" diff --git a/src/Examples/inviscid-flow/euler.h b/src/Examples/inviscid-flow/euler.h deleted file mode 100644 index 0bd0c6664c03ffd062568b424d23aaaf9e374b15..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/euler.h +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include -#include -#include "eulerProblem.h" -#include "LaxFridrichs.h" -#include "eulerRhs.h" -#include "eulerBuildConfigTag.h" - -#include "RiemannProblemInitialCondition.h" - -using namespace TNL; - -typedef eulerBuildConfigTag 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 eulerConfig -{ - public: - static void configSetup( Config::ConfigDescription & config ) - { - config.addDelimiter( "Inviscid flow settings:" ); - config.addEntry< String >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); - config.addEntryEnum< String >( "dirichlet" ); - config.addEntryEnum< String >( "neumann" ); - config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); - typedef Meshes::Grid< 3 > Mesh; - LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); - RiemannProblemInitialCondition< Mesh >::configSetup( config ); - - /**** - * Add definition of your solver command line arguments. - */ - - } -}; - -template< typename Real, - typename Device, - typename Index, - typename MeshType, - typename ConfigTag, - typename SolverStarter, - typename CommunicatorType > -class eulerSetter -{ - public: - - typedef Real RealType; - typedef Device DeviceType; - typedef Index IndexType; - - static bool run( const Config::ParameterContainer & parameters ) - { - enum { Dimension = MeshType::getMeshDimension() }; - typedef LaxFridrichs< MeshType, Real, Index > ApproximateOperator; - typedef eulerRhs< MeshType, Real > RightHandSide; - typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; - - /**** - * Resolve the template arguments of your solver here. - * The following code is for the Dirichlet and the Neumann boundary conditions. - * Both can be constant or defined as descrete values of Vector. - */ - String boundaryConditionsType = parameters.getParameter< String >( "boundary-conditions-type" ); - if( parameters.checkParameter( "boundary-conditions-constant" ) ) - { - typedef Functions::Analytic::Constant< Dimension, Real > Constant; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - if( boundaryConditionsType == "neumann" ) - { - typedef Operators::NeumannBoundaryConditions< MeshType, Constant, Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; - SolverStarter solverStarter; - return solverStarter.template run< Problem >( parameters ); - } - } - typedef Functions::MeshFunction< MeshType > MeshFunction; - if( boundaryConditionsType == "dirichlet" ) - { - typedef Operators::DirichletBoundaryConditions< MeshType, MeshFunction, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; - typedef eulerProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, 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, CommunicatorType, 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/src/Examples/inviscid-flow/eulerBuildConfigTag.h b/src/Examples/inviscid-flow/eulerBuildConfigTag.h deleted file mode 100644 index fec6d0fe721550c828cc475fafcd11d4c3496817..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/eulerBuildConfigTag.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef eulerBUILDCONFIGTAG_H_ -#define eulerBUILDCONFIGTAG_H_ - -#include -#include - -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 }; }; - -/**** - * 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, ExplicitEulerSolverTag >{ enum { enabled = true }; }; - -} // namespace Solvers - -namespace Meshes { -namespace BuildConfigTags { - -template< int Dimensions > struct GridDimensionTag< eulerBuildConfigTag, Dimensions >{ enum { enabled = ( Dimensions == 1 ) }; }; - -/**** - * Turn off support for float and long double. - */ -template<> struct GridRealTag< eulerBuildConfigTag, float > { enum { enabled = false }; }; -template<> struct GridRealTag< eulerBuildConfigTag, long double > { enum { enabled = false }; }; - -/**** - * Turn off support for short int and long int indexing. - */ -template<> struct GridIndexTag< eulerBuildConfigTag, short int >{ enum { enabled = false }; }; -template<> struct GridIndexTag< eulerBuildConfigTag, long int >{ enum { enabled = false }; }; - -} // namespace BuildConfigTags -} // namespace Meshes -} // namespace TNL - -#endif /* eulerBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/inviscid-flow/eulerProblem.h b/src/Examples/inviscid-flow/eulerProblem.h deleted file mode 100644 index a854f8098e751d65d9f1e542c540d653b1fb08c1..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/eulerProblem.h +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************** - 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 -#include -#include "CompressibleConservativeVariables.h" - - -using namespace TNL::Problems; - -namespace TNL { - -template< typename Mesh, - typename BoundaryCondition, - typename RightHandSide, - typename Communicator, - typename InviscidOperators > -class eulerProblem: - public PDEProblem< Mesh, - Communicator, - typename InviscidOperators::RealType, - typename Mesh::DeviceType, - typename InviscidOperators::IndexType > -{ - public: - - typedef typename InviscidOperators::RealType RealType; - typedef typename Mesh::DeviceType DeviceType; - typedef typename InviscidOperators::IndexType IndexType; - typedef PDEProblem< Mesh, Communicator, RealType, DeviceType, IndexType > BaseType; - - typedef Communicator CommunicatorType; - - using typename BaseType::MeshType; - using typename BaseType::MeshPointer; - using typename BaseType::DofVectorType; - using typename BaseType::DofVectorPointer; - static const int Dimensions = Mesh::getMeshDimension(); - - typedef Functions::MeshFunction< Mesh > MeshFunctionType; - typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; - typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; - typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; - typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; - typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; - typedef Pointers::SharedPointer< InviscidOperators > InviscidOperatorsPointer; - typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; - typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - - static String getType(); - - String getPrologHeader() const; - - void writeProlog( Logger& logger, - const Config::ParameterContainer& parameters ) const; - - bool setup( const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - bool setInitialCondition( const Config::ParameterContainer& parameters, - DofVectorPointer& dofs ); - - template< typename Matrix > - bool setupLinearSystem( Matrix& matrix ); - - bool makeSnapshot( const RealType& time, - const IndexType& step, - DofVectorPointer& dofs ); - - IndexType getDofs() const; - - void bindDofs( DofVectorPointer& dofs ); - - void getExplicitUpdate( const RealType& time, - const RealType& tau, - DofVectorPointer& _u, - DofVectorPointer& _fu ); - - void applyBoundaryConditions( const RealType& time, - DofVectorPointer& dofs ); - - template< typename Matrix > - void assemblyLinearSystem( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs, - Matrix& matrix, - DofVectorPointer& rightHandSide ); - - bool postIterate( const RealType& time, - const RealType& tau, - DofVectorPointer& dofs ); - - protected: - - InviscidOperatorsPointer inviscidOperatorsPointer; - - BoundaryConditionPointer boundaryConditionPointer; - RightHandSidePointer rightHandSidePointer; - - ConservativeVariablesPointer conservativeVariables, - conservativeVariablesRHS; - - VelocityFieldPointer velocity; - MeshFunctionPointer pressure; - - RealType gamma; -}; - -} // namespace TNL - -#include "eulerProblem_impl.h" - diff --git a/src/Examples/inviscid-flow/run-euler b/src/Examples/inviscid-flow/run-euler deleted file mode 100644 index 9ebf9cbb55a752a094a7a1e24d27eff4f7b6aa9c..0000000000000000000000000000000000000000 --- a/src/Examples/inviscid-flow/run-euler +++ /dev/null @@ -1,25 +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 -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/src/Examples/transport-equation/transportEquationProblem.h b/src/Examples/transport-equation/transportEquationProblem.h index b6aa381d5f1aca5fc004c6274a4128ac28a1c791..2b8b58fffab187cfdd2c89c4e2a0ade647aeb2e3 100644 --- a/src/Examples/transport-equation/transportEquationProblem.h +++ b/src/Examples/transport-equation/transportEquationProblem.h @@ -50,7 +50,7 @@ public PDEProblem< Mesh, using typename BaseType::MeshPointer; using typename BaseType::DofVectorType; using typename BaseType::DofVectorPointer; - + static String getType(); String getPrologHeader() const; diff --git a/src/Examples/turbulent-flows/CMakeLists.txt b/src/Examples/turbulent-flows/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..34889faf646205cb8ff5d58c1807ef6032ac0492 --- /dev/null +++ b/src/Examples/turbulent-flows/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory( zero-equation-model ) +add_subdirectory( one-equation-model ) +add_subdirectory( two-equation-model ) diff --git a/src/Examples/flow-sw/BoundaryConditionsBoiler.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h similarity index 83% rename from src/Examples/flow-sw/BoundaryConditionsBoiler.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h index f61f988da66f3f7476827c8f8853f4d6dbf67217..5b19d9cf3ebc20c84f6475363df372805ed0a3be 100644 --- a/src/Examples/flow-sw/BoundaryConditionsBoiler.h +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h @@ -5,6 +5,7 @@ #include "MomentumYBoundaryConditionBoiler.h" #include "MomentumZBoundaryConditionBoiler.h" #include "EnergyBoundaryConditionBoiler.h" +#include "TurbulentEnergyBoundaryConditionBoiler.h" namespace TNL { @@ -27,6 +28,7 @@ class BoundaryConditionsBoiler 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 TNL::Operators::TurbulentEnergyBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; @@ -34,6 +36,7 @@ class BoundaryConditionsBoiler typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; typedef Pointers::SharedPointer< MeshType > MeshPointer; typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; @@ -97,6 +100,28 @@ class BoundaryConditionsBoiler this->momentumYBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); this->momentumZBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->turbulentEnergyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + void setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + } DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() @@ -124,6 +149,11 @@ class BoundaryConditionsBoiler return this->energyBoundaryConditionsPointer; } + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + protected: DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; @@ -131,6 +161,7 @@ class BoundaryConditionsBoiler MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; }; diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/flow-vl/DensityBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-vl/DensityBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h diff --git a/src/Examples/flow-sw/EnergyBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h similarity index 99% rename from src/Examples/flow-sw/EnergyBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h index a99fdf0157bfcbca614374e8472ab9fe8a3b4f58..412640b5472f0e85026e26954503a6412bba0c39 100644 --- a/src/Examples/flow-sw/EnergyBoundaryConditionBoiler.h +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h @@ -12,7 +12,6 @@ #pragma once #include -#include "CompressibleConservativeVariables.h" namespace TNL { namespace Operators { diff --git a/src/Examples/flow-vl/MomentumXBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-vl/MomentumXBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h diff --git a/src/Examples/flow-vl/MomentumYBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-vl/MomentumYBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h diff --git a/src/Examples/flow-vl/MomentumZBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow-vl/MomentumZBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..e6b63da71803c661c620326a866389de874beca6 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h @@ -0,0 +1,664 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsBoilerBase +{ + 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 TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * 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())[ 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * 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, 0 >() ]; + /*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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..514caad73b645640b9ca5e7370c5740e93533382 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h @@ -0,0 +1,211 @@ +#include + +#include "DensityBoundaryConditionBoilerModel.h" +#include "MomentumXBoundaryConditionBoilerModel.h" +#include "MomentumYBoundaryConditionBoilerModel.h" +#include "MomentumZBoundaryConditionBoilerModel.h" +#include "EnergyBoundaryConditionBoilerModel.h" +#include "TurbulentEnergyBoundaryConditionBoilerModel.h" + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class BoundaryConditionsBoilerModel +{ + 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::DensityBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::MomentumXBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::MomentumYBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::MomentumZBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::EnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "vertical-angle", "Vertical angle of throttle in degrees", 0 ); + config.addEntry< double >( prefix + "horizontal-angle", "Horizontal angle of throttle in degrees", 45 ); + } + + 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); + setZAngle(parameters.getParameter< double >( prefix + "vertical-angle" ) * M_PI / 180.0 ); + setXYAngle(parameters.getParameter< double >( prefix + "horizontal-angle" ) * M_PI / 180.0 ); + 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 setZAngle(const RealType zAngle) + { + this->densityBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumXBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumYBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumZBoundaryConditionsPointer->setZAngle(zAngle); + this->energyBoundaryConditionsPointer->setZAngle(zAngle); + this->turbulentEnergyBoundaryConditionsPointer->setZAngle(zAngle); + } + + void setXYAngle(const RealType xYAngle) + { + this->densityBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumXBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumYBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumZBoundaryConditionsPointer->setXYAngle(xYAngle); + this->turbulentEnergyBoundaryConditionsPointer->setXYAngle(xYAngle); + } + + 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 setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType horizontalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + horizontalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + horizontalThrottleSpeed = 0; + else + horizontalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->energyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->turbulentEnergyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType verticalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + verticalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + verticalThrottleSpeed = 0; + else + verticalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->energyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->turbulentEnergyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..a58f32f7c577590801504d675dec55243e2f0b57 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h @@ -0,0 +1,580 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DensityBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class DensityBoundaryConditionsBoilerModelBase +{ + 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 DensityBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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.835 * ( entity.getMesh().getDimensions().y() - 1 )) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ 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, -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 setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 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 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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DensityBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..d0475576b5fa910528eaa3c7a80ffd8047bddcc9 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,962 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class EnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class EnergyBoundaryConditionsBoilerModelBase +{ + 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 EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const EnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..893815913ba45510c520de2033d7be690faea8bb --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h @@ -0,0 +1,940 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumXBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumXBoundaryConditionsBoilerModelBase +{ + 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 MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumXBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..e8aa33e885efcc06f134a94f7e6df8cb974fb417 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h @@ -0,0 +1,941 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumYBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumYBoundaryConditionsBoilerModelBase +{ + 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 MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( - 1.0 ) + * std::sin( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) +// down throttle + { + if( + ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumYBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..ee40b1b74066d4c5ee0491345538577525a7e4f5 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h @@ -0,0 +1,838 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumZBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumZBoundaryConditionsBoilerModelBase +{ + 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 MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( + ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.408 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumZBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..851b706184862400daae12810271d7ba6c9753e8 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,832 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsBoilerModelBase +{ + 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 TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle TurbulentEnergy + { + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle TurbulentEnergy + { + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + } +// if for chimney exit + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed;; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed;; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed;; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flow-sw/BoundaryConditionsCavity.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h similarity index 80% rename from src/Examples/flow-sw/BoundaryConditionsCavity.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h index bbae2d3e93c65383db11a53a3b16d734fc3131e2..0b80a7c5546803bcd2adcd7b23ff508445b7d630 100644 --- a/src/Examples/flow-sw/BoundaryConditionsCavity.h +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h @@ -5,6 +5,7 @@ #include "MomentumYBoundaryConditionCavity.h" #include "MomentumZBoundaryConditionCavity.h" #include "EnergyBoundaryConditionCavity.h" +#include "TurbulentEnergyBoundaryConditionCavity.h" namespace TNL { @@ -27,6 +28,7 @@ class BoundaryConditionsCavity 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 TNL::Operators::TurbulentEnergyBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; @@ -34,6 +36,7 @@ class BoundaryConditionsCavity typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; typedef Pointers::SharedPointer< MeshType > MeshPointer; typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; @@ -52,6 +55,7 @@ class BoundaryConditionsCavity this->momentumYBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); this->momentumZBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); this->energyBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->turbulentEnergyBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); return true; } @@ -62,6 +66,7 @@ class BoundaryConditionsCavity this->momentumYBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); this->momentumZBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); this->energyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->turbulentEnergyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); } void setTimestep(const RealType timestep) @@ -97,6 +102,28 @@ class BoundaryConditionsCavity this->momentumYBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); this->momentumZBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->turbulentEnergyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + void setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + } DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() @@ -124,6 +151,11 @@ class BoundaryConditionsCavity return this->energyBoundaryConditionsPointer; } + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + protected: DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; @@ -131,6 +163,7 @@ class BoundaryConditionsCavity MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; }; diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/flow-sw/DensityBoundaryConditionCavity.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h similarity index 99% rename from src/Examples/flow-sw/DensityBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h index 18eaff1101eccc7733eb5978b48807be82bba916..c753d324a288a331dbfb9d73e341fe962f39889e 100644 --- a/src/Examples/flow-sw/DensityBoundaryConditionCavity.h +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h @@ -253,20 +253,20 @@ class DensityBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIn const IndexType& index = entity.getIndex(); if( entity.getCoordinates().x() == 0 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 1, 0 >() ]; } if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; } if( entity.getCoordinates().y() == 0 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + return u[ 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, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, -1 >() ]; } } diff --git a/src/Examples/flow-vl/EnergyBoundaryConditionCavity.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h similarity index 97% rename from src/Examples/flow-vl/EnergyBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h index 3b49cd56e5ab6901716c86115561c26fbbbff973..ca5d85442d02edeb7ddd39749c6441c13e3eb6ed 100644 --- a/src/Examples/flow-vl/EnergyBoundaryConditionCavity.h +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h @@ -12,7 +12,6 @@ #pragma once #include -#include "CompressibleConservativeVariables.h" namespace TNL { namespace Operators { @@ -271,8 +270,8 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd const IndexType& index = entity.getIndex(); if( entity.getCoordinates().x() == 0 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; - /* ( (* this->pressure)[ neighborEntities.template getEntityIndex< 1, 0 >() ] + return //u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + ( (* this->pressure)[ neighborEntities.template getEntityIndex< 1, 0 >() ] / ( this->gamma - 1 ) ) + 0 @@ -287,12 +286,12 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd / (* 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 >() ] + return //u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + ( (* this->pressure)[ neighborEntities.template getEntityIndex< -1, 0 >() ] / ( this->gamma - 1 ) ) + 0 @@ -306,12 +305,12 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd / (* 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 >() ] + return //u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 1 >() ] / ( this->gamma - 1 ) ) + 0 @@ -325,7 +324,7 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd / (* 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 ) @@ -521,18 +520,18 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshInd + 0.5 * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] * ( - ( this->cavitySpeed + ( this->cavitySpeed/* * ( entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) ) - / ( entity.getMesh().getDimensions().x() / 2 ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ ) * - ( this->cavitySpeed + ( this->cavitySpeed/* * ( entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) ) - / ( entity.getMesh().getDimensions().x() / 2 ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ ) + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] diff --git a/src/Examples/flow-vl/MomentumXBoundaryConditionCavity.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow-vl/MomentumXBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h diff --git a/src/Examples/flow-vl/MomentumYBoundaryConditionCavity.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow-vl/MomentumYBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h diff --git a/src/Examples/flow-vl/MomentumZBoundaryConditionCavity.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow-vl/MomentumZBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..05098c7ddf400f05d49e35794cd92944013cd32a --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h @@ -0,0 +1,568 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsCavityBase +{ + 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 TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 >(), -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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h new file mode 100644 index 0000000000000000000000000000000000000000..da9e948ab1a3d410848e18ebbf2e19b455d8bbfc --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function = Functions::Analytic::Constant< Mesh::getMeshDimension(), typename Mesh::RealType >, + int MeshEntitiesDimension = Mesh::getMeshDimension(), + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsDirichlet +{ + 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::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setIntensity(const RealType& intensity) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h new file mode 100644 index 0000000000000000000000000000000000000000..c2a2a347511cec2bd5cdcc05be51b7dfc6312e61 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h @@ -0,0 +1,137 @@ +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsNeumann +{ + 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::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setIntensity(const RealType& intensity) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/CMakeLists.txt b/src/Examples/turbulent-flows/one-equation-model/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6c5571e6e4ea4278fb5f5160f59d978108de7d99 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/CMakeLists.txt @@ -0,0 +1,101 @@ +#one-equation-turbulence-model-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + oneEquationTurbulenceModelLaxFriedrichs.cpp + oneEquationTurbulenceModelLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-one-equation-turbulence-model-Lax-Friedrichs oneEquationTurbulenceModelLaxFriedrichs.cu) + target_link_libraries (tnl-one-equation-turbulence-model-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-one-equation-turbulence-model-Lax-Friedrichs oneEquationTurbulenceModelLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-one-equation-turbulence-model-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-one-equation-turbulence-model-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#one-equation-turbulence-model-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + oneEquationTurbulenceModelStegerWarming.cpp + oneEquationTurbulenceModelStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-one-equation-turbulence-model-Steger-Warming oneEquationTurbulenceModelStegerWarming.cu) + target_link_libraries (tnl-one-equation-turbulence-model-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-one-equation-turbulence-model-Steger-Warming oneEquationTurbulenceModelStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-one-equation-turbulence-model-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-one-equation-turbulence-model-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#one-equation-turbulence-model-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + oneEquationTurbulenceModelVanLeer.cpp + oneEquationTurbulenceModelVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-one-equation-turbulence-model-Van-Leer oneEquationTurbulenceModelVanLeer.cu) + target_link_libraries (tnl-one-equation-turbulence-model-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-one-equation-turbulence-model-Van-Leer oneEquationTurbulenceModelVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-one-equation-turbulence-model-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-one-equation-turbulence-model-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#one-equation-turbulence-model-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + oneEquationTurbulenceModelAUSMPlus.cpp + oneEquationTurbulenceModelAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-one-equation-turbulence-model-AUSM-plus oneEquationTurbulenceModelAUSMPlus.cu) + target_link_libraries (tnl-one-equation-turbulence-model-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-one-equation-turbulence-model-AUSM-plus oneEquationTurbulenceModelAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-one-equation-turbulence-model-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-one-equation-turbulence-model-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/one-equation-model/CMakeLists_separate.txt b/src/Examples/turbulent-flows/one-equation-model/CMakeLists_separate.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd8e6f8708f7029abaf81aea4050908eb47bb71b --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/CMakeLists_separate.txt @@ -0,0 +1,101 @@ +#navier-stokes-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesLaxFriedrichs.cpp + navierStokesLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cu) + target_link_libraries (tnl-navier-stokes-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesStegerWarming.cpp + navierStokesStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cu) + target_link_libraries (tnl-navier-stokes-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesVanLeer.cpp + navierStokesVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cu) + target_link_libraries (tnl-navier-stokes-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesAUSMPlus.cpp + navierStokesAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cu) + target_link_libraries (tnl-navier-stokes-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/one-equation-model/CMakeLists_together.txt b/src/Examples/turbulent-flows/one-equation-model/CMakeLists_together.txt new file mode 100644 index 0000000000000000000000000000000000000000..f26fc6d34635dad513d36fd9c4ea21d3c1e95489 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/CMakeLists_together.txt @@ -0,0 +1,26 @@ +#navier-stokes + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokes.cpp + navierStokes.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cu) + target_link_libraries (tnl-navier-stokes ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/one-equation-model/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/one-equation-model/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..23ca0fe8df549f2454d7278f939bc31a8a9b814a --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/CompressibleConservativeVariables.h @@ -0,0 +1,179 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > MomentumFieldPointer; + + CompressibleConservativeVariables(){}; + + CompressibleConservativeVariables( const MeshPointer& meshPointer ) + : density( meshPointer ), + momentum( meshPointer ), + //pressure( meshPointer ), + energy( meshPointer ), + turbulentEnergy( meshPointer ){}; + + void setMesh( const MeshPointer& meshPointer ) + { + this->density->setMesh( meshPointer ); + this->momentum->setMesh( meshPointer ); + //this->pressure.setMesh( meshPointer ); + this->energy->setMesh( meshPointer ); + this->turbulentEnergy->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 ); + currentOffset += this->energy->getDofs( meshPointer ); + this->turbulentEnergy->bind( meshPointer, data, currentOffset ); + } + + IndexType getDofs( const MeshPointer& meshPointer ) const + { + return this->density->getDofs( meshPointer ) + + this->momentum->getDofs( meshPointer ) + + this->energy->getDofs( meshPointer ) + + this->turbulentEnergy->getDofs( meshPointer ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + const MeshFunctionPointer& getEnergy() const + { + return this->energy; + } + + void setTurbulentEnergy( MeshFunctionPointer& energy ) + { + this->energy = energy; + } + + __cuda_callable__ + MeshFunctionPointer& getTurbulentEnergy() + { + return this->turbulentEnergy; + } + + __cuda_callable__ + const MeshFunctionPointer& getTurbulentEnergy() const + { + return this->turbulentEnergy; + } + + void setEnergy( MeshFunctionPointer& turbulentEnergy ) + { + this->energy = turbulentEnergy; + } + + void getVelocityField( VelocityFieldType& velocityField ) + { + + } + + protected: + + MeshFunctionPointer density; + MomentumFieldPointer momentum; + MeshFunctionPointer energy; + MeshFunctionPointer turbulentEnergy; + +}; + +} // namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlus.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..025a634de41beab0da310c7997e1bfb5061bca05 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlus.h @@ -0,0 +1,217 @@ +/*************************************************************************** + AUSMPlus.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 +#include +#include + +#include "AUSMPlusContinuity.h" +#include "AUSMPlusEnergy.h" +#include "AUSMPlusMomentumX.h" +#include "AUSMPlusMomentumY.h" +#include "AUSMPlusMomentumZ.h" +#include "AUSMPlusTurbulentEnergy.h" + +#include "Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = PrandtlKolmogorovOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlus +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + + typedef AUSMPlusContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef AUSMPlusMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef AUSMPlusMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef AUSMPlusMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef AUSMPlusEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef AUSMPlusTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + + 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 ); + } + + AUSMPlus() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "AUSMPlus" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->turbulentEnergyOperatorPointer->setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->turbulentEnergyOperatorPointer->setViscosityConstant( ViscosityConstant ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..1c90c16623d1878986e129fd00936a6663f5c7e0 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h @@ -0,0 +1,401 @@ +/*************************************************************************** + AUSMPlusContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusContinuity< " ) + + 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 DensityFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity + MachBorderMinus * RightDensity ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ], u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->DensityFlux( u[ west ] , u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ] , u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->DensityFlux( u[ down ] , u[ center ], velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->DensityFlux( u[ center ], u[ up ] , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..3013e563b78a4507379aeae8470a5c5d83c518e0 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h @@ -0,0 +1,522 @@ +/*************************************************************************** + AUSMPlusEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + AUSMPlusEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "AUSMPlusEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + RealType EnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftEnergy, + const RealType& RightEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * ( LeftEnergy + LeftPressure) + MachBorderMinus * ( RightEnergy + RightPressure ) ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->EnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ], u[ center ] ) + - this->EnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..e9b5565d73f0eed3785f661b7f1beed03da722e5 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h @@ -0,0 +1,206 @@ +/*************************************************************************** + AUSMPlusMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + RealType MainMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + RealType PressureSplitingPlus = 0; + RealType PressureSplitingMinus = 0; + RealType PressureBorder = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + PressureSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + PressureSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) * (2.0 - LeftMachNumber ) + + 3.0 / 16.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + PressureSplitingPlus = 1.0; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + PressureSplitingMinus = 1.0; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + PressureSplitingMinus = 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) * (2.0 + RightMachNumber ) + - 3.0 / 16.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + PressureSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + PressureBorder = PressureSplitingPlus * LeftPressure + PressureSplitingMinus * RightPressure; + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftVelocity + MachBorderMinus * RightDensity * RightVelocity ) + PressureBorder; + } + + RealType OtherMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftOtherVelocity, + const RealType& RightOtherVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftOtherVelocity + MachBorderMinus * RightDensity * RightOtherVelocity ); + } + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..24f4c5e780ecb2d640b65ec8bd139f3207efd9c9 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h @@ -0,0 +1,398 @@ +/*************************************************************************** + AUSMPlusMomentumX.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_x_down , velocity_x_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_x_center, velocity_x_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..d1a8d43041623a06152ac07c2fb114d2095e73ab --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h @@ -0,0 +1,371 @@ +/*************************************************************************** + AUSMPlusMomentumY.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_y_down , velocity_y_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_y_center, velocity_y_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..8915da35c870f05f85e91fa38afda392ad29b23b --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h @@ -0,0 +1,316 @@ +/*************************************************************************** + AUSMPlusMomentumZ.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_z_west , velocity_z_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_z_center, velocity_z_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_z_south , velocity_z_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_z_center, velocity_z_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->MainMomentumFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->MainMomentumFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..9eda7a2068f383b267dac194b1d74328e07d4f70 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h @@ -0,0 +1,460 @@ +/*************************************************************************** + AUSMPlusTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusTurbulentEnergy< " ) + + 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 setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->rightHandSide.setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->rightHandSide.setViscosityConstant( ViscosityConstant ); + } + + RealType TurbulentEnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftTurbulentEnergy, + const RealType& RightTurbulentEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftTurbulentEnergy + MachBorderMinus * RightTurbulentEnergy ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center , velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center , density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->TurbulentEnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ] , u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->TurbulentEnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ] , u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->TurbulentEnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ] , u[ center ]) + - this->TurbulentEnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/flow-sw/LaxFridrichs.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h similarity index 50% rename from src/Examples/flow-sw/LaxFridrichs.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h index c56d20aed9947bd16796a5bf7ceb22adb237bf0c..2581452d272b1cd1493fcc7f2fce17d3e578dee2 100644 --- a/src/Examples/flow-sw/LaxFridrichs.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h @@ -20,10 +20,14 @@ #include "LaxFridrichsMomentumX.h" #include "LaxFridrichsMomentumY.h" #include "LaxFridrichsMomentumZ.h" +#include "LaxFridrichsTurbulentEnergy.h" + +#include "Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide = PrandtlKolmogorovOperatorRightHandSide< Mesh, typename Mesh::RealType, typename Mesh::IndexType >, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichs @@ -36,12 +40,20 @@ class LaxFridrichs typedef Functions::MeshFunction< Mesh > MeshFunctionType; static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; - 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 LaxFridrichsContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef LaxFridrichsMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef LaxFridrichsMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef LaxFridrichsMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef LaxFridrichsEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef LaxFridrichsTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; @@ -52,11 +64,13 @@ class LaxFridrichs typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) { config.addEntry< double >( prefix + "numerical-viscosity", "Value of artificial (numerical) viscosity in the Lax-Fridrichs scheme", 1.0 ); + config.addEntry< double >( prefix + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); } LaxFridrichs() @@ -66,12 +80,20 @@ class LaxFridrichs const Config::ParameterContainer& parameters, const String& prefix = "" ) { + std::cout << "Lax-Friedrichs" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); 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 ); + this->turbulentEnergyOperatorPointer->setArtificialViscosity( artificialViscosity ); return true; } @@ -83,6 +105,11 @@ class LaxFridrichs this->momentumYOperatorPointer->setTau( tau ); this->momentumZOperatorPointer->setTau( tau ); this->energyOperatorPointer->setTau( tau ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + } + + void setGamma( const RealType& gamma ) + { } void setPressure( const MeshFunctionPointer& pressure ) @@ -100,6 +127,49 @@ class LaxFridrichs this->momentumYOperatorPointer->setVelocity( velocity ); this->momentumZOperatorPointer->setVelocity( velocity ); this->energyOperatorPointer->setVelocity( velocity ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->turbulentEnergyOperatorPointer->setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->turbulentEnergyOperatorPointer->setViscosityConstant( ViscosityConstant ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); } const ContinuityOperatorPointer& getContinuityOperator() const @@ -126,6 +196,11 @@ class LaxFridrichs { return this->energyOperatorPointer; } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } protected: @@ -133,9 +208,11 @@ class LaxFridrichs MomentumXOperatorPointer momentumXOperatorPointer; MomentumYOperatorPointer momentumYOperatorPointer; MomentumZOperatorPointer momentumZOperatorPointer; - EnergyOperatorPointer energyOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; RealType artificialViscosity; + RealType dynamicalViscosity; }; } //namespace TNL diff --git a/src/Examples/flow/LaxFridrichsContinuityEuler.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h similarity index 75% rename from src/Examples/flow/LaxFridrichsContinuityEuler.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h index f444a4e2541e76addb5c7a3eba87cf1d946ee4fa..e82c9d4242d426adb2f21b238b05f0773e3b1c3b 100644 --- a/src/Examples/flow/LaxFridrichsContinuityEuler.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h @@ -14,12 +14,13 @@ #include #include #include -#include +#include namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuityBase @@ -35,6 +36,7 @@ class LaxFridrichsContinuityBase static const int Dimensions = MeshType::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsContinuityBase() : artificialViscosity( 1.0 ){}; @@ -68,12 +70,15 @@ class LaxFridrichsContinuityBase RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; RealType artificialViscosity; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuity @@ -85,14 +90,15 @@ class LaxFridrichsContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -114,15 +120,20 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re 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 ]; + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + // return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) // - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) - - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse; + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -146,14 +157,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -177,19 +189,23 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re //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 ]; + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -213,14 +229,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -244,27 +261,30 @@ class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Re //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 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 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 ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ up ] * velocity_z_up - u[ down ] * velocity_z_down ) * hzInverse ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/inviscid-flow-sw/LaxFridrichsEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h similarity index 69% rename from src/Examples/inviscid-flow-sw/LaxFridrichsEnergy.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h index 03019ed23c85f82ee489c95d8173c0f100cff3c8..89743fae60943d272654e9088067d724e1db6262 100644 --- a/src/Examples/inviscid-flow-sw/LaxFridrichsEnergy.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h @@ -16,6 +16,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergyBase @@ -32,6 +33,7 @@ class LaxFridrichsEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsEnergyBase() : artificialViscosity( 1.0 ){}; @@ -52,6 +54,7 @@ class LaxFridrichsEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -63,12 +66,34 @@ class LaxFridrichsEnergyBase { this->artificialViscosity = artificialViscosity; } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity(density); + } protected: RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; @@ -76,6 +101,7 @@ class LaxFridrichsEnergyBase }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergy @@ -85,15 +111,16 @@ class LaxFridrichsEnergy template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -115,18 +142,23 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, 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& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; - + - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -150,14 +182,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -180,27 +213,33 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -224,14 +263,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -253,16 +293,17 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; @@ -270,13 +311,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ] ) @@ -285,7 +328,9 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, + ( ( ( 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 ); + -( ( e[ down ] + pressure_down ) * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-vl/LaxFridrichsMomentumBase.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h similarity index 72% rename from src/Examples/flow-vl/LaxFridrichsMomentumBase.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h index cc2561748968a2bd808fa434d4f3d87d41765f45..918cba0820717615f2dfa832d48bd5b176c9c648 100644 --- a/src/Examples/flow-vl/LaxFridrichsMomentumBase.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h @@ -14,6 +14,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumBase @@ -30,6 +31,7 @@ class LaxFridrichsMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsMomentumBase() : artificialViscosity( 1.0 ){}; @@ -42,6 +44,7 @@ class LaxFridrichsMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -54,11 +57,33 @@ class LaxFridrichsMomentumBase this->artificialViscosity = artificialViscosity; } + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity(density); + } + protected: RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; diff --git a/src/Examples/flow-sw/LaxFridrichsMomentumX.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h similarity index 70% rename from src/Examples/flow-sw/LaxFridrichsMomentumX.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h index 63def12d315188b82e82402635fca863d1b9a629..57258d1a534721a5887ad8affb0e60acdf66943d 100644 --- a/src/Examples/flow-sw/LaxFridrichsMomentumX.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumX @@ -27,15 +28,16 @@ class LaxFridrichsMomentumX template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -67,17 +69,22 @@ 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 IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; + -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -101,14 +108,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -139,26 +147,34 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -182,14 +198,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -219,30 +236,30 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -250,7 +267,9 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_u[ down ] * velocity_z_down ) )* hzInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumY.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h similarity index 69% rename from src/Examples/inviscid-flow-vl/LaxFridrichsMomentumY.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h index 8ce42282dd4c74d5ed72d2abbd661235b95dc160..4cca02779d04d1395051035156d30b8a998ffa64 100644 --- a/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumY.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumY @@ -27,15 +28,16 @@ class LaxFridrichsMomentumY template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -128,26 +131,32 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > @@ -171,14 +180,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -207,34 +217,44 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 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 * + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ down ] * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumZ.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h similarity index 78% rename from src/Examples/inviscid-flow-vl/LaxFridrichsMomentumZ.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h index a67e862ceffd78d4fd770d7b1a07e9f05af349d8..1f394bfef12c16125be4a674d08f2defbc455f12 100644 --- a/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumZ.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumZ @@ -27,15 +28,16 @@ class LaxFridrichsMomentumZ template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -151,14 +154,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -188,25 +192,30 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -214,7 +223,9 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_w[ down ] * velocity_z_down + pressure_down ) )* hzInverse ) + + + this->rightHandSide(rho_w, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..3c434196ede339ba47c3feeee642110b3d22dbc5 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h @@ -0,0 +1,347 @@ +/*************************************************************************** + LaxFridrichsTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + LaxFridrichsTurbulentEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsTurbulentEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->rightHandSide.setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->rightHandSide.setViscosityConstant( ViscosityConstant ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity(density); + } + + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarming.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..cec76d37c23c25d1a1e2abfae6ca617ce097cbdf --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarming.h @@ -0,0 +1,218 @@ +/*************************************************************************** + StegerWarming.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 +#include +#include + +#include "StegerWarmingContinuity.h" +#include "StegerWarmingEnergy.h" +#include "StegerWarmingMomentumX.h" +#include "StegerWarmingMomentumY.h" +#include "StegerWarmingMomentumZ.h" +#include "StegerWarmingTurbulentEnergy.h" + +#include "Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = PrandtlKolmogorovOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarming +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + + + typedef StegerWarmingContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef StegerWarmingMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef StegerWarmingMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef StegerWarmingMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef StegerWarmingEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef StegerWarmingTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + + 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 ); + } + + StegerWarming() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "Steger-Warming"<< std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->turbulentEnergyOperatorPointer->setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->turbulentEnergyOperatorPointer->setViscosityConstant( ViscosityConstant ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/flow-sw/UpwindContinuity.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h similarity index 83% rename from src/Examples/flow-sw/UpwindContinuity.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h index fc599d3d9773c39752b72abcee6626150ea70c7a..5fbef7be69519f22735bf920375af3ad71eb6353 100644 --- a/src/Examples/flow-sw/UpwindContinuity.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindContinuity.h - description + StegerWarmingContinuity.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -20,9 +20,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuityBase +class StegerWarmingContinuityBase { public: @@ -36,10 +37,11 @@ class UpwindContinuityBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; static String getType() { - return String( "UpwindContinuity< " ) + + return String( "StegerWarmingContinuity< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -65,7 +67,6 @@ class UpwindContinuityBase this->velocity = velocity; }; - __cuda_callable__ RealType positiveDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -80,7 +81,6 @@ class UpwindContinuityBase return density * velocity; }; - __cuda_callable__ RealType negativeDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -95,6 +95,7 @@ class UpwindContinuityBase return 0.0; }; + protected: @@ -104,15 +105,18 @@ class UpwindContinuityBase VelocityFieldPointer velocity; + OperatorRightHandSideType rightHandSide; + MeshFunctionPointer pressure; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuity +class StegerWarmingContinuity { }; @@ -121,14 +125,15 @@ class UpwindContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -159,16 +164,18 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -192,14 +199,15 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -221,8 +229,8 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In 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 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 >(); @@ -236,13 +244,13 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -255,7 +263,9 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -279,14 +289,15 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -328,17 +339,17 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -357,7 +368,9 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/flow-sw/UpwindEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h similarity index 52% rename from src/Examples/flow-sw/UpwindEnergy.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h index 6c7e94ec87ce2e3fbd96e6affaeb91b1242d9246..05d8c3b1f17bdc5db8ab27729430ce85f740492d 100644 --- a/src/Examples/flow-sw/UpwindEnergy.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindEnergy.h - description + StegerWarmingEnergy.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -16,9 +16,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergyBase +class StegerWarmingEnergyBase { public: @@ -32,13 +33,11 @@ class UpwindEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; - UpwindEnergyBase() - : artificialViscosity( 1.0 ){}; - static String getType() { - return String( "UpwindEnergy< " ) + + return String( "StegerWarmingEnergy< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -57,6 +56,7 @@ class UpwindEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -67,18 +67,24 @@ class UpwindEnergyBase void setDensity( const MeshFunctionPointer& density ) { this->density = density; - }; - - void setArtificialViscosity( const RealType& artificialViscosity ) - { - this->artificialViscosity = artificialViscosity; + this->rightHandSide.setDensity(density); }; void setDynamicalViscosity( const RealType& dynamicalViscosity ) { - this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); } + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + protected: RealType tau; @@ -86,33 +92,35 @@ class UpwindEnergyBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; - - RealType artificialViscosity, dynamicalViscosity; MeshFunctionPointer density; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergy +class StegerWarmingEnergy { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -124,7 +132,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index using typename BaseType::VelocityFieldPointer; using BaseType::Dimensions; - __cuda_callable__ RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -149,7 +156,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); }; - __cuda_callable__ RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -185,11 +191,10 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 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 ]; @@ -199,9 +204,9 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, pressure_center) @@ -209,11 +214,8 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index - 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; + + + this->rightHandSide(u, entity, time); } @@ -238,14 +240,15 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -315,20 +318,14 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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& 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 ]; @@ -342,25 +339,17 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) @@ -374,38 +363,8 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -429,14 +388,15 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -506,32 +466,17 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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 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 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 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 ]; @@ -549,53 +494,29 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) @@ -608,94 +529,15 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index - 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; + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..227c884869627e69d314d9df14df74c06b61ba08 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h @@ -0,0 +1,151 @@ +/*************************************************************************** + StegerWarmingMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + } + + 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 <= 0.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( ( machNumber + 1.0 ) * ( machNumber + 1.0 ) ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( 2.0 * ( this->gamma - 1.0 ) * machNumber * machNumber + (machNumber + 1.0 ) * (machNumber + 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( 2.0 * ( this->gamma - 1.0 ) * machNumber * machNumber + (machNumber - 1.0 ) * (machNumber - 1.0 ) ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( ( machNumber - 1.0 ) * ( machNumber - 1.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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ) * velocity_other; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * velocity_other; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ) * velocity_other; + else + return 0.0; + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/inviscid-flow-sw/UpwindMomentumX.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h similarity index 67% rename from src/Examples/inviscid-flow-sw/UpwindMomentumX.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h index ed49dda94585e64f85d820569a757d849757e6ca..c6588083cd9efdd02864d6200cff678de8d0a76d 100644 --- a/src/Examples/inviscid-flow-sw/UpwindMomentumX.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumX.h - description + StegerWarmingMomentumX.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "StegerWarmingMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumX +class StegerWarmingMomentumX { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "StegerWarmingMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -67,28 +69,31 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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& 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -112,14 +117,15 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -133,7 +139,7 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "StegerWarmingMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -151,13 +157,16 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); - const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + 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& 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 RealType& pressure_center = this->pressure.template getData< DeviceType >()[ center ]; const RealType& pressure_west = this->pressure.template getData< DeviceType >()[ west ]; @@ -171,15 +180,15 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -192,7 +201,9 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } @@ -218,14 +229,15 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -239,7 +251,7 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "StegerWarmingMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -255,17 +267,17 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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& 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 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 ]; @@ -283,21 +295,21 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -316,7 +328,9 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-sw/UpwindMomentumY.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h similarity index 67% rename from src/Examples/inviscid-flow-sw/UpwindMomentumY.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h index c2126d43af781289f86999a5f4a7f8d24ad5c6e8..210fb60878d9da9f6f44bb55972997d73be63df7 100644 --- a/src/Examples/inviscid-flow-sw/UpwindMomentumY.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumY.h - description + StegerWarmingMomentumY.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "StegerWarmingMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumY +class StegerWarmingMomentumY { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "StegerWarmingMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "StegerWarmingMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -128,14 +131,14 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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& 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 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 ]; @@ -149,15 +152,15 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -170,7 +173,9 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -194,14 +199,15 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -215,7 +221,7 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "StegerWarmingMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -231,17 +237,17 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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& 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 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 ]; @@ -259,21 +265,21 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -292,7 +298,9 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-sw/UpwindMomentumZ.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h similarity index 71% rename from src/Examples/inviscid-flow-sw/UpwindMomentumZ.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h index 97339e804b3bda5203d0b12feeb59e30249f2327..135352d2fdf260a2310e5c6e45f2cc581d0e9ff0 100644 --- a/src/Examples/inviscid-flow-sw/UpwindMomentumZ.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumZ.h - description + StegerWarmingMomentumZ.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "StegerWarmingMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumZ +class StegerWarmingMomentumZ { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "StegerWarmingMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "StegerWarmingMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -151,14 +154,15 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -172,7 +176,7 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "StegerWarmingMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -188,17 +192,17 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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& 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 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 ]; @@ -216,23 +220,23 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; - return -hxInverse * ( + return 0-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 ) @@ -249,7 +253,9 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..ff59b864df853e27f05a8f7f3dd8b840884bf5ef --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h @@ -0,0 +1,453 @@ +/*************************************************************************** + StegerWarmingTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->rightHandSide.setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->rightHandSide.setViscosityConstant( ViscosityConstant ); + } + + RealType positiveTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) 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 <= 0.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ); + else + return turbulentEnergy * velocity; + }; + + RealType negativeTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return turbulentEnergy * velocity; + else if ( machNumber <= 0.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeer.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..e4d6d113dfffa20a3e73c8067bdbe771ce8267d1 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeer.h @@ -0,0 +1,217 @@ +/*************************************************************************** + VanLeer.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 +#include +#include + +#include "VanLeerContinuity.h" +#include "VanLeerEnergy.h" +#include "VanLeerMomentumX.h" +#include "VanLeerMomentumY.h" +#include "VanLeerMomentumZ.h" +#include "VanLeerTurbulentEnergy.h" + +#include "Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = PrandtlKolmogorovOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeer +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + + typedef VanLeerContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef VanLeerMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef VanLeerMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef VanLeerMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef VanLeerEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef VanLeerTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + + 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 ); + } + + VanLeer() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "VanLeer" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->turbulentEnergyOperatorPointer->setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->turbulentEnergyOperatorPointer->setViscosityConstant( ViscosityConstant ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/inviscid-flow-vl/UpwindContinuity.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerContinuity.h similarity index 82% rename from src/Examples/inviscid-flow-vl/UpwindContinuity.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerContinuity.h index 4a21cd502b3f54f898a25ef85be84dcf52a52f5d..3b497125a6a291990c61c4fed6f158a73472e084 100644 --- a/src/Examples/inviscid-flow-vl/UpwindContinuity.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerContinuity.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindContinuity.h - description + VanLeerContinuity.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -20,9 +20,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuityBase +class VanLeerContinuityBase { public: @@ -36,10 +37,11 @@ class UpwindContinuityBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; static String getType() { - return String( "UpwindContinuity< " ) + + return String( "VanLeerContinuity< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -65,7 +67,6 @@ class UpwindContinuityBase this->velocity = velocity; }; - __cuda_callable__ RealType positiveDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -78,7 +79,6 @@ class UpwindContinuityBase return density * velocity; }; - __cuda_callable__ RealType negativeDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -86,10 +86,16 @@ class UpwindContinuityBase if ( machNumber <= -1.0 ) return density * velocity; else if ( machNumber <= 1.0 ) - return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( 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: @@ -99,15 +105,18 @@ class UpwindContinuityBase VelocityFieldPointer velocity; + OperatorRightHandSideType rightHandSide; + MeshFunctionPointer pressure; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuity +class VanLeerContinuity { }; @@ -116,14 +125,15 @@ class UpwindContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -147,23 +157,25 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -187,14 +199,15 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -231,13 +244,13 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -250,7 +263,9 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -274,14 +289,15 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -323,17 +339,17 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -352,7 +368,9 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..4e19cdda4ea4fd2d60d85f0f197bcf8ec235dfea --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerEnergy.h @@ -0,0 +1,593 @@ +/*************************************************************************** + VanLeerEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + VanLeerEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "VanLeerEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..a1901fb7c3a3e9b99026b5774f62026959bd4ed3 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h @@ -0,0 +1,146 @@ +/*************************************************************************** + VanLeerMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + 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; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/flow-sw/UpwindMomentumX.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h similarity index 57% rename from src/Examples/flow-sw/UpwindMomentumX.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h index edd3756208121de465185a84693a10671e587bac..04e41c015c6193ec3c7e45d5d737512a2762f38a 100644 --- a/src/Examples/flow-sw/UpwindMomentumX.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumX.h - description + VanLeerMomentumX.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "VanLeerMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumX +class VanLeerMomentumX { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "VanLeerMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -67,23 +69,24 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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& 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -91,10 +94,8 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -118,14 +119,15 @@ class UpwindMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -139,7 +141,7 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "VanLeerMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -156,20 +158,21 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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 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 ]; @@ -183,23 +186,23 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -213,18 +216,8 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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; + + + this->rightHandSide(u, entity, time); } @@ -250,14 +243,15 @@ class UpwindMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -271,7 +265,7 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumX< " ) + + return String( "VanLeerMomentumX< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -287,32 +281,33 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 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& 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& 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& 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& 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 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 ]; @@ -330,45 +325,45 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveMainMomentumFlux( density_center, velocity_x_center, pressure_center ) @@ -388,26 +383,8 @@ class UpwindMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-vl/UpwindMomentumY.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h similarity index 57% rename from src/Examples/flow-vl/UpwindMomentumY.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h index 4b5a7bcb26d049c2773790857d3f79246488b55b..65ac8482807903cb2e98f8fbc25a4627d1ef7a4b 100644 --- a/src/Examples/flow-vl/UpwindMomentumY.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumY.h - description + VanLeerMomentumY.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "VanLeerMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumY +class VanLeerMomentumY { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "VanLeerMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "VanLeerMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -128,20 +131,21 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 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& 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 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 ]; @@ -155,23 +159,23 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -185,18 +189,8 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -220,14 +214,15 @@ class UpwindMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -241,7 +236,7 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumY< " ) + + return String( "VanLeerMomentumY< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -257,32 +252,33 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 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& 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& 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& 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& 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 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 ]; @@ -300,45 +296,45 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_y_center, velocity_x_center, pressure_center ) @@ -358,26 +354,8 @@ class UpwindMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-vl/UpwindMomentumZ.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h similarity index 59% rename from src/Examples/flow-vl/UpwindMomentumZ.h rename to src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h index 887eec977517e5850db2085835d8242d63605c96..125166cb885b65a8f14049a90dcf92449d644498 100644 --- a/src/Examples/flow-vl/UpwindMomentumZ.h +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumZ.h - description + VanLeerMomentumZ.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -13,29 +13,31 @@ #include #include -#include "UpwindMomentumBase.h" +#include "VanLeerMomentumBase.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumZ +class VanLeerMomentumZ { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -49,7 +51,7 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "VanLeerMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -90,14 +92,15 @@ class UpwindMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -111,7 +114,7 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "VanLeerMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -151,14 +154,15 @@ class UpwindMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Ind template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindMomentumBase< MeshType, Real, Index > BaseType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -172,7 +176,7 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde static String getType() { - return String( "UpwindMomentumZ< " ) + + return String( "VanLeerMomentumZ< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -188,32 +192,33 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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 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& 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& 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& 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& 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 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 ]; @@ -231,45 +236,45 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveOtherMomentumFlux( density_center, velocity_z_center, velocity_x_center, pressure_center ) @@ -289,29 +294,8 @@ class UpwindMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Inde - 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; + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..bdfc5be328e1f9047dddf9521cb8483b94ffdc8f --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h @@ -0,0 +1,448 @@ +/*************************************************************************** + VanLeerTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->rightHandSide.setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->rightHandSide.setViscosityConstant( ViscosityConstant ); + } + + RealType positiveTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) 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 turbulentEnergy * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ); + else + return turbulentEnergy * velocity; + }; + + RealType negativeTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return turbulentEnergy * velocity; + else if ( machNumber <= 1.0 ) + return - turbulentEnergy * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovContinuityOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovContinuityOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..8d57805635871b94f8b65ecd2c6167345d256972 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovContinuityOperatorRightHandSide.h @@ -0,0 +1,218 @@ +/*************************************************************************** + PrandtlKolmogorovContinuityOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovContinuityRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + protected: + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovContinuityRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlKolmogorovContinuityRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovContinuityRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovContinuityRightHandSideBase< 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" ); + + return 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 PrandtlKolmogorovContinuityRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovContinuityRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovContinuityRightHandSideBase< 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" ); + + return 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 PrandtlKolmogorovContinuityRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovContinuityRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovContinuityRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovEnergyOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..23989021f80059acabdb3a5dec9e12e5d99ba2fd --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovEnergyOperatorRightHandSide.h @@ -0,0 +1,687 @@ +/*************************************************************************** + PrandtlKolmogorovEnergyOperatorRightHandSide.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 +#include + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + PrandtlKolmogorovEnergyRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovEnergyRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlKolmogorovEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D uT_11_x + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west + - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D_t_11_x + + + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + + + 2.0 / 3.0 * ( velocity_x_east * density_east * turbulentEnergy_east + - velocity_x_west * density_west * turbulentEnergy_west + ) * hxInverse / 2; + } + + /*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 PrandtlKolmogorovEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + 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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + - velocity_x_center * velocity_x_center + velocity_x_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_south + - velocity_x_northWest * velocity_y_north + velocity_x_southWest * velocity_y_south + ) * hxInverse * hyInverse / 4 + ) * this->dynamicalViscosity +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( velocity_x_east * density_east * turbulentEnergy_east + - velocity_x_west * density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ); + } + + /*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 PrandtlKolmogorovEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + 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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// wT_13_x + + ( ( velocity_x_upEast * velocity_z_east - velocity_x_downEast * velocity_z_east + - velocity_x_upWest * velocity_z_west + velocity_x_downWest * velocity_z_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center - velocity_z_center * velocity_z_west + - velocity_z_center * velocity_z_center + velocity_z_west * velocity_z_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + + velocity_x_center * velocity_x_center + velocity_x_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_23_y + + ( ( velocity_y_upNorth * velocity_z_north - velocity_y_downNorth * velocity_y_north + - velocity_y_upSouth * velocity_z_south + velocity_y_downSouth * velocity_z_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center - velocity_z_center * velocity_z_south + - velocity_z_center * velocity_z_center + velocity_z_south * velocity_z_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// uT_31_z + + ( ( velocity_x_up * velocity_x_center - velocity_x_center * velocity_x_center + - velocity_x_center * velocity_x_down + velocity_x_down * velocity_x_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up - velocity_z_downEast * velocity_x_down + - velocity_z_upWest * velocity_x_up + velocity_z_downWest * velocity_x_down + ) * hxInverse * hzInverse / 4 + ) * this->dynamicalViscosity +// T_32_z + + ( ( velocity_z_upNorth * velocity_y_up - velocity_z_downNorth * velocity_y_down + - velocity_z_upSouth * velocity_y_up + velocity_z_downSouth * velocity_y_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center - velocity_x_center * velocity_y_down + - velocity_x_center * velocity_y_center + velocity_x_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 +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upEast * velocity_x_east * turbulentViscosity_east - velocity_z_downEast * velocity_x_east * turbulentViscosity_east + - velocity_z_upWest * velocity_x_west * turbulentViscosity_west + velocity_z_downWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// wt_13_x + + ( ( velocity_x_upEast * velocity_z_east * turbulentViscosity_east - velocity_x_downEast * velocity_z_east * turbulentViscosity_east + - velocity_x_upWest * velocity_z_west * turbulentViscosity_west + velocity_x_downWest * velocity_z_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_west * turbulentViscosity_west + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_west * velocity_z_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + + velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upNorth * velocity_y_north * turbulentViscosity_north - velocity_z_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_z_upSouth * velocity_y_south * turbulentViscosity_south + velocity_z_downSouth * velocity_y_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// wt_23_y + + ( ( velocity_y_upNorth * velocity_z_north * turbulentViscosity_north - velocity_y_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_y_upSouth * velocity_z_south * turbulentViscosity_south + velocity_y_downSouth * velocity_z_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_south * turbulentViscosity_south + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_south * velocity_z_south * turbulentViscosity_south + ) * hySquareInverse + ) +// ut_31_z + + ( ( velocity_x_up * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_center * turbulentViscosity_center + - velocity_x_center * velocity_x_down * turbulentViscosity_down + velocity_x_down * velocity_x_down * turbulentViscosity_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up * turbulentViscosity_up - velocity_z_downEast * velocity_x_down * turbulentViscosity_down + - velocity_z_upWest * velocity_x_up * turbulentViscosity_up + velocity_z_downWest * velocity_x_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + ) +// vt_32_z + + ( ( velocity_z_upNorth * velocity_y_up * turbulentViscosity_up - velocity_z_downNorth * velocity_y_down * turbulentViscosity_down + - velocity_z_upSouth * velocity_y_up * turbulentViscosity_up + velocity_z_downSouth * velocity_y_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center * turbulentViscosity_center - velocity_x_center * velocity_y_down * turbulentViscosity_down + - velocity_x_center * velocity_y_center * turbulentViscosity_center + velocity_x_down * velocity_y_down * turbulentViscosity_down + ) * hzSquareInverse + ) +// wt_33_z + + ( 4.0 / 3.0 * ( velocity_z_up * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_down * turbulentViscosity_down + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_down * velocity_z_down * turbulentViscosity_down + ) * hzSquareInverse + - 2.0 / 3.0 * ( velocity_y_upNorth * velocity_z_up * turbulentViscosity_up - velocity_y_downNorth * velocity_z_down * turbulentViscosity_down + - velocity_y_upSouth * velocity_z_up * turbulentViscosity_up + velocity_y_downSouth * velocity_z_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( velocity_x_upEast * velocity_z_up * turbulentViscosity_up - velocity_x_downEast * velocity_z_down * turbulentViscosity_down + - velocity_x_upWest * velocity_z_up * turbulentViscosity_up + velocity_x_downWest * velocity_z_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_z_up * density_up * turbulentEnergy_up + - velocity_z_down * density_down * turbulentEnergy_down + ) * hzInverse / 2 + ); + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumBaseOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumBaseOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..b56a25b07a5c6e65b3fd56bca6993ec7e49acfcd --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumBaseOperatorRightHandSide.h @@ -0,0 +1,75 @@ +/*************************************************************************** + PrandtlKolmogorovMomentumRightHandSideBase.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 PrandtlKolmogorovMomentumRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + PrandtlKolmogorovMomentumRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumXOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumXOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..d672a28888cab003c45774f6219ad1c221c56eaf --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumXOperatorRightHandSide.h @@ -0,0 +1,450 @@ +/*************************************************************************** + PrandtlKolmogorovMomentumXRightHandSide.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 +#include +#include "PrandtlKolmogorovMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovMomentumXRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlKolmogorovMomentumXRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< 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& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D T_11_x + 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D t_11_x + + + 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2; + } + + /*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 PrandtlKolmogorovMomentumXRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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 + ) * hySquareInverse + ) * this->dynamicalViscosity +// t_11_x + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ); + + } + + /*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 PrandtlKolmogorovMomentumXRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_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 + ) * hxSquareInverse + ) * this->dynamicalViscosity +// T_31_z + + ( ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse / 4 + + ( velocity_x_up - 2 * velocity_x_center + velocity_x_down + ) * hzSquareInverse + ) * this->dynamicalViscosity +//t_11_x + + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_east * (velocity_z_upEast - velocity_z_downEast ) - turbulentViscosity_west * ( velocity_z_upWest - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ) +// t_31_z + + ( ( turbulentViscosity_up * ( velocity_z_upEast - velocity_z_upWest ) - turbulentViscosity_down * ( velocity_z_downEast - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_x_up - ( turbulentViscosity_up + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_down + ) * hzSquareInverse + ); + + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumYOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumYOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..1e5f64b41f32e638509e80b0f4da20c0cb6bbf05 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumYOperatorRightHandSide.h @@ -0,0 +1,417 @@ +/*************************************************************************** + PrandtlKolmogorovMomentumYRightHandSide.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 +#include +#include "PrandtlKolmogorovMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovMomentumYRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlKolmogorovMomentumYRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< 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 PrandtlKolmogorovMomentumYRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + + return +// 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 + + +// t_22_y + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( density_north * turbulentEnergy_north + - density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// t_12_x + + ( ( turbulentViscosity_east * (velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * (velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ); + } + + /*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 PrandtlKolmogorovMomentumYRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_12_y + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east - 2 * velocity_y_center + velocity_y_west + ) * hxSquareInverse + ) * 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_up - 2 * velocity_y_center + velocity_y_down + ) * hzSquareInverse + ) * this->dynamicalViscosity + + +// t_12_x + ( ( turbulentViscosity_east * ( velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * ( velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ) +// t_22_y + + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_south * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_z_upNorth - velocity_z_downNorth ) - turbulentViscosity_south * ( velocity_z_upSouth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_north * turbulentEnergy_north + - density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// t_32_z + + ( ( turbulentViscosity_up * ( velocity_z_upNorth - velocity_z_upSouth ) - turbulentViscosity_down * ( velocity_z_downNorth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_y_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_down + ) * hzSquareInverse + ); + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumZOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumZOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..b4b196369900a39cff6c74ff39e5214e9962678f --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovMomentumZOperatorRightHandSide.h @@ -0,0 +1,343 @@ +/*************************************************************************** + PrandtlKolmogorovMomentumZRightHandSide.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 +#include +#include "PrandtlKolmogorovMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovMomentumZRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlKolmogorovMomentumZRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< 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 PrandtlKolmogorovMomentumZRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< 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 PrandtlKolmogorovMomentumZRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_13_x + ( ( velocity_z_east - 2 * velocity_z_center + velocity_z_west ) + * hxSquareInverse + + ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) + * hxInverse * hzInverse / 4 + ) + * this->dynamicalViscosity +// T_23_y + + ( ( velocity_y_upNorth - velocity_y_downNorth - velocity_y_upSouth + velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + + ( velocity_z_north - 2 * velocity_z_center + velocity_z_south ) + * hySquareInverse + ) + * 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 +// t_13_x + + ( ( turbulentViscosity_east * velocity_z_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_west ) + * hxSquareInverse + + ( turbulentViscosity_east * ( velocity_x_upEast - velocity_x_downEast ) - turbulentViscosity_west * ( velocity_x_upWest - velocity_x_downWest ) ) + * hxInverse * hzInverse / 4 + ) +// t_23_y + + ( ( turbulentViscosity_north * ( velocity_y_upNorth - velocity_y_downNorth ) - turbulentViscosity_south * ( velocity_y_upSouth - velocity_y_downSouth ) ) + * hyInverse * hzInverse / 4 + + ( turbulentViscosity_north * velocity_z_north - (turbulentViscosity_north + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_south ) + * hySquareInverse + ) +// t_33_z + + ( 4.0 / 3.0 * ( turbulentViscosity_up * velocity_z_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_down ) + * hzSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_y_upNorth - turbulentViscosity_down * velocity_y_downNorth - turbulentViscosity_up * velocity_y_upSouth + turbulentViscosity_down * velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_x_upEast - turbulentViscosity_down * velocity_x_downEast - turbulentViscosity_up * velocity_x_upWest + turbulentViscosity_down * velocity_x_downWest ) + * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_up * turbulentEnergy_up + - density_down * turbulentEnergy_down + ) * hzInverse / 2 + ); + } + + /*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/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..b437cc7aa37797a0d96a038ac7c4f6913d438bca --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h @@ -0,0 +1,160 @@ +/*************************************************************************** + PrandtlKolmogorovOpratorRightHandSide.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 +#include +#include + +#include "PrandtlKolmogorovContinuityOperatorRightHandSide.h" +#include "PrandtlKolmogorovEnergyOperatorRightHandSide.h" +#include "PrandtlKolmogorovMomentumXOperatorRightHandSide.h" +#include "PrandtlKolmogorovMomentumYOperatorRightHandSide.h" +#include "PrandtlKolmogorovMomentumZOperatorRightHandSide.h" +#include "PrandtlKolmogorovTurbulentEnergyOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovOperatorRightHandSide +{ + 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 PrandtlKolmogorovContinuityRightHandSide< Mesh, Real, Index > ContinuityOperatorRightHandSideType; + typedef PrandtlKolmogorovMomentumXRightHandSide< Mesh, Real, Index > MomentumXOperatorRightHandSideType; + typedef PrandtlKolmogorovMomentumYRightHandSide< Mesh, Real, Index > MomentumYOperatorRightHandSideType; + typedef PrandtlKolmogorovMomentumZRightHandSide< Mesh, Real, Index > MomentumZOperatorRightHandSideType; + typedef PrandtlKolmogorovEnergyRightHandSide< Mesh, Real, Index > EnergyOperatorRightHandSideType; + typedef PrandtlKolmogorovTurbulentEnergyRightHandSide< Mesh, Real, Index > TurbulentEnergyOperatorRightHandSideType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorRightHandSideType > ContinuityOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumXOperatorRightHandSideType > MomentumXOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumYOperatorRightHandSideType > MomentumYOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumZOperatorRightHandSideType > MomentumZOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< EnergyOperatorRightHandSideType > EnergyOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorRightHandSideType > TurbulentEnergyOperatorRightHandSidePointer; + + 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 ); + } + + PrandtlKolmogorovOperatorRightHandSide() + : dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + return true; + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + this->continuityOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumXOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumYOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumZOperatorRightHandSidePointer->setVelocity( velocity ); + this->energyOperatorRightHandSidePointer->setVelocity( velocity ); + this->turbulentEnergyOperatorRightHandSidePointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->momentumXOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorRightHandSidePointer->setDensity( density ); + this->momentumYOperatorRightHandSidePointer->setDensity( density ); + this->momentumZOperatorRightHandSidePointer->setDensity( density ); + this->energyOperatorRightHandSidePointer->setDensity( density ); + this->turbulentEnergyOperatorRightHandSidePointer->setDenity( density ); + } + + const ContinuityOperatorRightHandSidePointer& getContinuityOperatorRightHandSide() const + { + return this->continuityOperatorRightHandSidePointer; + } + + const MomentumXOperatorRightHandSidePointer& getMomentumXOperatorRightHandSide() const + { + return this->momentumXOperatorRightHandSidePointer; + } + + const MomentumYOperatorRightHandSidePointer& getMomentumYOperatorRightHandSide() const + { + return this->momentumYOperatorRightHandSidePointer; + } + + const MomentumZOperatorRightHandSidePointer& getMomentumZOperatorRightHandSide() const + { + return this->momentumZOperatorRightHandSidePointer; + } + + const EnergyOperatorRightHandSidePointer& getEnergyOperatorRightHandSide() const + { + return this->energyOperatorRightHandSidePointer; + } + + const TurbulentEnergyOperatorRightHandSidePointer& getTurbulentEnergyOperatorRightHandSide() const + { + return this->turbulentEnergyOperatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorRightHandSidePointer continuityOperatorPointer; + MomentumXOperatorRightHandSidePointer momentumXOperatorPointer; + MomentumYOperatorRightHandSidePointer momentumYOperatorPointer; + MomentumZOperatorRightHandSidePointer momentumZOperatorPointer; + EnergyOperatorRightHandSidePointer energyOperatorPointer; + TurbulentEnergyOperatorRightHandSidePointer turbulentEnergyOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovTurbulentEnergyOperatorRightHandSide.h b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovTurbulentEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..3e7e370b11448234d0a9b4b7bf8e39c61fa6c057 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovTurbulentEnergyOperatorRightHandSide.h @@ -0,0 +1,574 @@ +/*************************************************************************** + PrandtlKolmogorovTurbulentEnergyOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovTurbulentEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + + + static String getType() + { + return String( "LaxFridrichsTurbulentEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setCharacteristicLength( const RealType& characteristicLength ) + { + this->characteristicLength = characteristicLength; + } + + void setViscosityConstant( const RealType& viscosityConstant ) + { + this->viscosityConstant = viscosityConstant; + } + + void setSigmaK( const RealType& sigmaK ) + { + this->sigmaK = sigmaK; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + void setCaracteristicLength( RealType& characteristicLength ) + { + this->characteristicLength = characteristicLength; + } + + void setSigmaK( RealType& sigmaK ) + { + this->sigmaK = sigmaK; + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->viscosityConstant = ViscosityConstant; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; + + RealType characteristicLength; + + RealType viscosityConstant; + + RealType sigmaK; +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlKolmogorovTurbulentEnergyRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlKolmogorovTurbulentEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovTurbulentEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovTurbulentEnergyRightHandSideBase< 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 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return + 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + - density_center / this->characteristicLength * std::pow( std::abs( turbulentEnergy_center ), 2.0 / 3.0 ) + + + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaK; + } + + /*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 PrandtlKolmogorovTurbulentEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovTurbulentEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovTurbulentEnergyRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return + ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + + - density_center / this->characteristicLength * std::pow( std::abs( turbulentEnergy_center ), 2.0 / 3.0 ) + + + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_north - 2 * turbulentEnergy_center + turbulentEnergy_south ) + * hySquareInverse + + ( turbulentEnergy_north * turbulentViscosity_north - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_north + turbulentEnergy_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaK; + } + + /*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 PrandtlKolmogorovTurbulentEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlKolmogorovTurbulentEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlKolmogorovTurbulentEnergyRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 3D uT_11_x + ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_x_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 +// vT_12_x + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 +// wT_13_x + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_east - velocity_z_west ) * hxInverse / 2 +// uT_21_y + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 +// 3D vT_22_y + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 +// wT_23_y + + ( ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + + ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_north - velocity_z_south ) * hyInverse / 2 +// uT_31_z + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_up - velocity_x_down ) * hzInverse / 2 +// T_32_z + + ( ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + + ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_up - velocity_y_down ) * hzInverse / 2 +// 3D T_33_z + + ( 4.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + + - density_center / this->characteristicLength * std::pow( std::abs( turbulentEnergy_center ), 2.0 / 3.0 ) + + + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_north - 2 * turbulentEnergy_center + turbulentEnergy_south ) + * hySquareInverse + + ( turbulentEnergy_north * turbulentViscosity_north - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_north + turbulentEnergy_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_up - 2 * turbulentEnergy_center + turbulentEnergy_down ) + * hySquareInverse + + ( turbulentEnergy_up * turbulentViscosity_up - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_up + turbulentEnergy_down * turbulentViscosity_center + ) * hySquareInverse / this->sigmaK; + } + + /*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/src/Examples/flow/PhysicalVariablesGetter.h b/src/Examples/turbulent-flows/one-equation-model/PhysicalVariablesGetter.h similarity index 54% rename from src/Examples/flow/PhysicalVariablesGetter.h rename to src/Examples/turbulent-flows/one-equation-model/PhysicalVariablesGetter.h index d7eeb7618657c34485b3e4842ea04e12d3ee725c..c51e14d659a722c8b8cbec647a4a7989043c7d25 100644 --- a/src/Examples/flow/PhysicalVariablesGetter.h +++ b/src/Examples/turbulent-flows/one-equation-model/PhysicalVariablesGetter.h @@ -79,7 +79,7 @@ class PhysicalVariablesGetter { const RealType e = energy.template getData< DeviceType >()( meshEntity ); const RealType rho = density.template getData< DeviceType >()( meshEntity ); - const RealType momentumNorm = lpNorm( momentum.template getData< DeviceType >().getVector( meshEntity ), 2.0 ); + const RealType momentumNorm = momentum.template getData< DeviceType >().getVector( meshEntity ).lpNorm( 2.0 ); if( rho == 0.0 ) return 0; else @@ -90,6 +90,59 @@ class PhysicalVariablesGetter const MeshFunctionPointer density, energy; const VelocityFieldPointer momentum; const RealType gamma; + }; + + class TurbulentEnergyGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + TurbulentEnergyGetter( MeshFunctionPointer density, + MeshFunctionPointer turbulentEnergyXDensity ) + : density( density ), turbulentEnergyXDensity( turbulentEnergyXDensity ) {} + + 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 turbulentEnergyXDensity.template getData< DeviceType >()( meshEntity ) / + density.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer density, turbulentEnergyXDensity; + }; + + class TurbulentViscosityGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + TurbulentViscosityGetter( MeshFunctionPointer density, + MeshFunctionPointer turbulentEnergy, + RealType viscosityConstant, + RealType specificLength ) + : density( density ), turbulentEnergy( turbulentEnergy ), viscosityConstant( viscosityConstant ), specificLength( specificLength ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + if( turbulentEnergy.template getData< DeviceType >()( meshEntity ) < 0.0 ) + return 0; + else + return density.template getData< DeviceType >()( meshEntity ) * viscosityConstant * specificLength + * std::sqrt(turbulentEnergy.template getData< DeviceType >()( meshEntity ) ); + } + + protected: + const MeshFunctionPointer density, turbulentEnergy; + const RealType viscosityConstant, specificLength; }; @@ -116,6 +169,35 @@ class PhysicalVariablesGetter gamma ); evaluator.evaluate( pressure, pressureGetter ); } + + void getTurbulentEnergy( const ConservativeVariablesPointer& conservativeVariables, + MeshFunctionPointer& turbulentEnergy_no_rho ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, TurbulentEnergyGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< TurbulentEnergyGetter, DeviceType > turbulentEnergyGetter( conservativeVariables->getDensity(), + conservativeVariables->getTurbulentEnergy() ); + evaluator.evaluate( turbulentEnergy_no_rho, turbulentEnergyGetter ); + } + } + + void getTurbulentViscosity( const ConservativeVariablesPointer& conservativeVariables, + MeshFunctionPointer& turbulentEnergy_no_rho, + const RealType& viscosityConstant, + const RealType& specificLength, + MeshFunctionPointer& turbulentViscosity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, TurbulentViscosityGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< TurbulentViscosityGetter, DeviceType > turbulentViscosityGetter( conservativeVariables->getDensity(), + turbulentEnergy_no_rho, + viscosityConstant, + specificLength ); + evaluator.evaluate( turbulentViscosity, turbulentViscosityGetter ); + } + } }; diff --git a/src/Examples/inviscid-flow/RiemannProblemInitialCondition.h b/src/Examples/turbulent-flows/one-equation-model/RiemannProblemInitialCondition.h similarity index 85% rename from src/Examples/inviscid-flow/RiemannProblemInitialCondition.h rename to src/Examples/turbulent-flows/one-equation-model/RiemannProblemInitialCondition.h index a3d54c747562b04f0b7a11dccb472f855dcf9849..b9b190c71ac0359677a0706f86fc5613b6a52b3a 100644 --- a/src/Examples/inviscid-flow/RiemannProblemInitialCondition.h +++ b/src/Examples/turbulent-flows/one-equation-model/RiemannProblemInitialCondition.h @@ -108,6 +108,25 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, Me this->SEDEnergy = SEDEnergy; }; + void setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + void setGamma(RealType gamma) { this->gamma = gamma; @@ -173,9 +192,32 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, Me } }; + + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + }; + PointType discontinuityPlacement; RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; RealType gamma; }; @@ -265,6 +307,25 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M this->SEDEnergy = SEDEnergy; }; + void setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + void setGamma(RealType gamma) { this->gamma = gamma; @@ -394,9 +455,51 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M } }; + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NEDTurbulentEnergy); + } + }; + PointType discontinuityPlacement; RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; RealType gamma; }; @@ -485,6 +588,25 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M this->SEDEnergy = SEDEnergy; }; + void setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + void setGamma(RealType gamma) { this->gamma = gamma; @@ -749,9 +871,92 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M } }; + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SWUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SWUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEUTurbulentEnergy); + } + }; + PointType discontinuityPlacement; RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; RealType gamma; }; @@ -768,7 +973,7 @@ class RiemannProblemInitialCondition static const int Dimensions = MeshType::getMeshDimension(); typedef Containers::StaticVector< Dimensions, RealType > PointType; typedef Functions::MeshFunction< MeshType > MeshFunctionType; - typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Functions::VectorField< Dimensions, MeshType > VectorFieldType; RiemannProblemInitialCondition() @@ -861,6 +1066,7 @@ class RiemannProblemInitialCondition String initial = parameters.getParameter< String >( prefix + "initial" ); if(initial == prefix + "none") { + this->intensity = parameters.getParameter< double >( "turbulence-intensity" ); this->discontinuityPlacement.setup( parameters, prefix + "discontinuity-placement-" ); this->gamma = parameters.getParameter< double >( prefix + "gamma" ); /* @@ -877,49 +1083,56 @@ class RiemannProblemInitialCondition this->NWUPressure = parameters.getParameter< RealType >( prefix + "NWU-pressure" ); this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); this->NWUMomentum = NWUVelocity * NWUDensity; + this->NWUTurbulentEnergy = this->NWUDensity * TurbulentEnergy( NWUVelocity, this->intensity); 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->SWUTurbulentEnergy = SWUDensity * TurbulentEnergy( SWUVelocity, this->intensity); 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->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); this->NWDMomentum = NWDVelocity * NWDDensity; + this->NWDTurbulentEnergy = NWDDensity * TurbulentEnergy( NWDVelocity, this->intensity); 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->SWDTurbulentEnergy = SWDDensity * TurbulentEnergy( SWDVelocity, this->intensity); 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->NEUTurbulentEnergy = NEUDensity * TurbulentEnergy( NEUVelocity, this->intensity); 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->SEUTurbulentEnergy = SEUDensity * TurbulentEnergy( SEUVelocity, this->intensity); 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->NEDTurbulentEnergy = NEDDensity * TurbulentEnergy( NEDVelocity, this->intensity); 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; - + this->SEDTurbulentEnergy = SEDDensity * TurbulentEnergy( SEDVelocity, this->intensity); } if(initial == prefix + "1D_2") predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, @@ -1208,6 +1421,7 @@ class RiemannProblemInitialCondition ) { + this->intensity = 1.0; this->discontinuityPlacement = PointLoad(preDiscX, preDiscY, preDiscZ); this->gamma = preGamma; @@ -1216,51 +1430,56 @@ class RiemannProblemInitialCondition this->NWUPressure = preNWUPressure; this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); this->NWUMomentum = NWUVelocity * NWUDensity; + this->NWUTurbulentEnergy = NWUDensity * TurbulentEnergy( NWUVelocity, this->intensity); this->SWUDensity = preNWUDensity; this->SWUVelocity = PointLoad(preSWUVelocityX, preSWUVelocityY, preSWUVelocityZ); this->SWUPressure = preSWUPressure; this->SWUEnergy = Energy( SWUDensity, SWUPressure, gamma, SWUVelocity); this->SWUMomentum = SWUVelocity * SWUDensity; + this->SWUTurbulentEnergy = SWUDensity * TurbulentEnergy( SWUVelocity, this->intensity); this->NWDDensity = preNWDDensity; this->NWDVelocity = PointLoad(preNWDVelocityX, preNWDVelocityY, preNWDVelocityZ); this->NWDPressure = preNWDPressure; this->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); this->NWDMomentum = NWDVelocity * NWDDensity; + this->NWDTurbulentEnergy = NWDDensity * TurbulentEnergy( NWDVelocity, this->intensity); this->SWDDensity = preSWDDensity; this->SWDVelocity = PointLoad(preSWDVelocityX, preSWDVelocityY, preSWDVelocityZ); this->SWDPressure = preSWDPressure; this->SWDEnergy = Energy( SWDDensity, SWDPressure, gamma, SWDVelocity); this->SWDMomentum = SWDVelocity * SWDDensity; + this->SWDTurbulentEnergy = SWDDensity * TurbulentEnergy( SWDVelocity, this->intensity); this->NEUDensity = preNEUDensity; this->NEUVelocity = PointLoad(preNEUVelocityX, preNEUVelocityY, preNEUVelocityZ); this->NEUPressure = preNEUPressure; this->NEUEnergy = Energy( NEUDensity, NEUPressure, gamma, NEUVelocity); this->NEUMomentum = NEUVelocity * NEUDensity; + this->NEUTurbulentEnergy = NEUDensity * TurbulentEnergy( NEUVelocity, this->intensity); this->SEUDensity = preSEUDensity; this->SEUVelocity = PointLoad(preSEUVelocityX, preSEUVelocityY, preSEUVelocityZ); this->SEUPressure = preSEUPressure; this->SEUEnergy = Energy( SEUDensity, SEUPressure, gamma, SEUVelocity); this->SEUMomentum = SEUVelocity * SEUDensity; + this->SEUTurbulentEnergy = TurbulentEnergy( SEUVelocity, this->intensity); this->NEDDensity = preNEDDensity; this->NEDVelocity = PointLoad(preNEDVelocityX, preNEDVelocityY, preNEDVelocityZ); this->NEDPressure = preNEDPressure; this->NEDEnergy = Energy( NEDDensity, NEDPressure, gamma, NEDVelocity); this->NEDMomentum = NEDVelocity * NEDDensity; + this->NEDTurbulentEnergy = NEDDensity * TurbulentEnergy( NEDVelocity, this->intensity); 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; + this->SEDTurbulentEnergy = SEDDensity * TurbulentEnergy( SEDVelocity, this->intensity); } @@ -1291,11 +1510,26 @@ class RiemannProblemInitialCondition 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 ))); + case 3: energy = (Pressure / (gamma -1.0) + 0.5 * Density * (std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 2 ], 2 ))); break; // druhou mocninu ps8t jako sou4in } return energy; } + + RealType TurbulentEnergy( PointType Velocity, RealType intensity ) + { + RealType turbulentEnergy; + switch (Dimensions) + { + case 1: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ))); + break; + case 2: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ))); + break; + case 3: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 2 ], 2 ))); + break; // druhou mocninu ps8t jako sou4in + } + return turbulentEnergy; + } void setInitialCondition( CompressibleConservativeVariables< MeshType >& conservativeVariables, const PointType& center = PointType( 0.0 ) ) @@ -1326,10 +1560,19 @@ class RiemannProblemInitialCondition this->NEDEnergy, this->SWDEnergy, this->SEDEnergy); + variablesSetter->setTurbulentEnergy(this->NWUTurbulentEnergy, + this->NEUTurbulentEnergy, + this->SWUTurbulentEnergy, + this->SEUTurbulentEnergy, + this->NWDTurbulentEnergy, + this->NEDTurbulentEnergy, + this->SWDTurbulentEnergy, + this->SEDTurbulentEnergy); variablesSetter->setDiscontinuity(this->discontinuityPlacement); variablesSetter->placeDensity(conservativeVariables); variablesSetter->placeMomentum(conservativeVariables); variablesSetter->placeEnergy(conservativeVariables); + variablesSetter->placeTurbulentEnergy(conservativeVariables); // for cyklus i = 0 to mesh.getDimensions().x() j pro .y() a k pro .z() // typedef typename MeshType::Cell CellType @@ -1342,7 +1585,7 @@ class RiemannProblemInitialCondition typedef Functions::Analytic::VectorNorm< Dimensions, RealType > VectorNormType; typedef Operators::Analytic::Sign< Dimensions, RealType > SignType; typedef Functions::OperatorFunction< SignType, VectorNormType > InitialConditionType; - typedef Pointers::SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; + typedef SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; InitialConditionPointer initialCondition; initialCondition->getFunction().setCenter( center ); @@ -1407,6 +1650,9 @@ class RiemannProblemInitialCondition 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 NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType intensity; RealType leftDensity, rightDensity; PointType leftVelocity, rightVelocity; RealType leftPressure, rightPressure; diff --git a/src/Examples/turbulent-flows/one-equation-model/flowsBuildConfigTag.h b/src/Examples/turbulent-flows/one-equation-model/flowsBuildConfigTag.h new file mode 100644 index 0000000000000000000000000000000000000000..c40b793b9e237d0ad756a66c57088373cad3e41b --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/flowsBuildConfigTag.h @@ -0,0 +1,72 @@ +#ifndef FLOWSBUILDCONFIGTAG_H_ +#define FLOWSBUILDCONFIGTAG_H_ + +#include +#include + +namespace TNL { + +class flowsBuildConfigTag{}; + +namespace Solvers { + +/**** + * Turn off support for float and long double. + */ +template<> struct ConfigTagReal< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct ConfigTagReal< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct ConfigTagIndex< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct ConfigTagIndex< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +//template< int Dimension > struct ConfigTagDimension< flowsBuildConfigTag, 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< flowsBuildConfigTag, Meshes::Grid< Dimension, Real, Device, Index > > + { enum { enabled = ConfigTagDimension< flowsBuildConfigTag, Dimension >::enabled && + ConfigTagReal< flowsBuildConfigTag, Real >::enabled && + ConfigTagDevice< flowsBuildConfigTag, Device >::enabled && + ConfigTagIndex< flowsBuildConfigTag, Index >::enabled }; }; +*/ +/**** + * Please, chose your preferred time discretisation here. + */ +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ExplicitTimeDiscretisationTag >{ enum { enabled = true }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, SemiImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; + +/**** + * Only the Runge-Kutta-Merson solver is enabled by default. + */ +template<> struct ConfigTagExplicitSolver< flowsBuildConfigTag, ExplicitEulerSolverTag >{ enum { enabled = true }; }; + +} // namespace Solvers + +namespace Meshes { +namespace BuildConfigTags { + +template< int Dimensions > struct GridDimensionTag< flowsBuildConfigTag, Dimensions >{ enum { enabled = true }; }; + +/**** + * Turn off support for float and long double. + */ +template<> struct GridRealTag< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct GridRealTag< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct GridIndexTag< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct GridIndexTag< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +} // namespace BuildConfigTags +} // namespace Meshes +} // namespace TNL + +#endif /* FLOWSBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/inviscid-flow/eulerRhs.h b/src/Examples/turbulent-flows/one-equation-model/flowsRhs.h similarity index 71% rename from src/Examples/inviscid-flow/eulerRhs.h rename to src/Examples/turbulent-flows/one-equation-model/flowsRhs.h index 51d4e024398d579f49c158292e2890536a1e319c..e0b8c7fac887f2b8ea588020ede105d9c8950888 100644 --- a/src/Examples/inviscid-flow/eulerRhs.h +++ b/src/Examples/turbulent-flows/one-equation-model/flowsRhs.h @@ -1,11 +1,11 @@ -#ifndef eulerRHS_H_ -#define eulerRHS_H_ +#ifndef FLOWSRHS_H_ +#define FLOWSRHS_H_ #include namespace TNL { -template< typename Mesh, typename Real >class eulerRhs +template< typename Mesh, typename Real >class flowsRhs : public Functions::Domain< Mesh::getMeshDimension(), Functions::MeshDomain > { public: @@ -24,12 +24,12 @@ template< typename Mesh, typename Real >class eulerRhs Real operator()( const MeshEntity& entity, const Real& time = 0.0 ) const { - typedef typename MeshEntity::MeshType::PointType PointType; - PointType v = entity.getCenter(); +// typedef typename MeshEntity::MeshType::PointType PointType; +// PointType v = entity.getCenter(); return 0.0; } }; } //namespace TNL -#endif /* eulerRHS_H_ */ +#endif /* FLOWSRHS_H_ */ diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.cpp b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b4d7cae11b57c415ca72427eff803d1cbdb1e2c --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.cpp @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.cu b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.cu new file mode 100644 index 0000000000000000000000000000000000000000..0b4d7cae11b57c415ca72427eff803d1cbdb1e2c --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.cu @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.h b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.h new file mode 100644 index 0000000000000000000000000000000000000000..7390dc6d92f3f6e69f51ede5d8d71b255720a1a4 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModel.h @@ -0,0 +1,276 @@ +#include +#include +#include +#include +#include +#include "oneEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/One-Equation-Turbulence-Model/Lax-Friedrichs/LaxFridrichs.h" +#include "DifferentialOperators/One-Equation-Turbulence-Model/Steger-Warming/StegerWarming.h" +#include "DifferentialOperators/One-Equation-Turbulence-Model/VanLeer/VanLeer.h" +#include "DifferentialOperators/One-Equation-Turbulence-Model/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 oneEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "differential-operator", "Choose the differential operator.", "Lax-Friedrichs"); + config.addEntryEnum< String >( "Lax-Friedrichs" ); + config.addEntryEnum< String >( "Steger-Warming" ); + config.addEntryEnum< String >( "VanLeer" ); + config.addEntryEnum< String >( "AUSMPlus" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class oneEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef oneEquationTurbulenceModelOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + String differentialOperatorType = parameters.getParameter< String >( "differential-operator"); + if( differentialOperatorType == "Lax-Friedrichs" ) + { + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "Steger-Warming" ) + { + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "VanLeer" ) + { + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "AUSMPlus" ) + { + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + + + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< oneEquationTurbulenceModelSetter, oneEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.cpp b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0dbfccb3b5947e91f3a823414cbc051cecf7a23e --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.cpp @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.cu b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.cu new file mode 100644 index 0000000000000000000000000000000000000000..0dbfccb3b5947e91f3a823414cbc051cecf7a23e --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.cu @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.h b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..3b46c200417d2fb61a34fb9fa7f2933c9a6b8259 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelAUSMPlus.h @@ -0,0 +1,142 @@ +//#include +#include +#include +#include +#include +#include +#include "oneEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/One-Equation-turbulence-model/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 oneEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "characteristic-length", "Value of characteristic mixing length", 1.0 ); + config.addEntry< double >( "viscosity-constant", "Value of viscosity constant", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + AUSMPlus< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class oneEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlKolmogorovOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< oneEquationTurbulenceModelSetter, oneEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.cpp b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d2b3d16c414b8f0d9667fe026f0c041ecb116af0 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.cpp @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.cu b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.cu new file mode 100644 index 0000000000000000000000000000000000000000..d2b3d16c414b8f0d9667fe026f0c041ecb116af0 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.cu @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.h b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..8a3611b5318380b01529030a089f3eafe4c3df1a --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelLaxFriedrichs.h @@ -0,0 +1,142 @@ +//#include +#include +#include +#include +#include +#include +#include "oneEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/One-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 oneEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "characteristic-length", "Value of characteristic mixing length", 1.0 ); + config.addEntry< double >( "viscosity-constant", "Value of viscosity constant", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class oneEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlKolmogorovOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< oneEquationTurbulenceModelSetter, oneEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/flow/navierStokesProblem.h b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelProblem.h similarity index 64% rename from src/Examples/flow/navierStokesProblem.h rename to src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelProblem.h index f42c2ed09908b4c73cfab906f9fcecfe5101201d..bb8ae1afd80f62bff0a7e308cc6064ab2b758e13 100644 --- a/src/Examples/flow/navierStokesProblem.h +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelProblem.h @@ -1,5 +1,5 @@ /*************************************************************************** - navierStokesProblem.h - description + oneEquationTurbulenceModelProblem.h - description ------------------- begin : Feb 13, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -12,7 +12,7 @@ #include #include -#include +#include #include "CompressibleConservativeVariables.h" @@ -23,9 +23,9 @@ namespace TNL { template< typename Mesh, typename BoundaryCondition, typename RightHandSide, - typename InviscidOperators, - typename Communicator > -class navierStokesProblem: + typename Communicator, + typename InviscidOperators > +class oneEquationTurbulenceModelProblem: public PDEProblem< Mesh, Communicator, typename InviscidOperators::RealType, @@ -38,12 +38,13 @@ class navierStokesProblem: typedef typename Mesh::DeviceType DeviceType; typedef typename InviscidOperators::IndexType IndexType; typedef PDEProblem< Mesh, Communicator, RealType, DeviceType, IndexType > BaseType; + + typedef Communicator CommunicatorType; using typename BaseType::MeshType; using typename BaseType::MeshPointer; using typename BaseType::DofVectorType; using typename BaseType::DofVectorPointer; - static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::MeshFunction< Mesh > MeshFunctionType; @@ -55,9 +56,8 @@ class navierStokesProblem: typedef Pointers::SharedPointer< InviscidOperators > InviscidOperatorsPointer; typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - using CommunicatorType = Communicator; - static String getTypeStatic(); + static String getType(); String getPrologHeader() const; @@ -79,18 +79,16 @@ class navierStokesProblem: IndexType getDofs() const; - void bindDofs(DofVectorPointer& dofs ); + void bindDofs( DofVectorPointer& dofs ); void getExplicitUpdate( const RealType& time, const RealType& tau, DofVectorPointer& _u, DofVectorPointer& _fu ); + void applyBoundaryConditions( const RealType& time, - DofVectorPointer& dofs ) - { - throw Exceptions::NotImplementedError("TODO:Implement"); - } + DofVectorPointer& dofs ); template< typename Matrix > void assemblyLinearSystem( const RealType& time, @@ -112,17 +110,36 @@ class navierStokesProblem: ConservativeVariablesPointer conservativeVariables, conservativeVariablesRHS; + + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::ContinuityOperatorType, typename BoundaryCondition::DensityBoundaryConditionsType, RightHandSide > explicitUpdaterContinuity; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumXOperatorType, typename BoundaryCondition::MomentumXBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumX; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumYOperatorType, typename BoundaryCondition::MomentumYBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumY; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumZOperatorType, typename BoundaryCondition::MomentumZBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumZ; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::EnergyOperatorType, typename BoundaryCondition::EnergyBoundaryConditionsType, RightHandSide > explicitUpdaterEnergy; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::TurbulentEnergyOperatorType, typename BoundaryCondition::TurbulentEnergyBoundaryConditionsType, RightHandSide > explicitUpdaterTurbulentEnergy; + VelocityFieldPointer velocity; MeshFunctionPointer pressure; + MeshFunctionPointer turbulentViscosity; + MeshFunctionPointer turbulentEnergy; RealType gamma; RealType speedIncrement; RealType cavitySpeed; RealType speedIncrementUntil; + RealType finalSpeed; + RealType startSpeed; + RealType speedIncrementUntilHThrottle; + RealType finalSpeedHThrottle; + RealType startSpeedHThrottle; + RealType characteristicLength; + RealType sigmaK; + RealType viscosityConstant; + RealType intensity; }; } // namespace TNL -#include "navierStokesProblem_impl.h" +#include "oneEquationTurbulenceModelProblem_impl.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelProblem_impl.h b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..0b4699c0f99000077c1b97a5150c66047f30a513 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelProblem_impl.h @@ -0,0 +1,546 @@ +/*************************************************************************** + oneEquationTurbulenceModelProblem_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 +#include +#include +#include +#include +#include + +#include "RiemannProblemInitialCondition.h" +#include "CompressibleConservativeVariables.h" +#include "PhysicalVariablesGetter.h" +#include "oneEquationTurbulenceModelProblem.h" + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getType() +{ + return String( "oneEquationTurbulenceModelProblem< " ) + Mesh :: getType() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getPrologHeader() const +{ + return String( "flow solver" ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, 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 Communicator, + typename InviscidOperators > +bool +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setup( const Config::ParameterContainer& parameters, + const String& prefix ) +{ + if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || + ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || + ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) + return false; + this->gamma = parameters.getParameter< double >( "gamma" ); + this->startSpeed = parameters.getParameter< double >( "start-speed" ); + this->finalSpeed = parameters.getParameter< double >( "final-speed" ); + this->speedIncrementUntil = parameters.getParameter< RealType >( "speed-increment-until" ); + this->startSpeedHThrottle = parameters.getParameter< double >( "start-speed-h-throttle" ); + this->finalSpeedHThrottle = parameters.getParameter< double >( "final-speed-h-throttle" ); + this->speedIncrementUntilHThrottle = parameters.getParameter< RealType >( "speed-increment-until-h-throttle" ); + this->characteristicLength = parameters.getParameter< double >( "characteristic-length" ); + this->viscosityConstant = parameters.getParameter< double >( "viscosity-constant" ); + this->sigmaK = parameters.getParameter< double >( "sigma-k" ); + this->intensity = parameters.getParameter< double >( "turbulence-intensity" ); + velocity->setMesh( this->getMesh() ); + pressure->setMesh( this->getMesh() ); + turbulentViscosity->setMesh( this->getMesh() ); + turbulentEnergy->setMesh( this->getMesh() ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setCharacteristicLength( this->characteristicLength ); + this->inviscidOperatorsPointer->setViscosityConstant( this->viscosityConstant ); + this->inviscidOperatorsPointer->setSigmaK( this->sigmaK ); + this->inviscidOperatorsPointer->setVelocity( this->velocity ); + this->inviscidOperatorsPointer->setPressure( this->pressure ); + this->inviscidOperatorsPointer->setDensity( this->conservativeVariables->getDensity() ); + this->inviscidOperatorsPointer->setGamma( this->gamma ); + this->inviscidOperatorsPointer->setTurbulentViscosity( this->turbulentViscosity ); + this->inviscidOperatorsPointer->setTurbulentEnergy( this->turbulentEnergy ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); + this->explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer->getDensityBoundaryCondition() ); + this->explicitUpdaterContinuity.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumXOperator() ); + this->explicitUpdaterMomentumX.setBoundaryConditions( this->boundaryConditionPointer->getMomentumXBoundaryCondition() ); + this->explicitUpdaterMomentumX.setRightHandSide( this->rightHandSidePointer ); + + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumYOperator() ); + this->explicitUpdaterMomentumY.setBoundaryConditions( this->boundaryConditionPointer->getMomentumYBoundaryCondition() ); + this->explicitUpdaterMomentumY.setRightHandSide( this->rightHandSidePointer ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumZOperator() ); + this->explicitUpdaterMomentumZ.setBoundaryConditions( this->boundaryConditionPointer->getMomentumZBoundaryCondition() ); + this->explicitUpdaterMomentumZ.setRightHandSide( this->rightHandSidePointer ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getEnergyOperator() ); + this->explicitUpdaterEnergy.setBoundaryConditions( this->boundaryConditionPointer->getEnergyBoundaryCondition() ); + this->explicitUpdaterEnergy.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getTurbulentEnergyOperator() ); + this->explicitUpdaterTurbulentEnergy.setBoundaryConditions( this->boundaryConditionPointer->getTurbulentEnergyBoundaryCondition() ); + this->explicitUpdaterTurbulentEnergy.setRightHandSide( this->rightHandSidePointer ); + + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +typename oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >::IndexType +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getDofs() const +{ + /**** + * Return number of DOFs (degrees of freedom) i.e. number + * of unknowns to be resolved by the main solver. + */ + return this->conservativeVariables->getDofs( this->getMesh() ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +bindDofs( DofVectorPointer& dofVector ) +{ + this->conservativeVariables->bind( this->getMesh(), dofVector ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setInitialCondition( const Config::ParameterContainer& parameters, + DofVectorPointer& dofs ) +{ + CompressibleConservativeVariables< MeshType > conservativeVariables; + conservativeVariables.bind( this->getMesh(), 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 Communicator, + typename InviscidOperators > + template< typename Matrix > +bool +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setupLinearSystem( Matrix& matrix ) +{ +/* const IndexType dofs = this->getDofs(); + 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 Communicator, + typename InviscidOperators > +bool +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +makeSnapshot( const RealType& time, + const IndexType& step, + DofVectorPointer& dofs ) +{ + std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; + + this->bindDofs( 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() ) ) + this->conservativeVariables->getDensity()->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "velocity-" ); +// if( ! this->velocity->save( fileName.getFileName() ) ) + this->velocity->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "pressure-" ); +// if( ! this->pressure->save( fileName.getFileName() ) ) + this->pressure->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "energy-" ); +// if( ! this->conservativeVariables->getEnergy()->save( fileName.getFileName() ) ) + this->conservativeVariables->getEnergy()->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "turbulentEnergy-" ); +// if( ! this->conservativeVariables->getEnergy()->save( fileName.getFileName() ) ) + this->conservativeVariables->getTurbulentEnergy()->save( fileName.getFileName() ); +// return false; + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getExplicitUpdate( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + DofVectorPointer& _fu ) +{ + typedef typename MeshType::Cell Cell; + + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), _u ); + this->conservativeVariablesRHS->bind( this->getMesh(), _fu ); + + /**** + * Resolve the physical variables + */ + PhysicalVariablesGetter< typename MeshPointer::ObjectType > physicalVariables; + physicalVariables.getVelocity( this->conservativeVariables, this->velocity ); + physicalVariables.getPressure( this->conservativeVariables, this->gamma, this->pressure ); + physicalVariables.getTurbulentEnergy( this->conservativeVariables, this->turbulentEnergy ); + physicalVariables.getTurbulentViscosity( this->conservativeVariables, this->turbulentEnergy, this->viscosityConstant, this->characteristicLength, this->turbulentViscosity ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setTau( tau ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getDensity(), + this->conservativeVariablesRHS->getDensity() ); + +// this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, +// this->conservativeVariables->getDensity() ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 0 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 0 ] ); //, fuRhoVelocityX ); + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 1 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 1 ] ); //, fuRhoVelocityX ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 2 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 2 ] ); //, fuRhoVelocityX ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); + + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getTurbulentEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getTurbulentEnergy() ); //, fuRhoVelocityX ); + + /*this->conservativeVariablesRHS->getDensity()->write( "density", "gnuplot" ); + this->conservativeVariablesRHS->getEnergy()->write( "energy", "gnuplot" ); + this->conservativeVariablesRHS->getMomentum()->write( "momentum", "gnuplot", 0.05 ); + getchar();*/ + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +applyBoundaryConditions( const RealType& time, + DofVectorPointer& dofs ) +{ + /**** + * Update Boundary Conditions + */ + if(this->speedIncrementUntil > time ) + { + this->boundaryConditionPointer->setTimestep(this->speedIncrement); + } + else + { + this->boundaryConditionPointer->setTimestep(0); + } + this->boundaryConditionPointer->setSpeed(this->intensity); + this->boundaryConditionPointer->setIntensity(this->cavitySpeed); + this->boundaryConditionPointer->setCompressibleConservativeVariables(this->conservativeVariables); + this->boundaryConditionPointer->setGamma(this->gamma); + this->boundaryConditionPointer->setPressure(this->pressure); + this->boundaryConditionPointer->setVerticalThrottleSpeed( startSpeed, finalSpeed, time, speedIncrementUntil ); + this->boundaryConditionPointer->setHorizontalThrottleSpeed( startSpeedHThrottle, finalSpeedHThrottle, time, speedIncrementUntilHThrottle ); + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), dofs ); +// this->conservativeVariables->getDensity()->write( "density", "gnuplot" ); +// this->conservativeVariables->getEnergy()->write( "energy", "gnuplot" ); +// this->conservativeVariables->getMomentum()->write( "momentum", "gnuplot", 0.05 ); +// dofs->save("dofs.tnl"); +// getchar(); +// std::cout <<"applyBCC" << std::endl; + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getDensity() ); + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 0 ] ); // uRhoVelocityX, + if( Dimensions > 1 ) + { + + this->explicitUpdaterMomentumY.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 1 ] ); // uRhoVelocityX, + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 2 ] ); // uRhoVelocityX, + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getEnergy() ); // uRhoVelocityX, + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getTurbulentEnergy() ); // uRhoVelocityX, + + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > + template< typename Matrix > +void +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +assemblyLinearSystem( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + Matrix& matrix, + DofVectorPointer& b ) +{ +/* LinearSystemAssembler< Mesh, + MeshFunctionType, + InviscidOperators, + BoundaryCondition, + RightHandSide, + BackwardTimeDiscretisation, + Matrix, + DofVectorType > systemAssembler; + + MeshFunction< Mesh > u( mesh, _u ); + systemAssembler.template assembly< typename Mesh::Cell >( time, + tau, + this->differentialOperator, + this->boundaryCondition, + this->rightHandSide, + u, + matrix, + b );*/ +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +oneEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +postIterate( const RealType& time, + const RealType& tau, + DofVectorPointer& dofs ) +{ + /* + 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/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.cpp b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c436b1a67d2da7e619d221a3be140e47363b971f --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.cpp @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModelStegerWarming.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.cu b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.cu new file mode 100644 index 0000000000000000000000000000000000000000..c436b1a67d2da7e619d221a3be140e47363b971f --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.cu @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModelStegerWarming.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.h b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..7a8798e1218927e1c2398a936a035db7e5479b3f --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelStegerWarming.h @@ -0,0 +1,142 @@ +//#include +#include +#include +#include +#include +#include +#include "oneEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/One-Equation-turbulence-model/Steger-Warming/StegerWarming.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 oneEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "characteristic-length", "Value of characteristic mixing length", 1.0 ); + config.addEntry< double >( "viscosity-constant", "Value of viscosity constant", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + StegerWarming< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class oneEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlKolmogorovOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< oneEquationTurbulenceModelSetter, oneEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.cpp b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..84d00169214911c579f31ee50839bca88bce7f1f --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.cpp @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModelVanLeer.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.cu b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.cu new file mode 100644 index 0000000000000000000000000000000000000000..0b4d7cae11b57c415ca72427eff803d1cbdb1e2c --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.cu @@ -0,0 +1 @@ +#include "oneEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.h b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..76abfba7136414e87b890d05017dfcba2e00373d --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/oneEquationTurbulenceModelVanLeer.h @@ -0,0 +1,142 @@ +//#include +#include +#include +#include +#include +#include +#include "oneEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/One-Equation-turbulence-model/VanLeer/VanLeer.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 oneEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "characteristic-length", "Value of characteristic mixing length", 1.0 ); + config.addEntry< double >( "viscosity-constant", "Value of viscosity constant", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + VanLeer< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class oneEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlKolmogorovOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef oneEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< oneEquationTurbulenceModelSetter, oneEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model new file mode 100644 index 0000000000000000000000000000000000000000..cd0c1bbb1426405814d32e2e1f3222e79bb11c8d --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model @@ -0,0 +1,40 @@ +#!/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-euler-navier-stokes + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --differential-operator Steger-Warming \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-AUSM-plus b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-AUSM-plus new file mode 100644 index 0000000000000000000000000000000000000000..faaad26b48f1fbea1002c066b6bfce61e323b7e7 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-AUSM-plus @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Ausm-Plus + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Lax-Friedrichs b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Lax-Friedrichs new file mode 100644 index 0000000000000000000000000000000000000000..5f7bfbdc6d6e7ebe6dd69663eeea28a5c6dc770f --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Lax-Friedrichs @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Lax-Friedrichs + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Steger-Warming b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Steger-Warming new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Steger-Warming @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Van-Leer b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Van-Leer new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/one-equation-model/run-one-equation-turbulence-model-Van-Leer @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/CMakeLists.txt b/src/Examples/turbulent-flows/two-equation-model/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..982eff3f34ede882e7879cd1dc39ae600850063e --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory( KEPsilon-model ) +add_subdirectory( KOmega-model ) diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..0709bc3b93fb040bb62e479adb611346485af0f6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h @@ -0,0 +1,190 @@ +#include + +#include "DensityBoundaryConditionBoiler.h" +#include "MomentumXBoundaryConditionBoiler.h" +#include "MomentumYBoundaryConditionBoiler.h" +#include "MomentumZBoundaryConditionBoiler.h" +#include "EnergyBoundaryConditionBoiler.h" +#include "TurbulentEnergyBoundaryConditionBoiler.h" +#include "DisipationBoundaryConditionBoiler.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 TNL::Operators::TurbulentEnergyBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DisipationBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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); + this->disipationBoundaryConditionsPointer->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); + this->turbulentEnergyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->disipationBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + void setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + this->disipationBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setLengthScale( const RealType& lengthScale ) + { + this->disipationBoundaryConditionsPointer->setLengthScale ( lengthScale ); + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->disipationBoundaryConditionsPointer->setTurbulenceConstant ( turbulenceConstant ); + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/flow/DensityBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow/DensityBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/DisipationBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/DisipationBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..a94af83b6da07aa1bb13034688792c09a64c9b02 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/DisipationBoundaryConditionBoiler.h @@ -0,0 +1,718 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DisipationBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function> +class DisipationBoundaryConditionsBoilerBase +{ + 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 DisipationBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerBase< 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 DisipationBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerBase< 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 DisipationBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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, 0 >() ]; + /*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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerBase< 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 DisipationBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DisipationBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flow/EnergyBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h similarity index 99% rename from src/Examples/flow/EnergyBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h index a99fdf0157bfcbca614374e8472ab9fe8a3b4f58..412640b5472f0e85026e26954503a6412bba0c39 100644 --- a/src/Examples/flow/EnergyBoundaryConditionBoiler.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h @@ -12,7 +12,6 @@ #pragma once #include -#include "CompressibleConservativeVariables.h" namespace TNL { namespace Operators { diff --git a/src/Examples/flow/MomentumXBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow/MomentumXBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h diff --git a/src/Examples/flow/MomentumYBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow/MomentumYBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h diff --git a/src/Examples/flow/MomentumZBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h similarity index 100% rename from src/Examples/flow/MomentumZBoundaryConditionBoiler.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..e6b63da71803c661c620326a866389de874beca6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h @@ -0,0 +1,664 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsBoilerBase +{ + 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 TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * 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())[ 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * 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, 0 >() ]; + /*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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..44e2b9531ffa6968838775d9084d0f4045004554 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h @@ -0,0 +1,237 @@ +#include + +#include "DensityBoundaryConditionBoilerModel.h" +#include "MomentumXBoundaryConditionBoilerModel.h" +#include "MomentumYBoundaryConditionBoilerModel.h" +#include "MomentumZBoundaryConditionBoilerModel.h" +#include "EnergyBoundaryConditionBoilerModel.h" +#include "TurbulentEnergyBoundaryConditionBoilerModel.h" +#include "DisipationBoundaryConditionBoilerModel.h" + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class BoundaryConditionsBoilerModel +{ + 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::DensityBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::MomentumXBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::MomentumYBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::MomentumZBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::EnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DisipationBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "vertical-angle", "Vertical angle of throttle in degrees", 0 ); + config.addEntry< double >( prefix + "horizontal-angle", "Horizontal angle of throttle in degrees", 45 ); + } + + 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); + setZAngle(parameters.getParameter< double >( prefix + "vertical-angle" ) * M_PI / 180.0 ); + setXYAngle(parameters.getParameter< double >( prefix + "horizontal-angle" ) * M_PI / 180.0 ); + 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); + this->turbulentEnergyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->disipationBoundaryConditionsPointer->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 setZAngle(const RealType zAngle) + { + this->densityBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumXBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumYBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumZBoundaryConditionsPointer->setZAngle(zAngle); + this->energyBoundaryConditionsPointer->setZAngle(zAngle); + this->turbulentEnergyBoundaryConditionsPointer->setZAngle(zAngle); + this->disipationBoundaryConditionsPointer->setZAngle(zAngle); + } + + void setXYAngle(const RealType xYAngle) + { + this->densityBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumXBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumYBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumZBoundaryConditionsPointer->setXYAngle(xYAngle); + this->turbulentEnergyBoundaryConditionsPointer->setXYAngle(xYAngle); + this->disipationBoundaryConditionsPointer->setXYAngle(xYAngle); + } + + 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 setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + this->disipationBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setLengthScale( const RealType& lengthScale ) + { + this->disipationBoundaryConditionsPointer->setLengthScale ( lengthScale ); + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->disipationBoundaryConditionsPointer->setTurbulenceConstant ( turbulenceConstant ); + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType horizontalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + horizontalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + horizontalThrottleSpeed = 0; + else + horizontalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->energyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->turbulentEnergyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->disipationBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType verticalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + verticalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + verticalThrottleSpeed = 0; + else + verticalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->energyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->turbulentEnergyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->disipationBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..a58f32f7c577590801504d675dec55243e2f0b57 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h @@ -0,0 +1,580 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DensityBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class DensityBoundaryConditionsBoilerModelBase +{ + 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 DensityBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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.835 * ( entity.getMesh().getDimensions().y() - 1 )) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ 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, -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 setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 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 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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DensityBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/DisipationBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/DisipationBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..b3f585a9ea3102300059ee8c5ae57efa485d4c0c --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/DisipationBoundaryConditionBoilerModel.h @@ -0,0 +1,892 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DisipationBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class DisipationBoundaryConditionsBoilerModelBase +{ + 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 DisipationBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerModelBase< 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 DisipationBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerModelBase< 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 DisipationBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle Disipation + { + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle Disipation + { + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + } +// if for chimney exit + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerModelBase< 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 DisipationBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DisipationBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..d0475576b5fa910528eaa3c7a80ffd8047bddcc9 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,962 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class EnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class EnergyBoundaryConditionsBoilerModelBase +{ + 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 EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const EnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..893815913ba45510c520de2033d7be690faea8bb --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h @@ -0,0 +1,940 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumXBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumXBoundaryConditionsBoilerModelBase +{ + 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 MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumXBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..e8aa33e885efcc06f134a94f7e6df8cb974fb417 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h @@ -0,0 +1,941 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumYBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumYBoundaryConditionsBoilerModelBase +{ + 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 MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( - 1.0 ) + * std::sin( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) +// down throttle + { + if( + ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumYBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..ee40b1b74066d4c5ee0491345538577525a7e4f5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h @@ -0,0 +1,838 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumZBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumZBoundaryConditionsBoilerModelBase +{ + 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 MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( + ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.408 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumZBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..851b706184862400daae12810271d7ba6c9753e8 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,832 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsBoilerModelBase +{ + 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 TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle TurbulentEnergy + { + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle TurbulentEnergy + { + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + } +// if for chimney exit + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed;; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed;; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed;; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..e2adc74244d8556338b30bc42b94fd5965f56ca6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h @@ -0,0 +1,193 @@ +#include + +#include "DensityBoundaryConditionCavity.h" +#include "MomentumXBoundaryConditionCavity.h" +#include "MomentumYBoundaryConditionCavity.h" +#include "MomentumZBoundaryConditionCavity.h" +#include "EnergyBoundaryConditionCavity.h" +#include "TurbulentEnergyBoundaryConditionCavity.h" +#include "DisipationBoundaryConditionCavity.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 TNL::Operators::TurbulentEnergyBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DisipationBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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); + this->turbulentEnergyBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->disipationBoundaryConditionsPointer->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); + this->turbulentEnergyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->disipationBoundaryConditionsPointer->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); + this->turbulentEnergyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->disipationBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + void setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + this->disipationBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setLengthScale( const RealType& lengthScale ) + { + this->disipationBoundaryConditionsPointer->setLengthScale ( lengthScale ); + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->disipationBoundaryConditionsPointer->setTurbulenceConstant ( turbulenceConstant ); + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/flow-vl/DensityBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h similarity index 99% rename from src/Examples/flow-vl/DensityBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h index 18eaff1101eccc7733eb5978b48807be82bba916..c753d324a288a331dbfb9d73e341fe962f39889e 100644 --- a/src/Examples/flow-vl/DensityBoundaryConditionCavity.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h @@ -253,20 +253,20 @@ class DensityBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIn const IndexType& index = entity.getIndex(); if( entity.getCoordinates().x() == 0 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 1, 0 >() ]; } if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; } if( entity.getCoordinates().y() == 0 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + return u[ 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, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, -1 >() ]; } } diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/DisipationBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/DisipationBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..acee185a2ed1178dbed5052a7862c4a9080102e8 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/DisipationBoundaryConditionCavity.h @@ -0,0 +1,610 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DisipationBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function> +class DisipationBoundaryConditionsCavityBase +{ + 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 DisipationBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 this->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + } + } + + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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->turbulenceConstant + * std::pow( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ), ( 3.0 / 2.0 ) ) + / this->lengthScale; + } + } + + + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DisipationBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flow-sw/EnergyBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h similarity index 97% rename from src/Examples/flow-sw/EnergyBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h index 3b49cd56e5ab6901716c86115561c26fbbbff973..ca5d85442d02edeb7ddd39749c6441c13e3eb6ed 100644 --- a/src/Examples/flow-sw/EnergyBoundaryConditionCavity.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h @@ -12,7 +12,6 @@ #pragma once #include -#include "CompressibleConservativeVariables.h" namespace TNL { namespace Operators { @@ -271,8 +270,8 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd const IndexType& index = entity.getIndex(); if( entity.getCoordinates().x() == 0 ) { - return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; - /* ( (* this->pressure)[ neighborEntities.template getEntityIndex< 1, 0 >() ] + return //u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + ( (* this->pressure)[ neighborEntities.template getEntityIndex< 1, 0 >() ] / ( this->gamma - 1 ) ) + 0 @@ -287,12 +286,12 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd / (* 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 >() ] + return //u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + ( (* this->pressure)[ neighborEntities.template getEntityIndex< -1, 0 >() ] / ( this->gamma - 1 ) ) + 0 @@ -306,12 +305,12 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd / (* 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 >() ] + return //u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 1 >() ] / ( this->gamma - 1 ) ) + 0 @@ -325,7 +324,7 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshInd / (* 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 ) @@ -521,18 +520,18 @@ class EnergyBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshInd + 0.5 * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] * ( - ( this->cavitySpeed + ( this->cavitySpeed/* * ( entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) ) - / ( entity.getMesh().getDimensions().x() / 2 ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ ) * - ( this->cavitySpeed + ( this->cavitySpeed/* * ( entity.getMesh().getDimensions().x() / 2 - std::abs( (entity.getCoordinates().x() - entity.getMesh().getDimensions().x() / 2 ) ) ) - / ( entity.getMesh().getDimensions().x() / 2 ) + / ( entity.getMesh().getDimensions().x() / 2 )*/ ) + ( (* (* this->compressibleConservativeVariables->getMomentum())[ 1 ])[neighborEntities.template getEntityIndex< 0, 0, 0 >()] diff --git a/src/Examples/flow/MomentumXBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow/MomentumXBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h diff --git a/src/Examples/flow/MomentumYBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow/MomentumYBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h diff --git a/src/Examples/flow/MomentumZBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h similarity index 100% rename from src/Examples/flow/MomentumZBoundaryConditionCavity.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..05098c7ddf400f05d49e35794cd92944013cd32a --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h @@ -0,0 +1,568 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsCavityBase +{ + 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 TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 >(), -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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h new file mode 100644 index 0000000000000000000000000000000000000000..8a93fd2fc447a91e7798ffae55c032e60e734e6e --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h @@ -0,0 +1,159 @@ +#include +#include +#include +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function = Functions::Analytic::Constant< Mesh::getMeshDimension(), typename Mesh::RealType >, + int MeshEntitiesDimension = Mesh::getMeshDimension(), + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsDirichlet +{ + 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::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setIntensity(const RealType& intensity) + { + + } + + void setLengthScale( const RealType& lengthScale ) + { + + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h new file mode 100644 index 0000000000000000000000000000000000000000..bc6c4bdecf3ccdd9b49f18574491827d693375ad --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h @@ -0,0 +1,155 @@ +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsNeumann +{ + 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::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setIntensity(const RealType& intensity) + { + + } + + void setLengthScale( const RealType& lengthScale ) + { + + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists.txt b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..950d69b3227e0669bf040f634ff5edbe96aaf8e8 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists.txt @@ -0,0 +1,101 @@ +#k-epsilon-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelLaxFriedrichs.cpp + twoEquationTurbulenceModelLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-epsilon-Lax-Friedrichs twoEquationTurbulenceModelLaxFriedrichs.cu) + target_link_libraries (tnl-k-epsilon-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-epsilon-Lax-Friedrichs twoEquationTurbulenceModelLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-epsilon-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#k-epsilon-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelStegerWarming.cpp + twoEquationTurbulenceModelStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-epsilon-Steger-Warming twoEquationTurbulenceModelStegerWarming.cu) + target_link_libraries (tnl-k-epsilon-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-epsilon-Steger-Warming twoEquationTurbulenceModelStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-epsilon-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#k-epsilon-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelVanLeer.cpp + twoEquationTurbulenceModelVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-epsilon-Van-Leer twoEquationTurbulenceModelVanLeer.cu) + target_link_libraries (tnl-k-epsilon-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-epsilon-Van-Leer twoEquationTurbulenceModelVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-epsilon-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#k-epsilon-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelAUSMPlus.cpp + twoEquationTurbulenceModelAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-epsilon-AUSM-plus twoEquationTurbulenceModelAUSMPlus.cu) + target_link_libraries (tnl-k-epsilon-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-epsilon-AUSM-plus twoEquationTurbulenceModelAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-epsilon-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists_separate.txt b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists_separate.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd8e6f8708f7029abaf81aea4050908eb47bb71b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists_separate.txt @@ -0,0 +1,101 @@ +#navier-stokes-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesLaxFriedrichs.cpp + navierStokesLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cu) + target_link_libraries (tnl-navier-stokes-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesStegerWarming.cpp + navierStokesStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cu) + target_link_libraries (tnl-navier-stokes-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesVanLeer.cpp + navierStokesVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cu) + target_link_libraries (tnl-navier-stokes-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesAUSMPlus.cpp + navierStokesAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cu) + target_link_libraries (tnl-navier-stokes-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists_together.txt b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists_together.txt new file mode 100644 index 0000000000000000000000000000000000000000..f26fc6d34635dad513d36fd9c4ea21d3c1e95489 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CMakeLists_together.txt @@ -0,0 +1,26 @@ +#navier-stokes + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokes.cpp + navierStokes.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cu) + target_link_libraries (tnl-navier-stokes ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..a6c4a7591ebfc730a5d922c55f962bd58696af32 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/CompressibleConservativeVariables.h @@ -0,0 +1,202 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > MomentumFieldPointer; + + CompressibleConservativeVariables(){}; + + CompressibleConservativeVariables( const MeshPointer& meshPointer ) + : density( meshPointer ), + momentum( meshPointer ), + //pressure( meshPointer ), + energy( meshPointer ), + turbulentEnergy( meshPointer ), + disipation( meshPointer ){}; + + void setMesh( const MeshPointer& meshPointer ) + { + this->density->setMesh( meshPointer ); + this->momentum->setMesh( meshPointer ); + //this->pressure.setMesh( meshPointer ); + this->energy->setMesh( meshPointer ); + this->turbulentEnergy->setMesh( meshPointer ); + this->disipation->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 ); + currentOffset += this->energy->getDofs( meshPointer ); + this->turbulentEnergy->bind( meshPointer, data, currentOffset ); + currentOffset += this->turbulentEnergy->getDofs( meshPointer ); + this->disipation->bind( meshPointer, data, currentOffset ); + } + + IndexType getDofs( const MeshPointer& meshPointer ) const + { + return this->density->getDofs( meshPointer ) + + this->momentum->getDofs( meshPointer ) + + this->energy->getDofs( meshPointer ) + + this->turbulentEnergy->getDofs( meshPointer ) + + this->disipation->getDofs( meshPointer ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + const MeshFunctionPointer& getEnergy() const + { + return this->energy; + } + + void setEnergy( MeshFunctionPointer& energy ) + { + this->energy = energy; + } + + __cuda_callable__ + MeshFunctionPointer& getTurbulentEnergy() + { + return this->turbulentEnergy; + } + + __cuda_callable__ + const MeshFunctionPointer& getTurbulentEnergy() const + { + return this->turbulentEnergy; + } + + void setTurbulentEnergy( MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + __cuda_callable__ + MeshFunctionPointer& getDisipation() + { + return this->disipation; + } + + __cuda_callable__ + const MeshFunctionPointer& getDisipation() const + { + return this->disipation; + } + + void setDisipation( MeshFunctionPointer& disipation ) + { + this->disipation = disipation; + } + + void getVelocityField( VelocityFieldType& velocityField ) + { + + } + + protected: + + MeshFunctionPointer density; + MomentumFieldPointer momentum; + MeshFunctionPointer energy; + MeshFunctionPointer turbulentEnergy; + MeshFunctionPointer disipation; + +}; + +} // namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..192a584a53be189b1eb82c148ca11da9e16c66e7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h @@ -0,0 +1,246 @@ +/*************************************************************************** + AUSMPlus.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 +#include +#include + +#include "AUSMPlusContinuity.h" +#include "AUSMPlusEnergy.h" +#include "AUSMPlusMomentumX.h" +#include "AUSMPlusMomentumY.h" +#include "AUSMPlusMomentumZ.h" +#include "AUSMPlusTurbulentEnergy.h" +#include "AUSMPlusDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KEpsilonOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlus +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + typedef AUSMPlusContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef AUSMPlusMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef AUSMPlusMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef AUSMPlusMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef AUSMPlusEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef AUSMPlusTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef AUSMPlusDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + 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 ); + } + + AUSMPlus() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "AUSMPlus" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setGamma( gamma ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + this->disipationOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->disipationOperatorPointer->setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->disipationOperatorPointer->setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..1c90c16623d1878986e129fd00936a6663f5c7e0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h @@ -0,0 +1,401 @@ +/*************************************************************************** + AUSMPlusContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusContinuity< " ) + + 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 DensityFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity + MachBorderMinus * RightDensity ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ], u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->DensityFlux( u[ west ] , u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ] , u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->DensityFlux( u[ down ] , u[ center ], velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->DensityFlux( u[ center ], u[ up ] , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..832e71d243ab3d7e90b80ec88aabc5f62e24bf00 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusDisipation.h @@ -0,0 +1,465 @@ +/*************************************************************************** + AUSMPlusDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusDisipationBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusDisipation< " ) + + 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; + this->rightHandSide.setVelocity( velocity ); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->rightHandSide.setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->rightHandSide.setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + RealType DisipationFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftDisipation, + const RealType& RightDisipation ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDisipation + MachBorderMinus * RightDisipation ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->DisipationFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->DisipationFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->DisipationFlux( density_west , density_center , velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->DisipationFlux( density_center , density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->DisipationFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->DisipationFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->DisipationFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ] , u[ center ] ) + - this->DisipationFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->DisipationFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ] , u[ center ] ) + - this->DisipationFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->DisipationFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ] , u[ center ]) + - this->DisipationFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..3013e563b78a4507379aeae8470a5c5d83c518e0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h @@ -0,0 +1,522 @@ +/*************************************************************************** + AUSMPlusEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + AUSMPlusEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "AUSMPlusEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + RealType EnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftEnergy, + const RealType& RightEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * ( LeftEnergy + LeftPressure) + MachBorderMinus * ( RightEnergy + RightPressure ) ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->EnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ], u[ center ] ) + - this->EnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..e9b5565d73f0eed3785f661b7f1beed03da722e5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h @@ -0,0 +1,206 @@ +/*************************************************************************** + AUSMPlusMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + RealType MainMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + RealType PressureSplitingPlus = 0; + RealType PressureSplitingMinus = 0; + RealType PressureBorder = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + PressureSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + PressureSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) * (2.0 - LeftMachNumber ) + + 3.0 / 16.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + PressureSplitingPlus = 1.0; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + PressureSplitingMinus = 1.0; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + PressureSplitingMinus = 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) * (2.0 + RightMachNumber ) + - 3.0 / 16.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + PressureSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + PressureBorder = PressureSplitingPlus * LeftPressure + PressureSplitingMinus * RightPressure; + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftVelocity + MachBorderMinus * RightDensity * RightVelocity ) + PressureBorder; + } + + RealType OtherMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftOtherVelocity, + const RealType& RightOtherVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftOtherVelocity + MachBorderMinus * RightDensity * RightOtherVelocity ); + } + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..24f4c5e780ecb2d640b65ec8bd139f3207efd9c9 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h @@ -0,0 +1,398 @@ +/*************************************************************************** + AUSMPlusMomentumX.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_x_down , velocity_x_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_x_center, velocity_x_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..d1a8d43041623a06152ac07c2fb114d2095e73ab --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h @@ -0,0 +1,371 @@ +/*************************************************************************** + AUSMPlusMomentumY.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_y_down , velocity_y_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_y_center, velocity_y_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..8915da35c870f05f85e91fa38afda392ad29b23b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h @@ -0,0 +1,316 @@ +/*************************************************************************** + AUSMPlusMomentumZ.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_z_west , velocity_z_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_z_center, velocity_z_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_z_south , velocity_z_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_z_center, velocity_z_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->MainMomentumFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->MainMomentumFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..3c5f77bb4e0398c857249924bf21a5b0275f7052 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h @@ -0,0 +1,450 @@ +/*************************************************************************** + AUSMPlusTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + RealType TurbulentEnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftTurbulentEnergy, + const RealType& RightTurbulentEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftTurbulentEnergy + MachBorderMinus * RightTurbulentEnergy ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center , velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center , density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->TurbulentEnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ] , u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->TurbulentEnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ] , u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->TurbulentEnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ] , u[ center ]) + - this->TurbulentEnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..1167c318bdac46c2fde844f5ef0d820948ad5940 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h @@ -0,0 +1,249 @@ +/*************************************************************************** + 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 +#include +#include + +#include "LaxFridrichsContinuity.h" +#include "LaxFridrichsEnergy.h" +#include "LaxFridrichsMomentumX.h" +#include "LaxFridrichsMomentumY.h" +#include "LaxFridrichsMomentumZ.h" +#include "LaxFridrichsTurbulentEnergy.h" +#include "LaxFridrichsDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KEpsilonOperatorRightHandSide< Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + typedef LaxFridrichsContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef LaxFridrichsMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef LaxFridrichsMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef LaxFridrichsMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef LaxFridrichsEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef LaxFridrichsTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef LaxFridrichsDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "numerical-viscosity", "Value of artificial (numerical) viscosity in the Lax-Fridrichs scheme", 1.0 ); + config.addEntry< double >( prefix + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); + } + + LaxFridrichs() + : artificialViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "Lax-Friedrichs" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + 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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->setTau( tau ); + } + + void setGamma( const RealType& gamma ) + { + } + + 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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->setDensity( density ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->turbulentEnergyOperatorPointer->setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->disipationOperatorPointer->setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->disipationOperatorPointer->setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType artificialViscosity; + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/flow-vl/LaxFridrichsContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h similarity index 74% rename from src/Examples/flow-vl/LaxFridrichsContinuity.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h index 82747cd18220efc01bc2d68e0247c01723c29fd0..e82c9d4242d426adb2f21b238b05f0773e3b1c3b 100644 --- a/src/Examples/flow-vl/LaxFridrichsContinuity.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h @@ -14,12 +14,13 @@ #include #include #include -#include +#include namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuityBase @@ -35,6 +36,7 @@ class LaxFridrichsContinuityBase static const int Dimensions = MeshType::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsContinuityBase() : artificialViscosity( 1.0 ){}; @@ -68,12 +70,15 @@ class LaxFridrichsContinuityBase RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; RealType artificialViscosity; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuity @@ -85,14 +90,15 @@ class LaxFridrichsContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -114,13 +120,20 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re 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 ]; + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) - - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse; + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -144,14 +157,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -175,19 +189,23 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re //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 ]; + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -211,14 +229,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -242,27 +261,30 @@ class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Re //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 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 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 ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ up ] * velocity_z_up - u[ down ] * velocity_z_down ) * hzInverse ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..c001b847cb42eb4f68bc392c06021589d017017f --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsDisipation.h @@ -0,0 +1,352 @@ +/*************************************************************************** + LaxFridrichsDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsDisipationBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + LaxFridrichsDisipationBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsDisipation< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity( velocity ); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->rightHandSide.setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->rightHandSide.setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsDisipationBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsDisipationBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsDisipationBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/flow-sw/LaxFridrichsEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h similarity index 69% rename from src/Examples/flow-sw/LaxFridrichsEnergy.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h index 03019ed23c85f82ee489c95d8173c0f100cff3c8..ab7c416d8c125af03f64d560c3c96b9381b36c36 100644 --- a/src/Examples/flow-sw/LaxFridrichsEnergy.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h @@ -16,6 +16,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergyBase @@ -32,6 +33,7 @@ class LaxFridrichsEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsEnergyBase() : artificialViscosity( 1.0 ){}; @@ -52,6 +54,7 @@ class LaxFridrichsEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -62,13 +65,35 @@ class LaxFridrichsEnergyBase void setArtificialViscosity( const RealType& artificialViscosity ) { this->artificialViscosity = artificialViscosity; - } + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity( density ); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; protected: RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; @@ -76,6 +101,7 @@ class LaxFridrichsEnergyBase }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergy @@ -85,15 +111,16 @@ class LaxFridrichsEnergy template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -115,18 +142,23 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, 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& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; - + - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -150,14 +182,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -180,27 +213,33 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -224,14 +263,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -253,16 +293,17 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; @@ -270,13 +311,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ] ) @@ -285,7 +328,9 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, + ( ( ( 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 ); + -( ( e[ down ] + pressure_down ) * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-sw/LaxFridrichsMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h similarity index 72% rename from src/Examples/flow-sw/LaxFridrichsMomentumBase.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h index cc2561748968a2bd808fa434d4f3d87d41765f45..c44f5777068017143db011224c80c78819446b55 100644 --- a/src/Examples/flow-sw/LaxFridrichsMomentumBase.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h @@ -14,6 +14,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumBase @@ -30,6 +31,7 @@ class LaxFridrichsMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsMomentumBase() : artificialViscosity( 1.0 ){}; @@ -42,6 +44,7 @@ class LaxFridrichsMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -54,11 +57,33 @@ class LaxFridrichsMomentumBase this->artificialViscosity = artificialViscosity; } + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity( density ); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + } + protected: RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; diff --git a/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h similarity index 70% rename from src/Examples/inviscid-flow-vl/LaxFridrichsMomentumX.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h index 63def12d315188b82e82402635fca863d1b9a629..57258d1a534721a5887ad8affb0e60acdf66943d 100644 --- a/src/Examples/inviscid-flow-vl/LaxFridrichsMomentumX.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumX @@ -27,15 +28,16 @@ class LaxFridrichsMomentumX template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -67,17 +69,22 @@ 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 IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; + -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -101,14 +108,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -139,26 +147,34 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -182,14 +198,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -219,30 +236,30 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -250,7 +267,9 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_u[ down ] * velocity_z_down ) )* hzInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-vl/LaxFridrichsMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h similarity index 69% rename from src/Examples/flow-vl/LaxFridrichsMomentumY.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h index 8ce42282dd4c74d5ed72d2abbd661235b95dc160..4cca02779d04d1395051035156d30b8a998ffa64 100644 --- a/src/Examples/flow-vl/LaxFridrichsMomentumY.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumY @@ -27,15 +28,16 @@ class LaxFridrichsMomentumY template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -128,26 +131,32 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > @@ -171,14 +180,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -207,34 +217,44 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 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 * + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ down ] * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h similarity index 78% rename from src/Examples/inviscid-flow-sw/LaxFridrichsMomentumZ.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h index a67e862ceffd78d4fd770d7b1a07e9f05af349d8..1f394bfef12c16125be4a674d08f2defbc455f12 100644 --- a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumZ.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumZ @@ -27,15 +28,16 @@ class LaxFridrichsMomentumZ template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -151,14 +154,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -188,25 +192,30 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -214,7 +223,9 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_w[ down ] * velocity_z_down + pressure_down ) )* hzInverse ) + + + this->rightHandSide(rho_w, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..5c6c9b15f5d7f1e64beca3a5a601c34e465c10fb --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h @@ -0,0 +1,347 @@ +/*************************************************************************** + LaxFridrichsTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + LaxFridrichsTurbulentEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsTurbulentEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity(density); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->rightHandSide.setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setViscosityConstant( RealType& ViscosityConstant ) + { + this->rightHandSide.setViscosityConstant( ViscosityConstant ); + } + + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..dd314493d0ab7909ca40dcc20c813427116f58ea --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h @@ -0,0 +1,247 @@ +/*************************************************************************** + StegerWarming.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 +#include +#include + +#include "StegerWarmingContinuity.h" +#include "StegerWarmingEnergy.h" +#include "StegerWarmingMomentumX.h" +#include "StegerWarmingMomentumY.h" +#include "StegerWarmingMomentumZ.h" +#include "StegerWarmingTurbulentEnergy.h" +#include "StegerWarmingDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KEpsilonOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarming +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + + typedef StegerWarmingContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef StegerWarmingMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef StegerWarmingMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef StegerWarmingMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef StegerWarmingEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef StegerWarmingTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef StegerWarmingDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + 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 ); + } + + StegerWarming() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "Steger-Warming"<< std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setGamma( gamma ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + this->disipationOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->disipationOperatorPointer->setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->disipationOperatorPointer->setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/inviscid-flow-sw/UpwindContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h similarity index 82% rename from src/Examples/inviscid-flow-sw/UpwindContinuity.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h index 22fc4ffc5d97e2933d7db36ceac3f66d5a33b63f..5fbef7be69519f22735bf920375af3ad71eb6353 100644 --- a/src/Examples/inviscid-flow-sw/UpwindContinuity.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindContinuity.h - description + StegerWarmingContinuity.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -20,9 +20,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuityBase +class StegerWarmingContinuityBase { public: @@ -36,10 +37,11 @@ class UpwindContinuityBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; static String getType() { - return String( "UpwindContinuity< " ) + + return String( "StegerWarmingContinuity< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -65,10 +67,9 @@ class UpwindContinuityBase this->velocity = velocity; }; - __cuda_callable__ RealType positiveDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { - const RealType& speedOfSound = TNL::sqrt( this->gamma * pressure / density ); + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); const RealType& machNumber = velocity / speedOfSound; if ( machNumber <= -1.0 ) return 0.0; @@ -80,10 +81,9 @@ class UpwindContinuityBase return density * velocity; }; - __cuda_callable__ RealType negativeDensityFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { - const RealType& speedOfSound = TNL::sqrt( this->gamma * pressure / density ); + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); const RealType& machNumber = velocity / speedOfSound; if ( machNumber <= -1.0 ) return density * velocity; @@ -93,7 +93,9 @@ class UpwindContinuityBase return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); else return 0.0; - }; + }; + + protected: @@ -103,15 +105,18 @@ class UpwindContinuityBase VelocityFieldPointer velocity; + OperatorRightHandSideType rightHandSide; + MeshFunctionPointer pressure; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindContinuity +class StegerWarmingContinuity { }; @@ -120,14 +125,15 @@ class UpwindContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -158,16 +164,18 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -191,14 +199,15 @@ class UpwindContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -220,8 +229,8 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In 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 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 >(); @@ -235,13 +244,13 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -254,7 +263,9 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -278,14 +289,15 @@ class UpwindContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, In template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class StegerWarmingContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindContinuityBase< MeshType, Real, Index > BaseType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -327,17 +339,17 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In 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_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; return -hxInverse * ( this->positiveDensityFlux( u[ center ], velocity_x_center, pressure_center ) @@ -356,7 +368,9 @@ class UpwindContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, In - 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 ) - ); + ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..e93fc39479339972a99fa01e8b5bd4b6debab726 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingDisipation.h @@ -0,0 +1,458 @@ +/*************************************************************************** + StegerWarmingDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingDisipationBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingDisipation< " ) + + 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; + this->rightHandSide.setVelocity( velocity ); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->rightHandSide.setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->rightHandSide.setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + RealType positiveDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) 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 <= 0.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ); + else + return disipation * velocity; + }; + + RealType negativeDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return disipation * velocity; + else if ( machNumber <= 0.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..05d8c3b1f17bdc5db8ab27729430ce85f740492d --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h @@ -0,0 +1,561 @@ +/*************************************************************************** + StegerWarmingEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..227c884869627e69d314d9df14df74c06b61ba08 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h @@ -0,0 +1,151 @@ +/*************************************************************************** + StegerWarmingMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + } + + 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 <= 0.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( ( machNumber + 1.0 ) * ( machNumber + 1.0 ) ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( 2.0 * ( this->gamma - 1.0 ) * machNumber * machNumber + (machNumber + 1.0 ) * (machNumber + 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( 2.0 * ( this->gamma - 1.0 ) * machNumber * machNumber + (machNumber - 1.0 ) * (machNumber - 1.0 ) ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( ( machNumber - 1.0 ) * ( machNumber - 1.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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ) * velocity_other; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * velocity_other; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ) * velocity_other; + else + return 0.0; + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..c6588083cd9efdd02864d6200cff678de8d0a76d --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h @@ -0,0 +1,356 @@ +/*************************************************************************** + StegerWarmingMomentumX.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..210fb60878d9da9f6f44bb55972997d73be63df7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h @@ -0,0 +1,326 @@ +/*************************************************************************** + StegerWarmingMomentumY.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..135352d2fdf260a2310e5c6e45f2cc581d0e9ff0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h @@ -0,0 +1,282 @@ +/*************************************************************************** + StegerWarmingMomentumZ.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return 0-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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..83b7f3fabfde66bb0ed6575290cff27fcf3555b6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h @@ -0,0 +1,443 @@ +/*************************************************************************** + StegerWarmingTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity(density); + this->density = density; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + }; + + RealType positiveTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) 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 <= 0.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ); + else + return turbulentEnergy * velocity; + }; + + RealType negativeTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return turbulentEnergy * velocity; + else if ( machNumber <= 0.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..58edd4ae936e193fe3617be2723ee084cf92f81c --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h @@ -0,0 +1,246 @@ +/*************************************************************************** + VanLeer.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 +#include +#include + +#include "VanLeerContinuity.h" +#include "VanLeerEnergy.h" +#include "VanLeerMomentumX.h" +#include "VanLeerMomentumY.h" +#include "VanLeerMomentumZ.h" +#include "VanLeerTurbulentEnergy.h" +#include "VanLeerDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KEpsilonOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeer +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + typedef VanLeerContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef VanLeerMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef VanLeerMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef VanLeerMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef VanLeerEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef VanLeerTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef VanLeerDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + 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 ); + } + + VanLeer() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "VanLeer" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setGamma( gamma ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + this->disipationOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->disipationOperatorPointer->setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->disipationOperatorPointer->setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..3b497125a6a291990c61c4fed6f158a73472e084 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerContinuity.h @@ -0,0 +1,396 @@ +/*************************************************************************** + VanLeerContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerContinuity< " ) + + 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; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..664790a55010b2f7cefff9abe7c86d84b453b569 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerDisipation.h @@ -0,0 +1,453 @@ +/*************************************************************************** + VanLeerDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerDisipationBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerDisipation< " ) + + 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; + this->rightHandSide.setVelocity( velocity ); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->rightHandSide.setViscosityConstant1( viscosityConstant1 ); + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->rightHandSide.setViscosityConstant2( viscosityConstant2 ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + RealType positiveDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) 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 disipation * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ); + else + return disipation * velocity; + }; + + RealType negativeDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return disipation * velocity; + else if ( machNumber <= 1.0 ) + return - disipation * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..4e19cdda4ea4fd2d60d85f0f197bcf8ec235dfea --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerEnergy.h @@ -0,0 +1,593 @@ +/*************************************************************************** + VanLeerEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + VanLeerEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "VanLeerEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..a1901fb7c3a3e9b99026b5774f62026959bd4ed3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h @@ -0,0 +1,146 @@ +/*************************************************************************** + VanLeerMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity(density); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + 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; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..04e41c015c6193ec3c7e45d5d737512a2762f38a --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h @@ -0,0 +1,410 @@ +/*************************************************************************** + VanLeerMomentumX.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..65ac8482807903cb2e98f8fbc25a4627d1ef7a4b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h @@ -0,0 +1,381 @@ +/*************************************************************************** + VanLeerMomentumY.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..125166cb885b65a8f14049a90dcf92449d644498 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h @@ -0,0 +1,322 @@ +/*************************************************************************** + VanLeerMomentumZ.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..9d6fd09d0e2d85ff4a6c792283c7e1ca53af6f3a --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h @@ -0,0 +1,438 @@ +/*************************************************************************** + VanLeerTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity(density); + this->density = density; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + RealType positiveTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) 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 turbulentEnergy * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ); + else + return turbulentEnergy * velocity; + }; + + RealType negativeTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return turbulentEnergy * velocity; + else if ( machNumber <= 1.0 ) + return - turbulentEnergy * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonContinuityOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonContinuityOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..08663eb0c7ec5749652e2453365226d338430aba --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonContinuityOperatorRightHandSide.h @@ -0,0 +1,218 @@ +/*************************************************************************** + KEpsilonContinuityOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonContinuityRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + protected: + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonContinuityRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KEpsilonContinuityRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonContinuityRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonContinuityRightHandSideBase< 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" ); + + return 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 KEpsilonContinuityRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonContinuityRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonContinuityRightHandSideBase< 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" ); + + return 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 KEpsilonContinuityRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonContinuityRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonContinuityRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonDisipationOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonDisipationOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..05be9d8e088af64fb3d128e40b21b143ec75ee69 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonDisipationOperatorRightHandSide.h @@ -0,0 +1,653 @@ +/*************************************************************************** + KEpsilonDisipationOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonDisipationRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setViscosityConstant1( const RealType& viscosityConstant1 ) + { + this->viscosityConstant1 = viscosityConstant1; + } + + void setViscosityConstant2( const RealType& viscosityConstant2 ) + { + this->viscosityConstant2 = viscosityConstant2; + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->sigmaEpsilon = sigmaEpsilon; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipation = disipation; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer disipation; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; + + RealType viscosityConstant1; + + RealType viscosityConstant2; + + RealType sigmaEpsilon; +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonDisipationRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KEpsilonDisipationRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonDisipationRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonDisipationRightHandSideBase< 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 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + const RealType& disipation_west = this->disipation.template getData< DeviceType >()[ west ]; + const RealType& disipation_east = this->disipation.template getData< DeviceType >()[ east ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + if( ! ( turbulentEnergy_center == 0.0 ) ) + return + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaEpsilon + + + this->viscosityConstant1 * disipation_center / turbulentEnergy_center + * ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + * turbulentViscosity_center + - 2.0 / 3.0 * density_center * turbulentEnergy_center + ) + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + - this->viscosityConstant2 * density_center * disipation_center * disipation_center / turbulentEnergy_center; + else + return + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaEpsilon; + } + + /*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 KEpsilonDisipationRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonDisipationRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonDisipationRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + const RealType& disipation_west = this->disipation.template getData< DeviceType >()[ west ]; + const RealType& disipation_east = this->disipation.template getData< DeviceType >()[ east ]; + const RealType& disipation_north = this->disipation.template getData< DeviceType >()[ north ]; + const RealType& disipation_south = this->disipation.template getData< DeviceType >()[ south ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + if( ! ( turbulentEnergy_center == 0.0 ) ) + return + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaEpsilon + + + this->viscosityConstant1 * disipation_center / turbulentEnergy_center + * ( ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + + ) + + - this->viscosityConstant2 * density_center * disipation_center * disipation_center / turbulentEnergy_center; + else + return + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaEpsilon; + } + + /*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 KEpsilonDisipationRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonDisipationRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonDisipationRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + const RealType& disipation_west = this->disipation.template getData< DeviceType >()[ west ]; + const RealType& disipation_east = this->disipation.template getData< DeviceType >()[ east ]; + const RealType& disipation_north = this->disipation.template getData< DeviceType >()[ north ]; + const RealType& disipation_south = this->disipation.template getData< DeviceType >()[ south ]; + const RealType& disipation_up = this->disipation.template getData< DeviceType >()[ up ]; + const RealType& disipation_down = this->disipation.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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + if( ! ( turbulentEnergy_center == 0.0 ) ) + return + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_up - 2 * disipation_center + disipation_down ) + * hySquareInverse + + ( disipation_up * turbulentViscosity_up - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_up + disipation_down * turbulentViscosity_center + ) * hySquareInverse / this->sigmaEpsilon + + + this->viscosityConstant1 * disipation_center / turbulentEnergy_center + * ( ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_x_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + + + ( ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + + ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + + ( ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + + ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) + + - this->viscosityConstant2 * density_center * disipation_center * disipation_center / turbulentEnergy_center; + else + return + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_up - 2 * disipation_center + disipation_down ) + * hySquareInverse + + ( disipation_up * turbulentViscosity_up - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_up + disipation_down * turbulentViscosity_center + ) * hySquareInverse / this->sigmaEpsilon; + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonEnergyOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..4f203a38110e0bec248d963ea6df86a59b8e8e46 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonEnergyOperatorRightHandSide.h @@ -0,0 +1,687 @@ +/*************************************************************************** + KEpsilonEnergyOperatorRightHandSide.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 +#include + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + KEpsilonEnergyRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonEnergyRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KEpsilonEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D uT_11_x + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west + - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D_t_11_x + + + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + + + 2.0 / 3.0 * ( velocity_x_east * density_east * turbulentEnergy_east + - velocity_x_west * density_west * turbulentEnergy_west + ) * hxInverse / 2; + } + + /*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 KEpsilonEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + 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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + - velocity_x_center * velocity_x_center + velocity_x_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_south + - velocity_x_northWest * velocity_y_north + velocity_x_southWest * velocity_y_south + ) * hxInverse * hyInverse / 4 + ) * this->dynamicalViscosity +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( velocity_x_east * density_east * turbulentEnergy_east + - velocity_x_west * density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ); + } + + /*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 KEpsilonEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + 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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// wT_13_x + + ( ( velocity_x_upEast * velocity_z_east - velocity_x_downEast * velocity_z_east + - velocity_x_upWest * velocity_z_west + velocity_x_downWest * velocity_z_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center - velocity_z_center * velocity_z_west + - velocity_z_center * velocity_z_center + velocity_z_west * velocity_z_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + + velocity_x_center * velocity_x_center + velocity_x_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_23_y + + ( ( velocity_y_upNorth * velocity_z_north - velocity_y_downNorth * velocity_y_north + - velocity_y_upSouth * velocity_z_south + velocity_y_downSouth * velocity_z_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center - velocity_z_center * velocity_z_south + - velocity_z_center * velocity_z_center + velocity_z_south * velocity_z_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// uT_31_z + + ( ( velocity_x_up * velocity_x_center - velocity_x_center * velocity_x_center + - velocity_x_center * velocity_x_down + velocity_x_down * velocity_x_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up - velocity_z_downEast * velocity_x_down + - velocity_z_upWest * velocity_x_up + velocity_z_downWest * velocity_x_down + ) * hxInverse * hzInverse / 4 + ) * this->dynamicalViscosity +// T_32_z + + ( ( velocity_z_upNorth * velocity_y_up - velocity_z_downNorth * velocity_y_down + - velocity_z_upSouth * velocity_y_up + velocity_z_downSouth * velocity_y_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center - velocity_x_center * velocity_y_down + - velocity_x_center * velocity_y_center + velocity_x_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 +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upEast * velocity_x_east * turbulentViscosity_east - velocity_z_downEast * velocity_x_east * turbulentViscosity_east + - velocity_z_upWest * velocity_x_west * turbulentViscosity_west + velocity_z_downWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// wt_13_x + + ( ( velocity_x_upEast * velocity_z_east * turbulentViscosity_east - velocity_x_downEast * velocity_z_east * turbulentViscosity_east + - velocity_x_upWest * velocity_z_west * turbulentViscosity_west + velocity_x_downWest * velocity_z_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_west * turbulentViscosity_west + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_west * velocity_z_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + + velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upNorth * velocity_y_north * turbulentViscosity_north - velocity_z_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_z_upSouth * velocity_y_south * turbulentViscosity_south + velocity_z_downSouth * velocity_y_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// wt_23_y + + ( ( velocity_y_upNorth * velocity_z_north * turbulentViscosity_north - velocity_y_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_y_upSouth * velocity_z_south * turbulentViscosity_south + velocity_y_downSouth * velocity_z_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_south * turbulentViscosity_south + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_south * velocity_z_south * turbulentViscosity_south + ) * hySquareInverse + ) +// ut_31_z + + ( ( velocity_x_up * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_center * turbulentViscosity_center + - velocity_x_center * velocity_x_down * turbulentViscosity_down + velocity_x_down * velocity_x_down * turbulentViscosity_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up * turbulentViscosity_up - velocity_z_downEast * velocity_x_down * turbulentViscosity_down + - velocity_z_upWest * velocity_x_up * turbulentViscosity_up + velocity_z_downWest * velocity_x_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + ) +// vt_32_z + + ( ( velocity_z_upNorth * velocity_y_up * turbulentViscosity_up - velocity_z_downNorth * velocity_y_down * turbulentViscosity_down + - velocity_z_upSouth * velocity_y_up * turbulentViscosity_up + velocity_z_downSouth * velocity_y_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center * turbulentViscosity_center - velocity_x_center * velocity_y_down * turbulentViscosity_down + - velocity_x_center * velocity_y_center * turbulentViscosity_center + velocity_x_down * velocity_y_down * turbulentViscosity_down + ) * hzSquareInverse + ) +// wt_33_z + + ( 4.0 / 3.0 * ( velocity_z_up * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_down * turbulentViscosity_down + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_down * velocity_z_down * turbulentViscosity_down + ) * hzSquareInverse + - 2.0 / 3.0 * ( velocity_y_upNorth * velocity_z_up * turbulentViscosity_up - velocity_y_downNorth * velocity_z_down * turbulentViscosity_down + - velocity_y_upSouth * velocity_z_up * turbulentViscosity_up + velocity_y_downSouth * velocity_z_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( velocity_x_upEast * velocity_z_up * turbulentViscosity_up - velocity_x_downEast * velocity_z_down * turbulentViscosity_down + - velocity_x_upWest * velocity_z_up * turbulentViscosity_up + velocity_x_downWest * velocity_z_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_z_up * density_up * turbulentEnergy_up + - velocity_z_down * density_down * turbulentEnergy_down + ) * hzInverse / 2 + ); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumBaseOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumBaseOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..36ce9b3df24b8a554b7a842a25792ac84410e9cd --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumBaseOperatorRightHandSide.h @@ -0,0 +1,75 @@ +/*************************************************************************** + KEpsilonMomentumRightHandSideBase.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 KEpsilonMomentumRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + KEpsilonMomentumRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumXOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumXOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..74d0b479f228f8efd5194f06badb785a29ca7113 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumXOperatorRightHandSide.h @@ -0,0 +1,450 @@ +/*************************************************************************** + KEpsilonMomentumXRightHandSide.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 +#include +#include "KEpsilonMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonMomentumXRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KEpsilonMomentumXRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< 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& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D T_11_x + 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D t_11_x + + + 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2; + } + + /*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 KEpsilonMomentumXRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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 + ) * hySquareInverse + ) * this->dynamicalViscosity +// t_11_x + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ); + + } + + /*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 KEpsilonMomentumXRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_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 + ) * hxSquareInverse + ) * this->dynamicalViscosity +// T_31_z + + ( ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse / 4 + + ( velocity_x_up - 2 * velocity_x_center + velocity_x_down + ) * hzSquareInverse + ) * this->dynamicalViscosity +//t_11_x + + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_east * (velocity_z_upEast - velocity_z_downEast ) - turbulentViscosity_west * ( velocity_z_upWest - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ) +// t_31_z + + ( ( turbulentViscosity_up * ( velocity_z_upEast - velocity_z_upWest ) - turbulentViscosity_down * ( velocity_z_downEast - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_x_up - ( turbulentViscosity_up + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_down + ) * hzSquareInverse + ); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumYOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumYOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..a5597847acb0130bcb3b4e35059c3b42db5c726e --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumYOperatorRightHandSide.h @@ -0,0 +1,417 @@ +/*************************************************************************** + KEpsilonMomentumYRightHandSide.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 +#include +#include "KEpsilonMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonMomentumYRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KEpsilonMomentumYRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< 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 KEpsilonMomentumYRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + + return +// 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 + + +// t_22_y + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( density_north * turbulentEnergy_north + - density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// t_12_x + + ( ( turbulentViscosity_east * (velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * (velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ); + } + + /*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 KEpsilonMomentumYRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_12_y + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east - 2 * velocity_y_center + velocity_y_west + ) * hxSquareInverse + ) * 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_up - 2 * velocity_y_center + velocity_y_down + ) * hzSquareInverse + ) * this->dynamicalViscosity + + +// t_12_x + ( ( turbulentViscosity_east * ( velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * ( velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ) +// t_22_y + + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_south * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_z_upNorth - velocity_z_downNorth ) - turbulentViscosity_south * ( velocity_z_upSouth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_north * turbulentEnergy_north + - density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// t_32_z + + ( ( turbulentViscosity_up * ( velocity_z_upNorth - velocity_z_upSouth ) - turbulentViscosity_down * ( velocity_z_downNorth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_y_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_down + ) * hzSquareInverse + ); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumZOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumZOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..ec9bb9e7687bc6c7af11429a9f2624eb484fe2ad --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonMomentumZOperatorRightHandSide.h @@ -0,0 +1,343 @@ +/*************************************************************************** + KEpsilonMomentumZRightHandSide.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 +#include +#include "KEpsilonMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonMomentumZRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KEpsilonMomentumZRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< 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 KEpsilonMomentumZRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< 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 KEpsilonMomentumZRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_13_x + ( ( velocity_z_east - 2 * velocity_z_center + velocity_z_west ) + * hxSquareInverse + + ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) + * hxInverse * hzInverse / 4 + ) + * this->dynamicalViscosity +// T_23_y + + ( ( velocity_y_upNorth - velocity_y_downNorth - velocity_y_upSouth + velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + + ( velocity_z_north - 2 * velocity_z_center + velocity_z_south ) + * hySquareInverse + ) + * 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 +// t_13_x + + ( ( turbulentViscosity_east * velocity_z_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_west ) + * hxSquareInverse + + ( turbulentViscosity_east * ( velocity_x_upEast - velocity_x_downEast ) - turbulentViscosity_west * ( velocity_x_upWest - velocity_x_downWest ) ) + * hxInverse * hzInverse / 4 + ) +// t_23_y + + ( ( turbulentViscosity_north * ( velocity_y_upNorth - velocity_y_downNorth ) - turbulentViscosity_south * ( velocity_y_upSouth - velocity_y_downSouth ) ) + * hyInverse * hzInverse / 4 + + ( turbulentViscosity_north * velocity_z_north - (turbulentViscosity_north + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_south ) + * hySquareInverse + ) +// t_33_z + + ( 4.0 / 3.0 * ( turbulentViscosity_up * velocity_z_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_down ) + * hzSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_y_upNorth - turbulentViscosity_down * velocity_y_downNorth - turbulentViscosity_up * velocity_y_upSouth + turbulentViscosity_down * velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_x_upEast - turbulentViscosity_down * velocity_x_downEast - turbulentViscosity_up * velocity_x_upWest + turbulentViscosity_down * velocity_x_downWest ) + * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_up * turbulentEnergy_up + - density_down * turbulentEnergy_down + ) * hzInverse / 2 + ); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..2c4277960438c7d58b413d17dfcec07fc338d2e5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h @@ -0,0 +1,169 @@ +/*************************************************************************** + KEpsilonOpratorRightHandSide.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 +#include +#include + +#include "KEpsilonContinuityOperatorRightHandSide.h" +#include "KEpsilonEnergyOperatorRightHandSide.h" +#include "KEpsilonMomentumXOperatorRightHandSide.h" +#include "KEpsilonMomentumYOperatorRightHandSide.h" +#include "KEpsilonMomentumZOperatorRightHandSide.h" +#include "KEpsilonTurbulentEnergyOperatorRightHandSide.h" +#include "KEpsilonDisipationOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonOperatorRightHandSide +{ + 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 KEpsilonContinuityRightHandSide< Mesh, Real, Index > ContinuityOperatorRightHandSideType; + typedef KEpsilonMomentumXRightHandSide< Mesh, Real, Index > MomentumXOperatorRightHandSideType; + typedef KEpsilonMomentumYRightHandSide< Mesh, Real, Index > MomentumYOperatorRightHandSideType; + typedef KEpsilonMomentumZRightHandSide< Mesh, Real, Index > MomentumZOperatorRightHandSideType; + typedef KEpsilonEnergyRightHandSide< Mesh, Real, Index > EnergyOperatorRightHandSideType; + typedef KEpsilonTurbulentEnergyRightHandSide< Mesh, Real, Index > TurbulentEnergyOperatorRightHandSideType; + typedef KEpsilonDisipationRightHandSide< Mesh, Real, Index > DisipationOperatorRightHandSideType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorRightHandSideType > ContinuityOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumXOperatorRightHandSideType > MomentumXOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumYOperatorRightHandSideType > MomentumYOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumZOperatorRightHandSideType > MomentumZOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< EnergyOperatorRightHandSideType > EnergyOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorRightHandSideType > TurbulentEnergyOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< DisipationOperatorRightHandSideType > DisipationOperatorRightHandSidePointer; + + 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 ); + } + + KEpsilonOperatorRightHandSide() + : dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + return true; + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + this->continuityOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumXOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumYOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumZOperatorRightHandSidePointer->setVelocity( velocity ); + this->energyOperatorRightHandSidePointer->setVelocity( velocity ); + this->turbulentEnergyOperatorRightHandSidePointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->momentumXOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorRightHandSidePointer->setDensity( density ); + this->momentumYOperatorRightHandSidePointer->setDensity( density ); + this->momentumZOperatorRightHandSidePointer->setDensity( density ); + this->energyOperatorRightHandSidePointer->setDensity( density ); + this->turbulentEnergyOperatorRightHandSidePointer->setDenity( density ); + } + + const ContinuityOperatorRightHandSidePointer& getContinuityOperatorRightHandSide() const + { + return this->continuityOperatorRightHandSidePointer; + } + + const MomentumXOperatorRightHandSidePointer& getMomentumXOperatorRightHandSide() const + { + return this->momentumXOperatorRightHandSidePointer; + } + + const MomentumYOperatorRightHandSidePointer& getMomentumYOperatorRightHandSide() const + { + return this->momentumYOperatorRightHandSidePointer; + } + + const MomentumZOperatorRightHandSidePointer& getMomentumZOperatorRightHandSide() const + { + return this->momentumZOperatorRightHandSidePointer; + } + + const EnergyOperatorRightHandSidePointer& getEnergyOperatorRightHandSide() const + { + return this->energyOperatorRightHandSidePointer; + } + + const TurbulentEnergyOperatorRightHandSidePointer& getTurbulentEnergyOperatorRightHandSide() const + { + return this->turbulentEnergyOperatorRightHandSidePointer; + } + + const DisipationOperatorRightHandSidePointer& getDisipationOperatorRightHandSide() const + { + return this->disipationOperatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorRightHandSidePointer continuityOperatorPointer; + MomentumXOperatorRightHandSidePointer momentumXOperatorPointer; + MomentumYOperatorRightHandSidePointer momentumYOperatorPointer; + MomentumZOperatorRightHandSidePointer momentumZOperatorPointer; + EnergyOperatorRightHandSidePointer energyOperatorPointer; + TurbulentEnergyOperatorRightHandSidePointer turbulentEnergyOperatorPointer; + DisipationOperatorRightHandSidePointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonTurbulentEnergyOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonTurbulentEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..0f3678c471a32ad2b95134e85b643a65485b6d9e --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonTurbulentEnergyOperatorRightHandSide.h @@ -0,0 +1,553 @@ +/*************************************************************************** + KEpsilonTurbulentEnergyOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonTurbulentEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + + + static String getType() + { + return String( "LaxFridrichsTurbulentEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setSigmaK( const RealType& sigmaK ) + { + this->sigmaK = sigmaK; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; + + RealType sigmaK; +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KEpsilonTurbulentEnergyRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KEpsilonTurbulentEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonTurbulentEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonTurbulentEnergyRightHandSideBase< 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 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaK + + + ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + * turbulentViscosity_center + - 2.0 / 3.0 * density_center * turbulentEnergy_center + ) + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2; + } + + /*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 KEpsilonTurbulentEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonTurbulentEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonTurbulentEnergyRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_north - 2 * turbulentEnergy_center + turbulentEnergy_south ) + * hySquareInverse + + ( turbulentEnergy_north * turbulentViscosity_north - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_north + turbulentEnergy_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaK + + + ( ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + + ); + } + + /*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 KEpsilonTurbulentEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KEpsilonTurbulentEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KEpsilonTurbulentEnergyRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse / this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_north - 2 * turbulentEnergy_center + turbulentEnergy_south ) + * hySquareInverse + + ( turbulentEnergy_north * turbulentViscosity_north - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_north + turbulentEnergy_south * turbulentViscosity_center + ) * hySquareInverse / this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_up - 2 * turbulentEnergy_center + turbulentEnergy_down ) + * hySquareInverse + + ( turbulentEnergy_up * turbulentViscosity_up - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_up + turbulentEnergy_down * turbulentViscosity_center + ) * hySquareInverse / this->sigmaK + + + ( ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_x_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + + + ( ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + + ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + ) * turbulentViscosity_center + * ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + + ( ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + + ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + ) * turbulentViscosity_center + * ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * turbulentViscosity_center + * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - 2.0 / 3.0 * density_center * turbulentEnergy_center + * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/PhysicalVariablesGetter.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/PhysicalVariablesGetter.h new file mode 100644 index 0000000000000000000000000000000000000000..452620d0d409dc3427a29e9f4e2b3e6bc33587b8 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/PhysicalVariablesGetter.h @@ -0,0 +1,243 @@ +/*************************************************************************** + 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 +#include +#include +#include +#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef Pointers::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; + }; + + class TurbulentEnergyGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + TurbulentEnergyGetter( MeshFunctionPointer density, + MeshFunctionPointer turbulentEnergyXDensity ) + : density( density ), turbulentEnergyXDensity( turbulentEnergyXDensity ) {} + + 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 turbulentEnergyXDensity.template getData< DeviceType >()( meshEntity ) / + density.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer density, turbulentEnergyXDensity; + }; + + class DisipationGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + DisipationGetter( MeshFunctionPointer density, + MeshFunctionPointer disipationXDensity ) + : density( density ), disipationXDensity( disipationXDensity ) {} + + 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 disipationXDensity.template getData< DeviceType >()( meshEntity ) / + density.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer density, disipationXDensity; + }; + + class TurbulentViscosityGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + TurbulentViscosityGetter( MeshFunctionPointer density, + MeshFunctionPointer turbulentEnergy, + RealType turbulenceConstant, + MeshFunctionPointer disipation ) + : density( density ), turbulentEnergy( turbulentEnergy ), turbulenceConstant( turbulenceConstant ), disipation( disipation ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + if( disipation.template getData< DeviceType >()( meshEntity ) == 0.0 ) + return 0; + else + return density.template getData< DeviceType >()( meshEntity ) * turbulenceConstant + * turbulentEnergy.template getData< DeviceType >()( meshEntity ) + * turbulentEnergy.template getData< DeviceType >()( meshEntity ) + / disipation.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer density, turbulentEnergy, disipation; + const RealType turbulenceConstant; + }; + + + void getVelocity( const ConservativeVariablesPointer& conservativeVariables, + VelocityFieldPointer& velocity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, VelocityGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::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; + Pointers::SharedPointer< PressureGetter, DeviceType > pressureGetter( conservativeVariables->getDensity(), + conservativeVariables->getEnergy(), + conservativeVariables->getMomentum(), + gamma ); + evaluator.evaluate( pressure, pressureGetter ); + } + + void getTurbulentEnergy( const ConservativeVariablesPointer& conservativeVariables, + MeshFunctionPointer& turbulentEnergy_no_rho ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, TurbulentEnergyGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< TurbulentEnergyGetter, DeviceType > turbulentEnergyGetter( conservativeVariables->getDensity(), + conservativeVariables->getTurbulentEnergy() ); + evaluator.evaluate( turbulentEnergy_no_rho, turbulentEnergyGetter ); + } + } + + void getDisipation( const ConservativeVariablesPointer& conservativeVariables, + MeshFunctionPointer& disipation_no_rho ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, DisipationGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< DisipationGetter, DeviceType > disipationGetter( conservativeVariables->getDensity(), + conservativeVariables->getDisipation() ); + evaluator.evaluate( disipation_no_rho, disipationGetter ); + } + } + + void getTurbulentViscosity( const ConservativeVariablesPointer& conservativeVariables, + MeshFunctionPointer& turbulentEnergy_no_rho, + MeshFunctionPointer& disipation_no_rho, + const RealType& turbulenceConstant, + MeshFunctionPointer& turbulentViscosity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, TurbulentViscosityGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< TurbulentViscosityGetter, DeviceType > turbulentViscosityGetter( conservativeVariables->getDensity(), + turbulentEnergy_no_rho, + turbulenceConstant, + disipation_no_rho); + evaluator.evaluate( turbulentViscosity, turbulentViscosityGetter ); + } + } + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/RiemannProblemInitialCondition.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/RiemannProblemInitialCondition.h new file mode 100644 index 0000000000000000000000000000000000000000..90a456fb49f13659b1964fee34b01886ea79b325 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/RiemannProblemInitialCondition.h @@ -0,0 +1,1896 @@ +/*************************************************************************** + 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 +#include +#include +#include +#include +#include "CompressibleConservativeVariables.h" + +namespace TNL { +template +class RiemannProblemInitialConditionSetter +{ + +}; + +template +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 Pointers::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 setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + + void setDisipation(RealType NWUDisipation, + RealType NEUDisipation, + RealType SWUDisipation, + RealType SEUDisipation, + RealType NWDDisipation, + RealType NEDDisipation, + RealType SWDDisipation, + RealType SEDDisipation) + { + this->NWUDisipation = NWUDisipation; + this->NEUDisipation = NEUDisipation; + this->SWUDisipation = SWUDisipation; + this->SEUDisipation = SEUDisipation; + this->NWDDisipation = NWDDisipation; + this->NEDDisipation = NEDDisipation; + this->SWDDisipation = SWDDisipation; + this->SEDDisipation = SEDDisipation; + }; + + 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); + } + }; + + + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + }; + + void placeDisipation(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.getDisipation()).setValue(cell, this->SWDDisipation); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getDisipation()).setValue(cell, this->SEDDisipation); + } + }; + + PointType discontinuityPlacement; + RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; + RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; + PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; + RealType gamma; +}; + + +template +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 Pointers::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 setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + + void setDisipation(RealType NWUDisipation, + RealType NEUDisipation, + RealType SWUDisipation, + RealType SEUDisipation, + RealType NWDDisipation, + RealType NEDDisipation, + RealType SWDDisipation, + RealType SEDDisipation) + { + this->NWUDisipation = NWUDisipation; + this->NEUDisipation = NEUDisipation; + this->SWUDisipation = SWUDisipation; + this->SEUDisipation = SEUDisipation; + this->NWDDisipation = NWDDisipation; + this->NEDDisipation = NEDDisipation; + this->SWDDisipation = SWDDisipation; + this->SEDDisipation = SEDDisipation; + }; + + 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); + } + }; + + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NEDTurbulentEnergy); + } + }; + + void placeDisipation(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.getDisipation()).setValue(cell, this->SWDDisipation); + } + 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.getDisipation()).setValue(cell, this->SEDDisipation); + } + 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.getDisipation()).setValue(cell, this->NWDDisipation); + } + 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.getDisipation()).setValue(cell, this->NEDDisipation); + } + }; + + PointType discontinuityPlacement; + RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; + RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; + PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; + RealType gamma; +}; + +template +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 Pointers::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 setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + + void setDisipation(RealType NWUDisipation, + RealType NEUDisipation, + RealType SWUDisipation, + RealType SEUDisipation, + RealType NWDDisipation, + RealType NEDDisipation, + RealType SWDDisipation, + RealType SEDDisipation) + { + this->NWUDisipation = NWUDisipation; + this->NEUDisipation = NEUDisipation; + this->SWUDisipation = SWUDisipation; + this->SEUDisipation = SEUDisipation; + this->NWDDisipation = NWDDisipation; + this->NEDDisipation = NEDDisipation; + this->SWDDisipation = SWDDisipation; + this->SEDDisipation = SEDDisipation; + }; + + 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); + } + }; + + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SWUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SWUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEUTurbulentEnergy); + } + }; + + void placeDisipation(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.getDisipation()).setValue(cell, this->SWDDisipation); + } + 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.getDisipation()).setValue(cell, this->SEDDisipation); + } + 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.getDisipation()).setValue(cell, this->NWDDisipation); + } + 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.getDisipation()).setValue(cell, this->NEDDisipation); + } + 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.getDisipation()).setValue(cell, this->SWUDisipation); + } + 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.getDisipation()).setValue(cell, this->SEUDisipation); + } + 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.getDisipation()).setValue(cell, this->SWUDisipation); + } + 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.getDisipation()).setValue(cell, this->SEUDisipation); + } + }; + + PointType discontinuityPlacement; + RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; + RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; + 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 Pointers::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->intensity = parameters.getParameter< double >( "turbulence-intensity" ); + this->turbulenceConstant = parameters.getParameter< double >( "turbulence-constant" ); + this->lengthScale = parameters.getParameter< double >( "turbulence-length-scale" ); + 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->NWUTurbulentEnergy = this->NWUDensity * TurbulentEnergy( NWUVelocity, this->intensity); + this->NWUDisipation = this->turbulenceConstant * std::pow( NWUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + 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->SWUTurbulentEnergy = SWUDensity * TurbulentEnergy( SWUVelocity, this->intensity); + this->SWUDisipation = this->turbulenceConstant * std::pow( SWUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + 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->NWDTurbulentEnergy = NWDDensity * TurbulentEnergy( NWDVelocity, this->intensity); + this->NWDDisipation = this->turbulenceConstant * std::pow( NWDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + 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->SWDTurbulentEnergy = SWDDensity * TurbulentEnergy( SWDVelocity, this->intensity); + this->SWDDisipation = this->turbulenceConstant * std::pow( SWDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + 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->NEUTurbulentEnergy = NEUDensity * TurbulentEnergy( NEUVelocity, this->intensity); + this->NEUDisipation = this->turbulenceConstant * std::pow( NEUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + 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->SEUTurbulentEnergy = SEUDensity * TurbulentEnergy( SEUVelocity, this->intensity); + this->SEUDisipation = this->turbulenceConstant * std::pow( SEUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + 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->NEDTurbulentEnergy = NEDDensity * TurbulentEnergy( NEDVelocity, this->intensity); + this->NEDDisipation = this->turbulenceConstant * std::pow( NEDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + 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; + this->SEDTurbulentEnergy = SEDDensity * TurbulentEnergy( SEDVelocity, this->intensity); + this->SEDDisipation = this->turbulenceConstant * std::pow( SEDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + } + 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, + 1.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_Noh") + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 0.000001, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 0.000001, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 1.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + -1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "1D_peak") + predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.0, 0.12612, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.0, 6.5915, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.0, 782.929, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.0, 3.15449, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 8.90470, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 2.26542, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_3") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.5323, 0.138, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.5, 0.5323, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.3, 0.029, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.5, 0.3, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 1.206, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 1.206, 1.206, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 1.206, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_4") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.5065, 1.1, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.1, 0.5065, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.35, 1.1, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.1, 0.35, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.8939, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.8939, 0.8939, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 0.8939, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + + if(initial == prefix + "2D_6") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 2.0, 1.0, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.0, 3.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 1.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.0, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.75, 0.5, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + -0.75, 0.5, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.75, -0.5, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + -0.75, -0.5, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_12") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 1.0, 0.8, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 0.5313, 1.0, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 1.0, 1.0, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 0.4, 1.0, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.7276, 0.0, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.0, 0.0, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, 0.0, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 0.7276, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + + if(initial == prefix + "2D_15") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 0.5197, 0.8, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.0, 0.5313, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 0.4, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.0, 0.4, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + -0.6259, -0.3, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.1, -0.3, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.1, -0.3, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.1, 0.4276, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + if(initial == prefix + "2D_17") + predefinedInitialCondition( 1.666, 0.5, 0.5, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, + 0.0, 0.0, 2.0, 1.0625, //double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + 0.0, 0.0, 1.0, 0.5197, //double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + 0.0, 0.0, 1.0, 0.4, //double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + 0.0, 0.0, 1.0, 0.4, //double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + 0.0, 0.0, 0.0, //double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + 0.0, 0.0, 0.0, //double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + 0.0, -0.3, 0.0, //double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + 0.0, 0.2145, 0.0, //double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + 0.0, 0.0, 0.0, //double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + 0.0, 0.0, 0.0, //double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + 0.0, -0.4, 0.0, //double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + 0.0, 1.1259, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ); + return true; + } + + void setDiscontinuityPlacement( const PointType& v ) + { + this->discontinuityPlacement = v; + } + + const PointType& getDiscontinuityPlasement() const + { + return this->discontinuityPlacement; + } + + void setLeftDensity( const RealType& leftDensity ) + { + this->leftDensity = leftDensity; + } + + const RealType& getLeftDensity() const + { + return this->leftDensity; + } + + void setRightDensity( const RealType& rightDensity ) + { + this->rightDensity = rightDensity; + } + + const RealType& getRightDensity() const + { + return this->rightDensity; + } + + void setLeftVelocity( const PointType& leftVelocity ) + { + this->leftVelocity = leftVelocity; + } + + const PointType& getLeftVelocity() const + { + return this->leftVelocity; + } + + void setRightVelocity( const RealType& rightVelocity ) + { + this->rightVelocity = rightVelocity; + } + + const PointType& getRightVelocity() const + { + return this->rightVelocity; + } + + void setLeftPressure( const RealType& leftPressure ) + { + this->leftPressure = leftPressure; + } + + const RealType& getLeftPressure() const + { + return this->leftPressure; + } + + void setRightPressure( const RealType& rightPressure ) + { + this->rightPressure = rightPressure; + } + + const RealType& getRightPressure() const + { + return this->rightPressure; + } + + + void predefinedInitialCondition( double preGamma, double preDiscX, double preDiscY, double preDiscZ, + double preNWUDensity, double preSWUDensity, double preNWDDensity, double preSWDDensity, + double preNEUDensity, double preSEUDensity, double preNEDDensity, double preSEDDensity, + double preNWUPressure, double preSWUPressure, double preNWDPressure, double preSWDPressure, + double preNEUPressure, double preSEUPressure, double preNEDPressure, double preSEDPressure, + double preNWUVelocityX, double preNWUVelocityY,double preNWUVelocityZ, + double preSWUVelocityX, double preSWUVelocityY,double preSWUVelocityZ, + double preNWDVelocityX, double preNWDVelocityY,double preNWDVelocityZ, + double preSWDVelocityX, double preSWDVelocityY,double preSWDVelocityZ, + double preNEUVelocityX, double preNEUVelocityY,double preNEUVelocityZ, + double preSEUVelocityX, double preSEUVelocityY,double preSEUVelocityZ, + double preNEDVelocityX, double preNEDVelocityY,double preNEDVelocityZ, + double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + ) + + { + this->intensity = 1.0; + this->turbulenceConstant = 1.0; + this->lengthScale = 1.0; + 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->NWUTurbulentEnergy = NWUDensity * TurbulentEnergy( NWUVelocity, this->intensity); + this->NWUDisipation = this->turbulenceConstant * std::pow( NWUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + this->SWUDensity = preNWUDensity; + this->SWUVelocity = PointLoad(preSWUVelocityX, preSWUVelocityY, preSWUVelocityZ); + this->SWUPressure = preSWUPressure; + this->SWUEnergy = Energy( SWUDensity, SWUPressure, gamma, SWUVelocity); + this->SWUMomentum = SWUVelocity * SWUDensity; + this->SWUTurbulentEnergy = SWUDensity * TurbulentEnergy( SWUVelocity, this->intensity); + this->SWUDisipation = this->turbulenceConstant * std::pow( SWUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + this->NWDDensity = preNWDDensity; + this->NWDVelocity = PointLoad(preNWDVelocityX, preNWDVelocityY, preNWDVelocityZ); + this->NWDPressure = preNWDPressure; + this->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); + this->NWDMomentum = NWDVelocity * NWDDensity; + this->NWDTurbulentEnergy = NWDDensity * TurbulentEnergy( NWDVelocity, this->intensity); + this->NWDDisipation = this->turbulenceConstant * std::pow( NWDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + this->SWDDensity = preSWDDensity; + this->SWDVelocity = PointLoad(preSWDVelocityX, preSWDVelocityY, preSWDVelocityZ); + this->SWDPressure = preSWDPressure; + this->SWDEnergy = Energy( SWDDensity, SWDPressure, gamma, SWDVelocity); + this->SWDMomentum = SWDVelocity * SWDDensity; + this->SWDTurbulentEnergy = SWDDensity * TurbulentEnergy( SWDVelocity, this->intensity); + this->SWDDisipation = this->turbulenceConstant * std::pow( SWDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + this->NEUDensity = preNEUDensity; + this->NEUVelocity = PointLoad(preNEUVelocityX, preNEUVelocityY, preNEUVelocityZ); + this->NEUPressure = preNEUPressure; + this->NEUEnergy = Energy( NEUDensity, NEUPressure, gamma, NEUVelocity); + this->NEUMomentum = NEUVelocity * NEUDensity; + this->NEUTurbulentEnergy = NEUDensity * TurbulentEnergy( NEUVelocity, this->intensity); + this->NEUDisipation = this->turbulenceConstant * std::pow( NEUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + this->SEUDensity = preSEUDensity; + this->SEUVelocity = PointLoad(preSEUVelocityX, preSEUVelocityY, preSEUVelocityZ); + this->SEUPressure = preSEUPressure; + this->SEUEnergy = Energy( SEUDensity, SEUPressure, gamma, SEUVelocity); + this->SEUMomentum = SEUVelocity * SEUDensity; + this->SEUTurbulentEnergy = TurbulentEnergy( SEUVelocity, this->intensity); + this->SEUDisipation = this->turbulenceConstant * std::pow( SEUTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + this->NEDDensity = preNEDDensity; + this->NEDVelocity = PointLoad(preNEDVelocityX, preNEDVelocityY, preNEDVelocityZ); + this->NEDPressure = preNEDPressure; + this->NEDEnergy = Energy( NEDDensity, NEDPressure, gamma, NEDVelocity); + this->NEDMomentum = NEDVelocity * NEDDensity; + this->NEDTurbulentEnergy = NEDDensity * TurbulentEnergy( NEDVelocity, this->intensity); + this->NEDDisipation = this->turbulenceConstant * std::pow( NEDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + this->SEDDensity = preSEDDensity; + this->SEDVelocity = PointLoad(preSEDVelocityX, preSEDVelocityY, preSEDVelocityZ); + this->SEDPressure = preSEDPressure; + this->SEDEnergy = Energy( SEDDensity, SEDPressure, gamma, SEDVelocity); + this->SEDMomentum = SEDVelocity * SEDDensity; + this->SEDTurbulentEnergy = SEDDensity * TurbulentEnergy( SEDVelocity, this->intensity); + this->SEDDisipation = this->turbulenceConstant * std::pow( SEDTurbulentEnergy, (3.0 / 2.0 ) ) / this->lengthScale; + + } + + 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[ 2 ], 2 ))); + break; // druhou mocninu ps8t jako sou4in + } + return energy; + } + + RealType TurbulentEnergy( PointType Velocity, RealType intensity ) + { + RealType turbulentEnergy; + switch (Dimensions) + { + case 1: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ))); + break; + case 2: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ))); + break; + case 3: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 2 ], 2 ))); + break; // druhou mocninu ps8t jako sou4in + } + return turbulentEnergy; + } + + void setInitialCondition( CompressibleConservativeVariables< MeshType >& conservativeVariables, + const PointType& center = PointType( 0.0 ) ) + { + RiemannProblemInitialConditionSetter* variablesSetter = new RiemannProblemInitialConditionSetter; + 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->setTurbulentEnergy(this->NWUTurbulentEnergy, + this->NEUTurbulentEnergy, + this->SWUTurbulentEnergy, + this->SEUTurbulentEnergy, + this->NWDTurbulentEnergy, + this->NEDTurbulentEnergy, + this->SWDTurbulentEnergy, + this->SEDTurbulentEnergy); + variablesSetter->setDisipation(this->NWUDisipation, + this->NEUDisipation, + this->SWUDisipation, + this->SEUDisipation, + this->NWDDisipation, + this->NEDDisipation, + this->SWDDisipation, + this->SEDDisipation); + variablesSetter->setDiscontinuity(this->discontinuityPlacement); + variablesSetter->placeDensity(conservativeVariables); + variablesSetter->placeMomentum(conservativeVariables); + variablesSetter->placeEnergy(conservativeVariables); + variablesSetter->placeTurbulentEnergy(conservativeVariables); + variablesSetter->placeDisipation(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 NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + RealType leftDensity, rightDensity; + PointType leftVelocity, rightVelocity; + RealType leftPressure, rightPressure; + + RealType gamma; // gamma in the ideal gas state equation +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/flowsBuildConfigTag.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/flowsBuildConfigTag.h new file mode 100644 index 0000000000000000000000000000000000000000..c40b793b9e237d0ad756a66c57088373cad3e41b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/flowsBuildConfigTag.h @@ -0,0 +1,72 @@ +#ifndef FLOWSBUILDCONFIGTAG_H_ +#define FLOWSBUILDCONFIGTAG_H_ + +#include +#include + +namespace TNL { + +class flowsBuildConfigTag{}; + +namespace Solvers { + +/**** + * Turn off support for float and long double. + */ +template<> struct ConfigTagReal< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct ConfigTagReal< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct ConfigTagIndex< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct ConfigTagIndex< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +//template< int Dimension > struct ConfigTagDimension< flowsBuildConfigTag, 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< flowsBuildConfigTag, Meshes::Grid< Dimension, Real, Device, Index > > + { enum { enabled = ConfigTagDimension< flowsBuildConfigTag, Dimension >::enabled && + ConfigTagReal< flowsBuildConfigTag, Real >::enabled && + ConfigTagDevice< flowsBuildConfigTag, Device >::enabled && + ConfigTagIndex< flowsBuildConfigTag, Index >::enabled }; }; +*/ +/**** + * Please, chose your preferred time discretisation here. + */ +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ExplicitTimeDiscretisationTag >{ enum { enabled = true }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, SemiImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; + +/**** + * Only the Runge-Kutta-Merson solver is enabled by default. + */ +template<> struct ConfigTagExplicitSolver< flowsBuildConfigTag, ExplicitEulerSolverTag >{ enum { enabled = true }; }; + +} // namespace Solvers + +namespace Meshes { +namespace BuildConfigTags { + +template< int Dimensions > struct GridDimensionTag< flowsBuildConfigTag, Dimensions >{ enum { enabled = true }; }; + +/**** + * Turn off support for float and long double. + */ +template<> struct GridRealTag< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct GridRealTag< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct GridIndexTag< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct GridIndexTag< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +} // namespace BuildConfigTags +} // namespace Meshes +} // namespace TNL + +#endif /* FLOWSBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/inviscid-flow-sw/eulerRhs.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/flowsRhs.h similarity index 71% rename from src/Examples/inviscid-flow-sw/eulerRhs.h rename to src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/flowsRhs.h index 51d4e024398d579f49c158292e2890536a1e319c..e0b8c7fac887f2b8ea588020ede105d9c8950888 100644 --- a/src/Examples/inviscid-flow-sw/eulerRhs.h +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/flowsRhs.h @@ -1,11 +1,11 @@ -#ifndef eulerRHS_H_ -#define eulerRHS_H_ +#ifndef FLOWSRHS_H_ +#define FLOWSRHS_H_ #include namespace TNL { -template< typename Mesh, typename Real >class eulerRhs +template< typename Mesh, typename Real >class flowsRhs : public Functions::Domain< Mesh::getMeshDimension(), Functions::MeshDomain > { public: @@ -24,12 +24,12 @@ template< typename Mesh, typename Real >class eulerRhs Real operator()( const MeshEntity& entity, const Real& time = 0.0 ) const { - typedef typename MeshEntity::MeshType::PointType PointType; - PointType v = entity.getCenter(); +// typedef typename MeshEntity::MeshType::PointType PointType; +// PointType v = entity.getCenter(); return 0.0; } }; } //namespace TNL -#endif /* eulerRHS_H_ */ +#endif /* FLOWSRHS_H_ */ diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model new file mode 100644 index 0000000000000000000000000000000000000000..cd0c1bbb1426405814d32e2e1f3222e79bb11c8d --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model @@ -0,0 +1,40 @@ +#!/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-euler-navier-stokes + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --differential-operator Steger-Warming \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-AUSM-plus b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-AUSM-plus new file mode 100644 index 0000000000000000000000000000000000000000..faaad26b48f1fbea1002c066b6bfce61e323b7e7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-AUSM-plus @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Ausm-Plus + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Lax-Friedrichs b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Lax-Friedrichs new file mode 100644 index 0000000000000000000000000000000000000000..5f7bfbdc6d6e7ebe6dd69663eeea28a5c6dc770f --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Lax-Friedrichs @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Lax-Friedrichs + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Steger-Warming b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Steger-Warming new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Steger-Warming @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Van-Leer b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Van-Leer new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/run-two-equation-turbulence-model-Van-Leer @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.cpp b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4f35360ff6a853fde03482e65724cc8e15c73c3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.cu b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.cu new file mode 100644 index 0000000000000000000000000000000000000000..a4f35360ff6a853fde03482e65724cc8e15c73c3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.h new file mode 100644 index 0000000000000000000000000000000000000000..047a44e006a83b4cd08f12535662ec7dffb11a23 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModel.h @@ -0,0 +1,276 @@ +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/Lax-Friedrichs/LaxFridrichs.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/Steger-Warming/StegerWarming.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/VanLeer/VanLeer.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "differential-operator", "Choose the differential operator.", "Lax-Friedrichs"); + config.addEntryEnum< String >( "Lax-Friedrichs" ); + config.addEntryEnum< String >( "Steger-Warming" ); + config.addEntryEnum< String >( "VanLeer" ); + config.addEntryEnum< String >( "AUSMPlus" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef twoEquationTurbulenceModelOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + String differentialOperatorType = parameters.getParameter< String >( "differential-operator"); + if( differentialOperatorType == "Lax-Friedrichs" ) + { + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "Steger-Warming" ) + { + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "VanLeer" ) + { + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "AUSMPlus" ) + { + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + + + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.cpp b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9c751db2a977e309c47122b52f7a76597f913d5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.cu b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.cu new file mode 100644 index 0000000000000000000000000000000000000000..c9c751db2a977e309c47122b52f7a76597f913d5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..6b5cf4297a3fb17add3ccbb152709d3a1be2df16 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelAUSMPlus.h @@ -0,0 +1,145 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "viscosity-constant-1", "Value of viscosity constant C_epsilon_1", 1.0 ); + config.addEntry< double >( "viscosity-constant-2", "Value of viscosity constant C_epsilon_2", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + AUSMPlus< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KEpsilonOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.cpp b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a17eddc7694ea4d253abb4dbc51445246f2725b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.cu b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.cu new file mode 100644 index 0000000000000000000000000000000000000000..0a17eddc7694ea4d253abb4dbc51445246f2725b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..0c1668882c5496544f958b21132b1c64052d12c1 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelLaxFriedrichs.h @@ -0,0 +1,145 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "viscosity-constant-1", "Value of viscosity constant C_epsilon_1", 1.0 ); + config.addEntry< double >( "viscosity-constant-2", "Value of viscosity constant C_epsilon_2", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KEpsilonOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelProblem.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelProblem.h new file mode 100644 index 0000000000000000000000000000000000000000..4b948b3a38a2d5968e9dd718db39759f684f1ac6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelProblem.h @@ -0,0 +1,150 @@ +/*************************************************************************** + twoEquationTurbulenceModelProblem.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 +#include +#include +#include "CompressibleConservativeVariables.h" + + +using namespace TNL::Problems; + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +class twoEquationTurbulenceModelProblem: + public PDEProblem< Mesh, + Communicator, + typename InviscidOperators::RealType, + typename Mesh::DeviceType, + typename InviscidOperators::IndexType > +{ + public: + + typedef typename InviscidOperators::RealType RealType; + typedef typename Mesh::DeviceType DeviceType; + typedef typename InviscidOperators::IndexType IndexType; + typedef PDEProblem< Mesh, Communicator, RealType, DeviceType, IndexType > BaseType; + + typedef Communicator CommunicatorType; + + using typename BaseType::MeshType; + using typename BaseType::MeshPointer; + using typename BaseType::DofVectorType; + using typename BaseType::DofVectorPointer; + static const int Dimensions = Mesh::getMeshDimension(); + + typedef Functions::MeshFunction< Mesh > MeshFunctionType; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< InviscidOperators > InviscidOperatorsPointer; + typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; + typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; + + static String getType(); + + String getPrologHeader() const; + + void writeProlog( Logger& logger, + const Config::ParameterContainer& parameters ) const; + + bool setup( const Config::ParameterContainer& parameters, + const String& prefix = "" ); + + bool setInitialCondition( const Config::ParameterContainer& parameters, + DofVectorPointer& dofs ); + + template< typename Matrix > + bool setupLinearSystem( Matrix& matrix ); + + bool makeSnapshot( const RealType& time, + const IndexType& step, + DofVectorPointer& dofs ); + + IndexType getDofs() const; + + void bindDofs( DofVectorPointer& dofs ); + + void getExplicitUpdate( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + DofVectorPointer& _fu ); + + + void applyBoundaryConditions( const RealType& time, + DofVectorPointer& dofs ); + + template< typename Matrix > + void assemblyLinearSystem( const RealType& time, + const RealType& tau, + DofVectorPointer& dofs, + Matrix& matrix, + DofVectorPointer& rightHandSide ); + + bool postIterate( const RealType& time, + const RealType& tau, + DofVectorPointer& dofs ); + + protected: + + InviscidOperatorsPointer inviscidOperatorsPointer; + + BoundaryConditionPointer boundaryConditionPointer; + RightHandSidePointer rightHandSidePointer; + + ConservativeVariablesPointer conservativeVariables, + conservativeVariablesRHS; + + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::ContinuityOperatorType, typename BoundaryCondition::DensityBoundaryConditionsType, RightHandSide > explicitUpdaterContinuity; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumXOperatorType, typename BoundaryCondition::MomentumXBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumX; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumYOperatorType, typename BoundaryCondition::MomentumYBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumY; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumZOperatorType, typename BoundaryCondition::MomentumZBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumZ; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::EnergyOperatorType, typename BoundaryCondition::EnergyBoundaryConditionsType, RightHandSide > explicitUpdaterEnergy; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::TurbulentEnergyOperatorType, typename BoundaryCondition::TurbulentEnergyBoundaryConditionsType, RightHandSide > explicitUpdaterTurbulentEnergy; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::DisipationOperatorType, typename BoundaryCondition::DisipationBoundaryConditionsType, RightHandSide > explicitUpdaterDisipation; + + + VelocityFieldPointer velocity; + MeshFunctionPointer pressure; + MeshFunctionPointer turbulentViscosity; + MeshFunctionPointer turbulentEnergy; + MeshFunctionPointer disipation; + + RealType gamma; + RealType speedIncrement; + RealType cavitySpeed; + RealType speedIncrementUntil; + RealType finalSpeed; + RealType startSpeed; + RealType speedIncrementUntilHThrottle; + RealType finalSpeedHThrottle; + RealType startSpeedHThrottle; + RealType turbulenceConstant; + RealType sigmaK; + RealType sigmaEpsilon; + RealType viscosityConstant1; + RealType viscosityConstant2; + RealType intensity; + RealType lengthScale; +}; + +} // namespace TNL + +#include "twoEquationTurbulenceModelProblem_impl.h" + diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelProblem_impl.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..c7c6b3b7c36ebe3210835a39e4a3a08913161cbe --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelProblem_impl.h @@ -0,0 +1,569 @@ +/*************************************************************************** + twoEquationTurbulenceModelProblem_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 +#include +#include +#include +#include +#include + +#include "RiemannProblemInitialCondition.h" +#include "CompressibleConservativeVariables.h" +#include "PhysicalVariablesGetter.h" +#include "twoEquationTurbulenceModelProblem.h" + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getType() +{ + return String( "twoEquationTurbulenceModelProblem< " ) + Mesh :: getType() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getPrologHeader() const +{ + return String( "flow solver" ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, 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 Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setup( const Config::ParameterContainer& parameters, + const String& prefix ) +{ + if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || + ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || + ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) + return false; + this->gamma = parameters.getParameter< double >( "gamma" ); + this->startSpeed = parameters.getParameter< double >( "start-speed" ); + this->finalSpeed = parameters.getParameter< double >( "final-speed" ); + this->speedIncrementUntil = parameters.getParameter< RealType >( "speed-increment-until" ); + this->startSpeedHThrottle = parameters.getParameter< double >( "start-speed-h-throttle" ); + this->finalSpeedHThrottle = parameters.getParameter< double >( "final-speed-h-throttle" ); + this->speedIncrementUntilHThrottle = parameters.getParameter< RealType >( "speed-increment-until-h-throttle" ); + this->turbulenceConstant = parameters.getParameter< double >( "turbulence-constant" ); + this->viscosityConstant1 = parameters.getParameter< double >( "viscosity-constant-1" ); + this->viscosityConstant2 = parameters.getParameter< double >( "viscosity-constant-2" ); + this->sigmaK = parameters.getParameter< double >( "sigma-k" ); + this->sigmaEpsilon = parameters.getParameter< double >( "sigma-epsilon" ); + this->intensity = parameters.getParameter< double >( "turbulence-intensity" ); + this->lengthScale = parameters.getParameter< double >( "turbulence-length-scale" ); + velocity->setMesh( this->getMesh() ); + pressure->setMesh( this->getMesh() ); + turbulentViscosity->setMesh( this->getMesh() ); + turbulentEnergy->setMesh( this->getMesh() ); + disipation->setMesh( this->getMesh() ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setSigmaK( this->sigmaK ); + this->inviscidOperatorsPointer->setSigmaEpsilon( this->sigmaEpsilon ); + this->inviscidOperatorsPointer->setViscosityConstant1( this->viscosityConstant1 ); + this->inviscidOperatorsPointer->setViscosityConstant2( this->viscosityConstant2 ); + this->inviscidOperatorsPointer->setDisipation( this->disipation ); + this->inviscidOperatorsPointer->setVelocity( this->velocity ); + this->inviscidOperatorsPointer->setPressure( this->pressure ); + this->inviscidOperatorsPointer->setDensity( this->conservativeVariables->getDensity() ); + this->inviscidOperatorsPointer->setGamma( this->gamma ); + this->inviscidOperatorsPointer->setTurbulentViscosity( this->turbulentViscosity ); + this->inviscidOperatorsPointer->setTurbulentEnergy( this->turbulentEnergy ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); + this->explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer->getDensityBoundaryCondition() ); + this->explicitUpdaterContinuity.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumXOperator() ); + this->explicitUpdaterMomentumX.setBoundaryConditions( this->boundaryConditionPointer->getMomentumXBoundaryCondition() ); + this->explicitUpdaterMomentumX.setRightHandSide( this->rightHandSidePointer ); + + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumYOperator() ); + this->explicitUpdaterMomentumY.setBoundaryConditions( this->boundaryConditionPointer->getMomentumYBoundaryCondition() ); + this->explicitUpdaterMomentumY.setRightHandSide( this->rightHandSidePointer ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumZOperator() ); + this->explicitUpdaterMomentumZ.setBoundaryConditions( this->boundaryConditionPointer->getMomentumZBoundaryCondition() ); + this->explicitUpdaterMomentumZ.setRightHandSide( this->rightHandSidePointer ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getEnergyOperator() ); + this->explicitUpdaterEnergy.setBoundaryConditions( this->boundaryConditionPointer->getEnergyBoundaryCondition() ); + this->explicitUpdaterEnergy.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getTurbulentEnergyOperator() ); + this->explicitUpdaterTurbulentEnergy.setBoundaryConditions( this->boundaryConditionPointer->getTurbulentEnergyBoundaryCondition() ); + this->explicitUpdaterTurbulentEnergy.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Disipation equation + */ + this->explicitUpdaterDisipation.setDifferentialOperator( this->inviscidOperatorsPointer->getDisipationOperator() ); + this->explicitUpdaterDisipation.setBoundaryConditions( this->boundaryConditionPointer->getDisipationBoundaryCondition() ); + this->explicitUpdaterDisipation.setRightHandSide( this->rightHandSidePointer ); + + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +typename twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >::IndexType +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getDofs() const +{ + /**** + * Return number of DOFs (degrees of freedom) i.e. number + * of unknowns to be resolved by the main solver. + */ + return this->conservativeVariables->getDofs( this->getMesh() ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +bindDofs( DofVectorPointer& dofVector ) +{ + this->conservativeVariables->bind( this->getMesh(), dofVector ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setInitialCondition( const Config::ParameterContainer& parameters, + DofVectorPointer& dofs ) +{ + CompressibleConservativeVariables< MeshType > conservativeVariables; + conservativeVariables.bind( this->getMesh(), 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 Communicator, + typename InviscidOperators > + template< typename Matrix > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setupLinearSystem( Matrix& matrix ) +{ +/* const IndexType dofs = this->getDofs(); + 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 Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +makeSnapshot( const RealType& time, + const IndexType& step, + DofVectorPointer& dofs ) +{ + std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; + + this->bindDofs( 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() ) ) + this->conservativeVariables->getDensity()->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "velocity-" ); +// if( ! this->velocity->save( fileName.getFileName() ) ) + this->velocity->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "pressure-" ); +// if( ! this->pressure->save( fileName.getFileName() ) ) + this->pressure->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "energy-" ); +// if( ! this->conservativeVariables->getEnergy()->save( fileName.getFileName() ) ) + this->conservativeVariables->getEnergy()->save( fileName.getFileName() ); +// return false; + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getExplicitUpdate( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + DofVectorPointer& _fu ) +{ + typedef typename MeshType::Cell Cell; + + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), _u ); + this->conservativeVariablesRHS->bind( this->getMesh(), _fu ); + + /**** + * Resolve the physical variables + */ + PhysicalVariablesGetter< typename MeshPointer::ObjectType > physicalVariables; + physicalVariables.getVelocity( this->conservativeVariables, this->velocity ); + physicalVariables.getPressure( this->conservativeVariables, this->gamma, this->pressure ); + physicalVariables.getTurbulentEnergy( this->conservativeVariables, this->turbulentEnergy ); + physicalVariables.getDisipation( this->conservativeVariables, this->disipation ); + physicalVariables.getTurbulentViscosity( this->conservativeVariables, this->turbulentEnergy, this->disipation, this->turbulenceConstant, this->turbulentViscosity ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setTau( tau ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getDensity(), + this->conservativeVariablesRHS->getDensity() ); + +// this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, +// this->conservativeVariables->getDensity() ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 0 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 0 ] ); //, fuRhoVelocityX ); + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 1 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 1 ] ); //, fuRhoVelocityX ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 2 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 2 ] ); //, fuRhoVelocityX ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); + + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getTurbulentEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getTurbulentEnergy() ); //, fuRhoVelocityX ); + + /**** + * Disipation equation + */ + this->explicitUpdaterTurbulentEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getDisipation(), // uRhoVelocityX, + this->conservativeVariablesRHS->getDisipation() ); //, fuRhoVelocityX ); + + /*this->conservativeVariablesRHS->getDensity()->write( "density", "gnuplot" ); + this->conservativeVariablesRHS->getEnergy()->write( "energy", "gnuplot" ); + this->conservativeVariablesRHS->getMomentum()->write( "momentum", "gnuplot", 0.05 ); + getchar();*/ + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +applyBoundaryConditions( const RealType& time, + DofVectorPointer& dofs ) +{ + /**** + * Update Boundary Conditions + */ + if(this->speedIncrementUntil > time ) + { + this->boundaryConditionPointer->setTimestep(this->speedIncrement); + } + else + { + this->boundaryConditionPointer->setTimestep(0); + } + this->boundaryConditionPointer->setIntensity(this->intensity); + this->boundaryConditionPointer->setLengthScale(this->lengthScale); + this->boundaryConditionPointer->setTurbulenceConstant(this->turbulenceConstant); + this->boundaryConditionPointer->setSpeed(this->cavitySpeed); + this->boundaryConditionPointer->setCompressibleConservativeVariables(this->conservativeVariables); + this->boundaryConditionPointer->setGamma(this->gamma); + this->boundaryConditionPointer->setPressure(this->pressure); + this->boundaryConditionPointer->setVerticalThrottleSpeed( startSpeed, finalSpeed, time, speedIncrementUntil ); + this->boundaryConditionPointer->setHorizontalThrottleSpeed( startSpeedHThrottle, finalSpeedHThrottle, time, speedIncrementUntilHThrottle ); + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), dofs ); +// this->conservativeVariables->getDensity()->write( "density", "gnuplot" ); +// this->conservativeVariables->getEnergy()->write( "energy", "gnuplot" ); +// this->conservativeVariables->getMomentum()->write( "momentum", "gnuplot", 0.05 ); +// dofs->save("dofs.tnl"); +// getchar(); +// std::cout <<"applyBCC" << std::endl; + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getDensity() ); + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 0 ] ); // uRhoVelocityX, + if( Dimensions > 1 ) + { + + this->explicitUpdaterMomentumY.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 1 ] ); // uRhoVelocityX, + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 2 ] ); // uRhoVelocityX, + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getEnergy() ); // uRhoVelocityX, + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getTurbulentEnergy() ); // uRhoVelocityX, + /**** + * Turbulent energy equation + */ + this->explicitUpdaterDisipation.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getDisipation() ); // uRhoVelocityX, + + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > + template< typename Matrix > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +assemblyLinearSystem( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + Matrix& matrix, + DofVectorPointer& b ) +{ +/* LinearSystemAssembler< Mesh, + MeshFunctionType, + InviscidOperators, + BoundaryCondition, + RightHandSide, + BackwardTimeDiscretisation, + Matrix, + DofVectorType > systemAssembler; + + MeshFunction< Mesh > u( mesh, _u ); + systemAssembler.template assembly< typename Mesh::Cell >( time, + tau, + this->differentialOperator, + this->boundaryCondition, + this->rightHandSide, + u, + matrix, + b );*/ +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +postIterate( const RealType& time, + const RealType& tau, + DofVectorPointer& dofs ) +{ + /* + 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/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.cpp b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30a2938a74488d83b4c6f5dfd17fe4a6560fe6f0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelStegerWarming.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.cu b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.cu new file mode 100644 index 0000000000000000000000000000000000000000..30a2938a74488d83b4c6f5dfd17fe4a6560fe6f0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelStegerWarming.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..511d7a5e156d41ce0d88aa7a1b2a24a09eaebe62 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelStegerWarming.h @@ -0,0 +1,145 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "viscosity-constant-1", "Value of viscosity constant C_epsilon_1", 1.0 ); + config.addEntry< double >( "viscosity-constant-2", "Value of viscosity constant C_epsilon_2", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + StegerWarming< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KEpsilonOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.cpp b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2bd33e16a63676adbe48957ceb3277b9005d23b7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelVanLeer.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.cu b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.cu new file mode 100644 index 0000000000000000000000000000000000000000..a4f35360ff6a853fde03482e65724cc8e15c73c3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.h b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..d03d38ce4089e4bb5e8efd72c17b4754c82b5bfa --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KEPsilon-model/twoEquationTurbulenceModelVanLeer.h @@ -0,0 +1,145 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KEPsilonRightHandSide/KEpsilonOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "viscosity-constant-1", "Value of viscosity constant C_epsilon_1", 1.0 ); + config.addEntry< double >( "viscosity-constant-2", "Value of viscosity constant C_epsilon_2", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + VanLeer< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KEpsilonOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..0709bc3b93fb040bb62e479adb611346485af0f6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h @@ -0,0 +1,190 @@ +#include + +#include "DensityBoundaryConditionBoiler.h" +#include "MomentumXBoundaryConditionBoiler.h" +#include "MomentumYBoundaryConditionBoiler.h" +#include "MomentumZBoundaryConditionBoiler.h" +#include "EnergyBoundaryConditionBoiler.h" +#include "TurbulentEnergyBoundaryConditionBoiler.h" +#include "DisipationBoundaryConditionBoiler.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 TNL::Operators::TurbulentEnergyBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DisipationBoundaryConditionsBoiler< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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); + this->disipationBoundaryConditionsPointer->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); + this->turbulentEnergyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->disipationBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + void setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + this->disipationBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setLengthScale( const RealType& lengthScale ) + { + this->disipationBoundaryConditionsPointer->setLengthScale ( lengthScale ); + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->disipationBoundaryConditionsPointer->setTurbulenceConstant ( turbulenceConstant ); + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..6231f6780e24e3090c83832c9d47534a9c6104a8 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/DisipationBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/DisipationBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..4ddfd0d61e241e110e9ba77c97bbcace3a5890a9 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/DisipationBoundaryConditionBoiler.h @@ -0,0 +1,709 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DisipationBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function> +class DisipationBoundaryConditionsBoilerBase +{ + 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 DisipationBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerBase< 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 DisipationBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerBase< 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 DisipationBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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, 0 >() ]; + /*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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerBase< 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 DisipationBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DisipationBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..412640b5472f0e85026e26954503a6412bba0c39 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h @@ -0,0 +1,853 @@ +/*************************************************************************** + 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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..dfe63e07623a6fdb6ca7ebb7da8ab445d9505372 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..83b6282ddd50033f32a382f0b48f5abe7347ccaa --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..9d887857ce97f916dcfaccd0208138afc200afd1 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..e6b63da71803c661c620326a866389de874beca6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Boiler/TurbulentEnergyBoundaryConditionBoiler.h @@ -0,0 +1,664 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsBoiler +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsBoilerBase +{ + 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 TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * 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())[ 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * 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, 0 >() ]; + /*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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoiler< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerBase< 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 TurbulentEnergyBoundaryConditionsBoiler< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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 2.0/3.0 * this->intensity * this->intensity * 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsBoiler< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsBoiler: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..44e2b9531ffa6968838775d9084d0f4045004554 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h @@ -0,0 +1,237 @@ +#include + +#include "DensityBoundaryConditionBoilerModel.h" +#include "MomentumXBoundaryConditionBoilerModel.h" +#include "MomentumYBoundaryConditionBoilerModel.h" +#include "MomentumZBoundaryConditionBoilerModel.h" +#include "EnergyBoundaryConditionBoilerModel.h" +#include "TurbulentEnergyBoundaryConditionBoilerModel.h" +#include "DisipationBoundaryConditionBoilerModel.h" + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class BoundaryConditionsBoilerModel +{ + 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::DensityBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::MomentumXBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::MomentumYBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::MomentumZBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::EnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DisipationBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "vertical-angle", "Vertical angle of throttle in degrees", 0 ); + config.addEntry< double >( prefix + "horizontal-angle", "Horizontal angle of throttle in degrees", 45 ); + } + + 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); + setZAngle(parameters.getParameter< double >( prefix + "vertical-angle" ) * M_PI / 180.0 ); + setXYAngle(parameters.getParameter< double >( prefix + "horizontal-angle" ) * M_PI / 180.0 ); + 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); + this->turbulentEnergyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->disipationBoundaryConditionsPointer->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 setZAngle(const RealType zAngle) + { + this->densityBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumXBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumYBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumZBoundaryConditionsPointer->setZAngle(zAngle); + this->energyBoundaryConditionsPointer->setZAngle(zAngle); + this->turbulentEnergyBoundaryConditionsPointer->setZAngle(zAngle); + this->disipationBoundaryConditionsPointer->setZAngle(zAngle); + } + + void setXYAngle(const RealType xYAngle) + { + this->densityBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumXBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumYBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumZBoundaryConditionsPointer->setXYAngle(xYAngle); + this->turbulentEnergyBoundaryConditionsPointer->setXYAngle(xYAngle); + this->disipationBoundaryConditionsPointer->setXYAngle(xYAngle); + } + + 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 setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + this->disipationBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setLengthScale( const RealType& lengthScale ) + { + this->disipationBoundaryConditionsPointer->setLengthScale ( lengthScale ); + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->disipationBoundaryConditionsPointer->setTurbulenceConstant ( turbulenceConstant ); + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType horizontalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + horizontalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + horizontalThrottleSpeed = 0; + else + horizontalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->energyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->turbulentEnergyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->disipationBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType verticalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + verticalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + verticalThrottleSpeed = 0; + else + verticalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->energyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->turbulentEnergyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->disipationBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..a58f32f7c577590801504d675dec55243e2f0b57 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h @@ -0,0 +1,580 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DensityBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class DensityBoundaryConditionsBoilerModelBase +{ + 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 DensityBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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.835 * ( entity.getMesh().getDimensions().y() - 1 )) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ 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, -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 setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 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 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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DensityBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/DisipationBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/DisipationBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..a112001cc693a32ca3b8d9ee1462eb578f2e0e03 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/DisipationBoundaryConditionBoilerModel.h @@ -0,0 +1,881 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DisipationBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class DisipationBoundaryConditionsBoilerModelBase +{ + 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 DisipationBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerModelBase< 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 DisipationBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerModelBase< 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 DisipationBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle Disipation + { + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle Disipation + { + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + } +// if for chimney exit + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed ) ) + / this->lengthScale; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsBoilerModelBase< 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 DisipationBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DisipationBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed ) ) + / this->lengthScale; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DisipationBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..d0475576b5fa910528eaa3c7a80ffd8047bddcc9 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,962 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class EnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class EnergyBoundaryConditionsBoilerModelBase +{ + 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 EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const EnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..893815913ba45510c520de2033d7be690faea8bb --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h @@ -0,0 +1,940 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumXBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumXBoundaryConditionsBoilerModelBase +{ + 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 MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumXBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..e8aa33e885efcc06f134a94f7e6df8cb974fb417 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h @@ -0,0 +1,941 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumYBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumYBoundaryConditionsBoilerModelBase +{ + 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 MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( - 1.0 ) + * std::sin( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) +// down throttle + { + if( + ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumYBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..ee40b1b74066d4c5ee0491345538577525a7e4f5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h @@ -0,0 +1,838 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumZBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumZBoundaryConditionsBoilerModelBase +{ + 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 MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( + ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.408 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumZBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..851b706184862400daae12810271d7ba6c9753e8 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/BoilerModel/TurbulentEnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,832 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsBoilerModelBase +{ + 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 TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle TurbulentEnergy + { + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle TurbulentEnergy + { + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + } +// if for chimney exit + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed; + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsBoilerModelBase< 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 TurbulentEnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef TurbulentEnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed;; + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed; + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return 2.0/3.0 * this->intensity * this->intensity * this->horizontalThrottleSpeed * this->horizontalThrottleSpeed;; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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 2.0/3.0 * this->intensity * this->intensity * this->verticalThrottleSpeed * this->verticalThrottleSpeed;; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + RealType intensity; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..e2adc74244d8556338b30bc42b94fd5965f56ca6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h @@ -0,0 +1,193 @@ +#include + +#include "DensityBoundaryConditionCavity.h" +#include "MomentumXBoundaryConditionCavity.h" +#include "MomentumYBoundaryConditionCavity.h" +#include "MomentumZBoundaryConditionCavity.h" +#include "EnergyBoundaryConditionCavity.h" +#include "TurbulentEnergyBoundaryConditionCavity.h" +#include "DisipationBoundaryConditionCavity.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 TNL::Operators::TurbulentEnergyBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DisipationBoundaryConditionsCavity< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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); + this->turbulentEnergyBoundaryConditionsPointer->setup( meshPointer, parameters, prefix); + this->disipationBoundaryConditionsPointer->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); + this->turbulentEnergyBoundaryConditionsPointer->setCompressibleConservativeVariables(compressibleConservativeVariables); + this->disipationBoundaryConditionsPointer->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); + this->turbulentEnergyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + this->disipationBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); + } + + void setIntensity(const RealType& intensity) + { + this->turbulentEnergyBoundaryConditionsPointer->setIntensity( intensity ); + this->disipationBoundaryConditionsPointer->setIntensity( intensity ); + } + + void setLengthScale( const RealType& lengthScale ) + { + this->disipationBoundaryConditionsPointer->setLengthScale ( lengthScale ); + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->disipationBoundaryConditionsPointer->setTurbulenceConstant ( turbulenceConstant ); + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..c753d324a288a331dbfb9d73e341fe962f39889e --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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< 1, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ 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 >() ]; + } + } + + 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/DisipationBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/DisipationBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..6f15f3f884e47f5ec14e677f37088ca1367a602b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/DisipationBoundaryConditionCavity.h @@ -0,0 +1,607 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DisipationBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function> +class DisipationBoundaryConditionsCavityBase +{ + 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 DisipationBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + } + } + + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DisipationBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DisipationBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 std::sqrt( ( 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed ) ) + / this->lengthScale; + } + } + + + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + void setLengthScale( const RealType& lengthScale ) + { + this->lengthScale = lengthScale; + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + this->turbulenceConstant = turbulenceConstant; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DisipationBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..ca5d85442d02edeb7ddd39749c6441c13e3eb6ed --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h @@ -0,0 +1,672 @@ +/*************************************************************************** + 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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..07abfdbeb940039555ac2799d0ef374ca26faff0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..a83dd653f92328814b8d0746bc45c8775552a310 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..5fe6f22e5945513c9e9e86d835256ef84e27c054 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..05098c7ddf400f05d49e35794cd92944013cd32a --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Cavity/TurbulentEnergyBoundaryConditionCavity.h @@ -0,0 +1,568 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class TurbulentEnergyBoundaryConditionsCavity +{ + +}; + +/**** + * Base + */ +template< typename Function> +class TurbulentEnergyBoundaryConditionsCavityBase +{ + 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 TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * this->cavitySpeed; + 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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 >(), -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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class TurbulentEnergyBoundaryConditionsCavity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public TurbulentEnergyBoundaryConditionsCavityBase< 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 2.0/3.0 * this->intensity * this->intensity * this->cavitySpeed * 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; + } + + void setIntensity( const RealType& intensity ) + { + this->intensity = intensity; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType cavitySpeed; + RealType gamma; + RealType intensity; + MeshFunctionPointer pressure; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const TurbulentEnergyBoundaryConditionsCavity< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary ConditionsCavity: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h new file mode 100644 index 0000000000000000000000000000000000000000..8a93fd2fc447a91e7798ffae55c032e60e734e6e --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h @@ -0,0 +1,159 @@ +#include +#include +#include +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function = Functions::Analytic::Constant< Mesh::getMeshDimension(), typename Mesh::RealType >, + int MeshEntitiesDimension = Mesh::getMeshDimension(), + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsDirichlet +{ + 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::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setIntensity(const RealType& intensity) + { + + } + + void setLengthScale( const RealType& lengthScale ) + { + + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h new file mode 100644 index 0000000000000000000000000000000000000000..bc6c4bdecf3ccdd9b49f18574491827d693375ad --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h @@ -0,0 +1,155 @@ +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsNeumann +{ + 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::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > TurbulentEnergyBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > DisipationBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< TurbulentEnergyBoundaryConditionsType > TurbulentEnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< DisipationBoundaryConditionsType > DisipationBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setIntensity(const RealType& intensity) + { + + } + + void setLengthScale( const RealType& lengthScale ) + { + + } + + void setTurbulenceConstant( const RealType& turbulenceConstant ) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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; + } + + TurbulentEnergyBoundaryConditionsTypePointer& getTurbulentEnergyBoundaryCondition() + { + return this->turbulentEnergyBoundaryConditionsPointer; + } + + DisipationBoundaryConditionsTypePointer& getDisipationBoundaryCondition() + { + return this->disipationBoundaryConditionsPointer; + } + + + protected: + DensityBoundaryConditionsTypePointer densityBoundaryConditionsPointer; + MomentumXBoundaryConditionsTypePointer momentumXBoundaryConditionsPointer; + MomentumYBoundaryConditionsTypePointer momentumYBoundaryConditionsPointer; + MomentumZBoundaryConditionsTypePointer momentumZBoundaryConditionsPointer; + EnergyBoundaryConditionsTypePointer energyBoundaryConditionsPointer; + TurbulentEnergyBoundaryConditionsTypePointer turbulentEnergyBoundaryConditionsPointer; + DisipationBoundaryConditionsTypePointer disipationBoundaryConditionsPointer; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists.txt b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c170893b983c29042d41b39de863c7b73c9e7c2 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists.txt @@ -0,0 +1,101 @@ +#k-omega-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelLaxFriedrichs.cpp + twoEquationTurbulenceModelLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-omega-Lax-Friedrichs twoEquationTurbulenceModelLaxFriedrichs.cu) + target_link_libraries (tnl-k-omega-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-omega-Lax-Friedrichs twoEquationTurbulenceModelLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-omega-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#k-omega-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelStegerWarming.cpp + twoEquationTurbulenceModelStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-omega-Steger-Warming twoEquationTurbulenceModelStegerWarming.cu) + target_link_libraries (tnl-k-omega-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-omega-Steger-Warming twoEquationTurbulenceModelStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-omega-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#k-omega-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelVanLeer.cpp + twoEquationTurbulenceModelVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-omega-Van-Leer twoEquationTurbulenceModelVanLeer.cu) + target_link_libraries (tnl-k-omega-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-omega-Van-Leer twoEquationTurbulenceModelVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-omega-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#k-omega-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + twoEquationTurbulenceModelAUSMPlus.cpp + twoEquationTurbulenceModelAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-k-omega-AUSM-plus twoEquationTurbulenceModelAUSMPlus.cu) + target_link_libraries (tnl-k-omega-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-k-omega-AUSM-plus twoEquationTurbulenceModelAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-k-omega-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-two-equation-turbulence-model-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists_separate.txt b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists_separate.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd8e6f8708f7029abaf81aea4050908eb47bb71b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists_separate.txt @@ -0,0 +1,101 @@ +#navier-stokes-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesLaxFriedrichs.cpp + navierStokesLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cu) + target_link_libraries (tnl-navier-stokes-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesStegerWarming.cpp + navierStokesStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cu) + target_link_libraries (tnl-navier-stokes-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesVanLeer.cpp + navierStokesVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cu) + target_link_libraries (tnl-navier-stokes-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesAUSMPlus.cpp + navierStokesAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cu) + target_link_libraries (tnl-navier-stokes-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists_together.txt b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists_together.txt new file mode 100644 index 0000000000000000000000000000000000000000..f26fc6d34635dad513d36fd9c4ea21d3c1e95489 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CMakeLists_together.txt @@ -0,0 +1,26 @@ +#navier-stokes + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokes.cpp + navierStokes.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cu) + target_link_libraries (tnl-navier-stokes ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..a6c4a7591ebfc730a5d922c55f962bd58696af32 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/CompressibleConservativeVariables.h @@ -0,0 +1,202 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > MomentumFieldPointer; + + CompressibleConservativeVariables(){}; + + CompressibleConservativeVariables( const MeshPointer& meshPointer ) + : density( meshPointer ), + momentum( meshPointer ), + //pressure( meshPointer ), + energy( meshPointer ), + turbulentEnergy( meshPointer ), + disipation( meshPointer ){}; + + void setMesh( const MeshPointer& meshPointer ) + { + this->density->setMesh( meshPointer ); + this->momentum->setMesh( meshPointer ); + //this->pressure.setMesh( meshPointer ); + this->energy->setMesh( meshPointer ); + this->turbulentEnergy->setMesh( meshPointer ); + this->disipation->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 ); + currentOffset += this->energy->getDofs( meshPointer ); + this->turbulentEnergy->bind( meshPointer, data, currentOffset ); + currentOffset += this->turbulentEnergy->getDofs( meshPointer ); + this->disipation->bind( meshPointer, data, currentOffset ); + } + + IndexType getDofs( const MeshPointer& meshPointer ) const + { + return this->density->getDofs( meshPointer ) + + this->momentum->getDofs( meshPointer ) + + this->energy->getDofs( meshPointer ) + + this->turbulentEnergy->getDofs( meshPointer ) + + this->disipation->getDofs( meshPointer ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + const MeshFunctionPointer& getEnergy() const + { + return this->energy; + } + + void setEnergy( MeshFunctionPointer& energy ) + { + this->energy = energy; + } + + __cuda_callable__ + MeshFunctionPointer& getTurbulentEnergy() + { + return this->turbulentEnergy; + } + + __cuda_callable__ + const MeshFunctionPointer& getTurbulentEnergy() const + { + return this->turbulentEnergy; + } + + void setTurbulentEnergy( MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + __cuda_callable__ + MeshFunctionPointer& getDisipation() + { + return this->disipation; + } + + __cuda_callable__ + const MeshFunctionPointer& getDisipation() const + { + return this->disipation; + } + + void setDisipation( MeshFunctionPointer& disipation ) + { + this->disipation = disipation; + } + + void getVelocityField( VelocityFieldType& velocityField ) + { + + } + + protected: + + MeshFunctionPointer density; + MomentumFieldPointer momentum; + MeshFunctionPointer energy; + MeshFunctionPointer turbulentEnergy; + MeshFunctionPointer disipation; + +}; + +} // namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..e74d0e5d41ecd3349edd9bc0ccd9baf25276c5d4 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h @@ -0,0 +1,252 @@ +/*************************************************************************** + AUSMPlus.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 +#include +#include + +#include "AUSMPlusContinuity.h" +#include "AUSMPlusEnergy.h" +#include "AUSMPlusMomentumX.h" +#include "AUSMPlusMomentumY.h" +#include "AUSMPlusMomentumZ.h" +#include "AUSMPlusTurbulentEnergy.h" +#include "AUSMPlusDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KOmegaOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlus +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + typedef AUSMPlusContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef AUSMPlusMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef AUSMPlusMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef AUSMPlusMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef AUSMPlusEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef AUSMPlusTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef AUSMPlusDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + 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 ); + } + + AUSMPlus() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "AUSMPlus" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setGamma( gamma ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + this->disipationOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + this->turbulentEnergyOperatorPointer->setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->disipationOperatorPointer->setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->disipationOperatorPointer->setAlpha( alpha ); + } + + void setBetaStar( const RealType& betaStar ) + { + this->turbulentEnergyOperatorPointer->setBetaStar( betaStar ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..9ba702004165d80e7c0f263a58bdc7d45023b23d --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusContinuity.h @@ -0,0 +1,401 @@ +/*************************************************************************** + AUSMPlusContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusContinuity< " ) + + 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 DensityFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity + MachBorderMinus * RightDensity ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ], u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->DensityFlux( u[ west ] , u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ] , u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->DensityFlux( u[ down ] , u[ center ], velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->DensityFlux( u[ center ], u[ up ] , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..8c6a271505e30154e264a5442a8920777f597ba2 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusDisipation.h @@ -0,0 +1,465 @@ +/*************************************************************************** + AUSMPlusDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusDisipationBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusDisipation< " ) + + 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; + this->rightHandSide.setVelocity( velocity ); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->rightHandSide.setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->rightHandSide.setAlpha( alpha ); + } + + RealType DisipationFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftDisipation, + const RealType& RightDisipation ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDisipation + MachBorderMinus * RightDisipation ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->DisipationFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->DisipationFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->DisipationFlux( density_west , density_center , velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->DisipationFlux( density_center , density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->DisipationFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->DisipationFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->DisipationFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ] , u[ center ] ) + - this->DisipationFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->DisipationFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ] , u[ center ] ) + - this->DisipationFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->DisipationFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ] , u[ center ]) + - this->DisipationFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..be20ec9dd681a280324f72966926099fd120fa63 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusEnergy.h @@ -0,0 +1,522 @@ +/*************************************************************************** + AUSMPlusEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + AUSMPlusEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "AUSMPlusEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + RealType EnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftEnergy, + const RealType& RightEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * ( LeftEnergy + LeftPressure) + MachBorderMinus * ( RightEnergy + RightPressure ) ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->EnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ], u[ center ] ) + - this->EnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..a049568ca70c1f5f9c9ce186fc4e7c36b6f3563d --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumBase.h @@ -0,0 +1,206 @@ +/*************************************************************************** + AUSMPlusMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + RealType MainMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + RealType PressureSplitingPlus = 0; + RealType PressureSplitingMinus = 0; + RealType PressureBorder = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + PressureSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + PressureSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) * (2.0 - LeftMachNumber ) + + 3.0 / 16.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + PressureSplitingPlus = 1.0; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + PressureSplitingMinus = 1.0; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + PressureSplitingMinus = 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) * (2.0 + RightMachNumber ) + - 3.0 / 16.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + PressureSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + PressureBorder = PressureSplitingPlus * LeftPressure + PressureSplitingMinus * RightPressure; + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftVelocity + MachBorderMinus * RightDensity * RightVelocity ) + PressureBorder; + } + + RealType OtherMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftOtherVelocity, + const RealType& RightOtherVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftOtherVelocity + MachBorderMinus * RightDensity * RightOtherVelocity ); + } + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..24f4c5e780ecb2d640b65ec8bd139f3207efd9c9 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumX.h @@ -0,0 +1,398 @@ +/*************************************************************************** + AUSMPlusMomentumX.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_x_down , velocity_x_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_x_center, velocity_x_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..d1a8d43041623a06152ac07c2fb114d2095e73ab --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumY.h @@ -0,0 +1,371 @@ +/*************************************************************************** + AUSMPlusMomentumY.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_y_down , velocity_y_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_y_center, velocity_y_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..8915da35c870f05f85e91fa38afda392ad29b23b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusMomentumZ.h @@ -0,0 +1,316 @@ +/*************************************************************************** + AUSMPlusMomentumZ.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_z_west , velocity_z_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_z_center, velocity_z_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_z_south , velocity_z_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_z_center, velocity_z_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->MainMomentumFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->MainMomentumFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..034e5ab6f777ae0802a5082db64c5f989db3353a --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlusTurbulentEnergy.h @@ -0,0 +1,459 @@ +/*************************************************************************** + AUSMPlusTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + }; + + void setBetaStar( const RealType& betaStar ) + { + this->rightHandSide.setBetaStar( betaStar ); + } + + RealType TurbulentEnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftTurbulentEnergy, + const RealType& RightTurbulentEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftTurbulentEnergy + MachBorderMinus * RightTurbulentEnergy ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center , velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center , density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->TurbulentEnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->TurbulentEnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ] , u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->TurbulentEnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ] , u[ center ] ) + - this->TurbulentEnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->TurbulentEnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ] , u[ center ]) + - this->TurbulentEnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..d8949290a35edd29775959b92a8e38caffcafdf6 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h @@ -0,0 +1,254 @@ +/*************************************************************************** + 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 +#include +#include + +#include "LaxFridrichsContinuity.h" +#include "LaxFridrichsEnergy.h" +#include "LaxFridrichsMomentumX.h" +#include "LaxFridrichsMomentumY.h" +#include "LaxFridrichsMomentumZ.h" +#include "LaxFridrichsTurbulentEnergy.h" +#include "LaxFridrichsDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KOmegaOperatorRightHandSide< Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + typedef LaxFridrichsContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef LaxFridrichsMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef LaxFridrichsMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef LaxFridrichsMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef LaxFridrichsEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef LaxFridrichsTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef LaxFridrichsDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "numerical-viscosity", "Value of artificial (numerical) viscosity in the Lax-Fridrichs scheme", 1.0 ); + config.addEntry< double >( prefix + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); + } + + LaxFridrichs() + : artificialViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "Lax-Friedrichs" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + 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 ); + this->turbulentEnergyOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->setTau( tau ); + } + + void setGamma( const RealType& gamma ) + { + } + + 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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->setDensity( density ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setCharacteristicLength( RealType& characteristicLength ) + { + this->turbulentEnergyOperatorPointer->setCharacteristicLength( characteristicLength ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + this->turbulentEnergyOperatorPointer->setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->disipationOperatorPointer->setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->disipationOperatorPointer->setAlpha( alpha ); + } + + void setBetaStar( const RealType& betaStar ) + { + this->turbulentEnergyOperatorPointer->setBetaStar( betaStar ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType artificialViscosity; + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/flow-sw/LaxFridrichsContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h similarity index 74% rename from src/Examples/flow-sw/LaxFridrichsContinuity.h rename to src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h index 82747cd18220efc01bc2d68e0247c01723c29fd0..e82c9d4242d426adb2f21b238b05f0773e3b1c3b 100644 --- a/src/Examples/flow-sw/LaxFridrichsContinuity.h +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsContinuity.h @@ -14,12 +14,13 @@ #include #include #include -#include +#include namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuityBase @@ -35,6 +36,7 @@ class LaxFridrichsContinuityBase static const int Dimensions = MeshType::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsContinuityBase() : artificialViscosity( 1.0 ){}; @@ -68,12 +70,15 @@ class LaxFridrichsContinuityBase RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; RealType artificialViscosity; }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsContinuity @@ -85,14 +90,15 @@ class LaxFridrichsContinuity template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -114,13 +120,20 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re 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 ]; + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) - - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse; + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -144,14 +157,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -175,19 +189,23 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re //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 ]; + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ north ] * velocity_y_north - u[ south ] * velocity_y_south ) * hyInverse ) + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -211,14 +229,15 @@ class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Re template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsContinuityBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -242,27 +261,30 @@ class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Re //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 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 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 ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + + ( u[ up ] * velocity_z_up - u[ down ] * velocity_z_down ) * hzInverse ) + + + this->rightHandSide(u, entity, time); } diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..76b41623f1297245f70078f94d316824c1509f4b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsDisipation.h @@ -0,0 +1,352 @@ +/*************************************************************************** + LaxFridrichsDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsDisipationBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + LaxFridrichsDisipationBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsDisipation< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity( velocity ); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->rightHandSide.setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->rightHandSide.setAlpha( alpha ); + } + + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsDisipationBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsDisipationBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsDisipationBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..ab7c416d8c125af03f64d560c3c96b9381b36c36 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsEnergy.h @@ -0,0 +1,354 @@ +/*************************************************************************** + 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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity( density ); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 + + + this->rightHandSide(e, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(e, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(e, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..c44f5777068017143db011224c80c78819446b55 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumBase.h @@ -0,0 +1,93 @@ +/*************************************************************************** + 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 OperatorRightHandSide, + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + LaxFridrichsMomentumBase() + : artificialViscosity( 1.0 ){}; + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity( density ); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + } + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h similarity index 70% rename from src/Examples/inviscid-flow-sw/LaxFridrichsMomentumX.h rename to src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h index 63def12d315188b82e82402635fca863d1b9a629..57258d1a534721a5887ad8affb0e60acdf66943d 100644 --- a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumX.h +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumX.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumX @@ -27,15 +28,16 @@ class LaxFridrichsMomentumX template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -67,17 +69,22 @@ 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 IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); - const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; + -( rho_u[ west ] * velocity_x_west + pressure_west ) ) * hxInverse + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -101,14 +108,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -139,26 +147,34 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_u[ south ] * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > @@ -182,14 +198,15 @@ class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -219,30 +236,30 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -250,7 +267,9 @@ class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_u[ down ] * velocity_z_down ) )* hzInverse ) + + + this->rightHandSide(rho_u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h similarity index 69% rename from src/Examples/inviscid-flow-sw/LaxFridrichsMomentumY.h rename to src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h index 8ce42282dd4c74d5ed72d2abbd661235b95dc160..4cca02779d04d1395051035156d30b8a998ffa64 100644 --- a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumY.h +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumY.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumY @@ -27,15 +28,16 @@ class LaxFridrichsMomentumY template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -128,26 +131,32 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea 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& 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 ]; + const RealType& pressure_south = this->pressure.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ south ] * velocity_y_south + pressure_south ) )* hyInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > @@ -171,14 +180,15 @@ class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -207,34 +217,44 @@ class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 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 * + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + - ( rho_v[ down ] * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(rho_v, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/flow-vl/LaxFridrichsMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h similarity index 78% rename from src/Examples/flow-vl/LaxFridrichsMomentumZ.h rename to src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h index a67e862ceffd78d4fd770d7b1a07e9f05af349d8..1f394bfef12c16125be4a674d08f2defbc455f12 100644 --- a/src/Examples/flow-vl/LaxFridrichsMomentumZ.h +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsMomentumZ.h @@ -18,6 +18,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumZ @@ -27,15 +28,16 @@ class LaxFridrichsMomentumZ template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -90,14 +92,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -151,14 +154,15 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Rea template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsMomentumBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -188,25 +192,30 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) @@ -214,7 +223,9 @@ class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real + ( ( 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 ); + - ( rho_w[ down ] * velocity_z_down + pressure_down ) )* hzInverse ) + + + this->rightHandSide(rho_w, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..d3b41a0704d82ded4137335496f8d604159ec9d4 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichsTurbulentEnergy.h @@ -0,0 +1,347 @@ +/*************************************************************************** + LaxFridrichsTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + LaxFridrichsTurbulentEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsTurbulentEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setArtificialViscosity( const RealType& artificialViscosity ) + { + this->artificialViscosity = artificialViscosity; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->rightHandSide.setDensity( density ); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + }; + + void setBetaStar( const RealType& betaStar ) + { + this->rightHandSide.setBetaStar( betaStar ); + } + + + protected: + + RealType tau; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..68b71b85e1be1385faac4ecf047e3695dbe0cf99 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h @@ -0,0 +1,253 @@ +/*************************************************************************** + StegerWarming.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 +#include +#include + +#include "StegerWarmingContinuity.h" +#include "StegerWarmingEnergy.h" +#include "StegerWarmingMomentumX.h" +#include "StegerWarmingMomentumY.h" +#include "StegerWarmingMomentumZ.h" +#include "StegerWarmingTurbulentEnergy.h" +#include "StegerWarmingDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KOmegaOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarming +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + + typedef StegerWarmingContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef StegerWarmingMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef StegerWarmingMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef StegerWarmingMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef StegerWarmingEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef StegerWarmingTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef StegerWarmingDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + 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 ); + } + + StegerWarming() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "Steger-Warming"<< std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setGamma( gamma ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + this->disipationOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + this->turbulentEnergyOperatorPointer->setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->disipationOperatorPointer->setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->disipationOperatorPointer->setAlpha( alpha ); + } + + void setBetaStar( const RealType& betaStar ) + { + this->turbulentEnergyOperatorPointer->setBetaStar( betaStar ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..5fbef7be69519f22735bf920375af3ad71eb6353 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingContinuity.h @@ -0,0 +1,396 @@ +/*************************************************************************** + StegerWarmingContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingContinuity< " ) + + 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..a91a8b48b7102250b865078b721958e744119e04 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingDisipation.h @@ -0,0 +1,458 @@ +/*************************************************************************** + StegerWarmingDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingDisipationBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingDisipation< " ) + + 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; + this->rightHandSide.setVelocity( velocity ); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->rightHandSide.setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->rightHandSide.setAlpha( alpha ); + } + + RealType positiveDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) 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 <= 0.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ); + else + return disipation * velocity; + }; + + RealType negativeDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return disipation * velocity; + else if ( machNumber <= 0.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return disipation * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..3dad255258b2ef78a744a72fc5074a125d436205 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingEnergy.h @@ -0,0 +1,561 @@ +/*************************************************************************** + StegerWarmingEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..b13dd0894c14b01bfb3d643f1bbe263e7d8e88a4 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumBase.h @@ -0,0 +1,151 @@ +/*************************************************************************** + StegerWarmingMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + } + + 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 <= 0.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( ( machNumber + 1.0 ) * ( machNumber + 1.0 ) ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( 2.0 * ( this->gamma - 1.0 ) * machNumber * machNumber + (machNumber + 1.0 ) * (machNumber + 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( 2.0 * ( this->gamma - 1.0 ) * machNumber * machNumber + (machNumber - 1.0 ) * (machNumber - 1.0 ) ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound / ( 2 * this->gamma ) * ( ( machNumber - 1.0 ) * ( machNumber - 1.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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ) * velocity_other; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * velocity_other; + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ) * velocity_other; + else + return 0.0; + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..c6588083cd9efdd02864d6200cff678de8d0a76d --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumX.h @@ -0,0 +1,356 @@ +/*************************************************************************** + StegerWarmingMomentumX.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..210fb60878d9da9f6f44bb55972997d73be63df7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumY.h @@ -0,0 +1,326 @@ +/*************************************************************************** + StegerWarmingMomentumY.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..135352d2fdf260a2310e5c6e45f2cc581d0e9ff0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingMomentumZ.h @@ -0,0 +1,282 @@ +/*************************************************************************** + StegerWarmingMomentumZ.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return 0-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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..e4d365510e65f83a9c8eaa412d4f14bf12f8dd63 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarmingTurbulentEnergy.h @@ -0,0 +1,452 @@ +/*************************************************************************** + StegerWarmingTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + }; + + void setBetaStar( const RealType& betaStar ) + { + this->rightHandSide.setBetaStar( betaStar ); + } + + RealType positiveTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) 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 <= 0.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ); + else + return turbulentEnergy * velocity; + }; + + RealType negativeTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return turbulentEnergy * velocity; + else if ( machNumber <= 0.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return turbulentEnergy * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..96536383e8a0cc21ed852ea647178a02199fb574 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h @@ -0,0 +1,252 @@ +/*************************************************************************** + VanLeer.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 +#include +#include + +#include "VanLeerContinuity.h" +#include "VanLeerEnergy.h" +#include "VanLeerMomentumX.h" +#include "VanLeerMomentumY.h" +#include "VanLeerMomentumZ.h" +#include "VanLeerTurbulentEnergy.h" +#include "VanLeerDisipation.h" + +#include "Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = KOmegaOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeer +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::TurbulentEnergyOperatorRightHandSideType TurbulentEnergyOperatorRightHandSideType; + typedef typename OperatorRightHandSide::DisipationOperatorRightHandSideType DisipationOperatorRightHandSideType; + + typedef VanLeerContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef VanLeerMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef VanLeerMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef VanLeerMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef VanLeerEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + typedef VanLeerTurbulentEnergy< Mesh, TurbulentEnergyOperatorRightHandSideType, Real, Index > TurbulentEnergyOperatorType; + typedef VanLeerDisipation< Mesh, DisipationOperatorRightHandSideType, Real, Index > DisipationOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorType > TurbulentEnergyOperatorPointer; + typedef Pointers::SharedPointer< DisipationOperatorType > DisipationOperatorPointer; + + 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 ); + } + + VanLeer() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "VanLeer" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setTau( tau ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setGamma( gamma ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setPressure( pressure ); + this->disipationOperatorPointer->setPressure( pressure ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorPointer->setDensity( density ); + this->momentumYOperatorPointer->setDensity( density ); + this->momentumZOperatorPointer->setDensity( density ); + this->energyOperatorPointer->setDensity( density ); + this->turbulentEnergyOperatorPointer->setDensity( density ); + this->disipationOperatorPointer->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 ); + this->turbulentEnergyOperatorPointer->setVelocity( velocity ); + this->disipationOperatorPointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->disipationOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setSigmaK( RealType& sigmaK ) + { + this->turbulentEnergyOperatorPointer->setSigmaK( sigmaK ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumXOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + this->disipationOperatorPointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->disipationOperatorPointer->setSigmaEpsilon( sigmaEpsilon ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipationOperatorPointer->setDisipation( disipation ); + this->turbulentEnergyOperatorPointer->setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->disipationOperatorPointer->setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->disipationOperatorPointer->setAlpha( alpha ); + } + + void setBetaStar( const RealType& betaStar ) + { + this->turbulentEnergyOperatorPointer->setBetaStar( betaStar ); + } + + 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; + } + + const TurbulentEnergyOperatorPointer& getTurbulentEnergyOperator() const + { + return this->turbulentEnergyOperatorPointer; + } + + const DisipationOperatorPointer& getDisipationOperator() const + { + return this->disipationOperatorPointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + TurbulentEnergyOperatorPointer turbulentEnergyOperatorPointer; + DisipationOperatorPointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerContinuity.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..3b497125a6a291990c61c4fed6f158a73472e084 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerContinuity.h @@ -0,0 +1,396 @@ +/*************************************************************************** + VanLeerContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerContinuity< " ) + + 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; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerDisipation.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerDisipation.h new file mode 100644 index 0000000000000000000000000000000000000000..e4998ea2df834b32633820242f887de2aedc5fd8 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerDisipation.h @@ -0,0 +1,453 @@ +/*************************************************************************** + VanLeerDisipation.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerDisipationBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerDisipation< " ) + + 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; + this->rightHandSide.setVelocity( velocity ); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity( turbulentViscosity ); + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity( dynamicalViscosity ); + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->rightHandSide.setSigmaEpsilon( sigmaEpsilon ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy( turbulentEnergy ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + } + + void setBeta( const RealType& beta ) + { + this->rightHandSide.setBeta( beta ); + } + + void setAlpha( const RealType& alpha ) + { + this->rightHandSide.setAlpha( alpha ); + } + + RealType positiveDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) 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 disipation * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ); + else + return disipation * velocity; + }; + + RealType negativeDisipationFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& disipation ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return disipation * velocity; + else if ( machNumber <= 1.0 ) + return - disipation * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerDisipation +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerDisipation< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerDisipationBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerDisipation< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerDisipationBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerDisipation< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerDisipationBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerDisipationBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeDisipationFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeDisipationFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveDisipationFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeDisipationFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeDisipationFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..238b0d7abda5ceb688f8842f24e0034d7bd1724f --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerEnergy.h @@ -0,0 +1,588 @@ +/*************************************************************************** + VanLeerEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + VanLeerEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "VanLeerEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..b34768577be5bba3e19ddb3c3d97c7980c7a5098 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumBase.h @@ -0,0 +1,146 @@ +/*************************************************************************** + VanLeerMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + this->rightHandSide.setDensity( density ); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + 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; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..04e41c015c6193ec3c7e45d5d737512a2762f38a --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumX.h @@ -0,0 +1,410 @@ +/*************************************************************************** + VanLeerMomentumX.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..65ac8482807903cb2e98f8fbc25a4627d1ef7a4b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumY.h @@ -0,0 +1,381 @@ +/*************************************************************************** + VanLeerMomentumY.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..125166cb885b65a8f14049a90dcf92449d644498 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerMomentumZ.h @@ -0,0 +1,322 @@ +/*************************************************************************** + VanLeerMomentumZ.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..aa4c46976a0134117523e73433880f0c25612172 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeerTurbulentEnergy.h @@ -0,0 +1,447 @@ +/*************************************************************************** + VanLeerTurbulentEnergy.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerTurbulentEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerTurbulentEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->rightHandSide.setTurbulentEnergy(turbulentEnergy); + }; + + void setSigmaK( RealType& sigmaK ) + { + this->rightHandSide.setSigmaK( sigmaK ); + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->rightHandSide.setDisipation( disipation ); + }; + + void setBetaStar( const RealType& betaStar ) + { + this->rightHandSide.setBetaStar( betaStar ); + } + + RealType positiveTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) 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 turbulentEnergy * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ); + else + return turbulentEnergy * velocity; + }; + + RealType negativeTurbulentEnergyFlux( const RealType& density, const RealType& velocity, const RealType& pressure, const RealType& turbulentEnergy ) const + { + const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); + const RealType& machNumber = velocity / speedOfSound; + if ( machNumber <= -1.0 ) + return turbulentEnergy * velocity; + else if ( machNumber <= 1.0 ) + return - turbulentEnergy * speedOfSound / 4 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerTurbulentEnergy +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerTurbulentEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerTurbulentEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerTurbulentEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return -hxInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_west , velocity_x_west , pressure_west , u[ west ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_x_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_east , velocity_x_east , pressure_east , u[ east ] ) + ) + -hyInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_south , velocity_y_south , pressure_south , u[ south ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_y_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_north , velocity_y_north , pressure_north , u[ north ] ) + ) + -hzInverse * ( + this->positiveTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + - this->positiveTurbulentEnergyFlux( density_down , velocity_z_down , pressure_down , u[ down ] ) + - this->negativeTurbulentEnergyFlux( density_center, velocity_z_center, pressure_center, u[ center ] ) + + this->negativeTurbulentEnergyFlux( density_up , velocity_z_up , pressure_up , u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaContinuityOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaContinuityOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..f5c9883ff76e361a4853c28e4ec1a58512a10573 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaContinuityOperatorRightHandSide.h @@ -0,0 +1,218 @@ +/*************************************************************************** + KOmegaContinuityOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaContinuityRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + protected: + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaContinuityRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KOmegaContinuityRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaContinuityRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaContinuityRightHandSideBase< 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" ); + + return 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 KOmegaContinuityRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaContinuityRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaContinuityRightHandSideBase< 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" ); + + return 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 KOmegaContinuityRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaContinuityRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaContinuityRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaDisipationOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaDisipationOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..892699db9902da14fa22aeef5ee125842ecf231f --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaDisipationOperatorRightHandSide.h @@ -0,0 +1,649 @@ +/*************************************************************************** + KOmegaDisipationOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaDisipationRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setBeta( const RealType& beta ) + { + this->beta = beta; + } + + void setAlpha( const RealType& alpha ) + { + this->alpha = alpha; + } + + void setSigmaEpsilon( const RealType& sigmaEpsilon ) + { + this->sigmaEpsilon = sigmaEpsilon; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipation = disipation; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer disipation; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; + + RealType alpha; + + RealType beta; + + RealType sigmaEpsilon; +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaDisipationRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KOmegaDisipationRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaDisipationRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaDisipationRightHandSideBase< 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 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + const RealType& disipation_east = this->disipation.template getData< DeviceType >()[ east ]; + const RealType& disipation_west = this->disipation.template getData< DeviceType >()[ west ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + if( ! turbulentEnergy_center == 0.0 ) + return + this->alpha * disipation_center / turbulentEnergy_center + * 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - + this->beta * disipation_center * disipation_center + + + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse * this->sigmaEpsilon; + else + return + - + this->beta * disipation_center * disipation_center + + + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse * this->sigmaEpsilon; + } + + /*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 KOmegaDisipationRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaDisipationRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaDisipationRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + const RealType& disipation_west = this->disipation.template getData< DeviceType >()[ west ]; + const RealType& disipation_east = this->disipation.template getData< DeviceType >()[ east ]; + const RealType& disipation_north = this->disipation.template getData< DeviceType >()[ north ]; + const RealType& disipation_south = this->disipation.template getData< DeviceType >()[ south ]; + + const RealType& density_center = this->density.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + if( ! turbulentEnergy_center == 0.0 ) + return this->alpha * disipation_center / turbulentEnergy_center + * ( ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + ) + - + this->beta * disipation_center * disipation_center + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse * this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse * this->sigmaEpsilon; + else + return + - + this->beta * disipation_center * disipation_center + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse * this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_east + disipation_west * turbulentViscosity_center + ) * hxSquareInverse * this->sigmaEpsilon; + } + + /*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 KOmegaDisipationRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaDisipationRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaDisipationRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + const RealType& disipation_west = this->disipation.template getData< DeviceType >()[ west ]; + const RealType& disipation_east = this->disipation.template getData< DeviceType >()[ east ]; + const RealType& disipation_north = this->disipation.template getData< DeviceType >()[ north ]; + const RealType& disipation_south = this->disipation.template getData< DeviceType >()[ south ]; + const RealType& disipation_up = this->disipation.template getData< DeviceType >()[ up ]; + const RealType& disipation_down = this->disipation.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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + if( ! turbulentEnergy_center == 0.0 ) + return this->alpha * disipation_center / turbulentEnergy_center +// 3D uT_11_x + * ( ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_x_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 +// vT_12_x + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 +// wT_13_x + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_east - velocity_z_west ) * hxInverse / 2 +// uT_21_y + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 +// 3D vT_22_y + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 +// wT_23_y + + ( ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + + ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_north - velocity_z_south ) * hyInverse / 2 +// uT_31_z + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_up - velocity_x_down ) * hzInverse / 2 +// T_32_z + + ( ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + + ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_up - velocity_y_down ) * hzInverse / 2 +// 3D T_33_z + + ( 4.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) + - + this->beta * disipation_center * disipation_center + + + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * disipation_center + - disipation_center * turbulentViscosity_east + disipation_west * disipation_center + ) * hxSquareInverse * this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse * this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_up - 2 * disipation_center + disipation_down ) + * hySquareInverse + + ( disipation_up * turbulentViscosity_up - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_up + disipation_down * turbulentViscosity_center + ) * hySquareInverse * this->sigmaEpsilon; + else + return + - + this->beta * disipation_center * disipation_center + + + this->dynamicalViscosity + * ( disipation_east - 2 * disipation_center + disipation_west ) + * hxSquareInverse + + ( disipation_east * turbulentViscosity_east - disipation_center * disipation_center + - disipation_center * turbulentViscosity_east + disipation_west * disipation_center + ) * hxSquareInverse * this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_north - 2 * disipation_center + disipation_south ) + * hySquareInverse + + ( disipation_north * turbulentViscosity_north - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_north + disipation_south * turbulentViscosity_center + ) * hySquareInverse * this->sigmaEpsilon + + + this->dynamicalViscosity + * ( disipation_up - 2 * disipation_center + disipation_down ) + * hySquareInverse + + ( disipation_up * turbulentViscosity_up - disipation_center * turbulentViscosity_center + - disipation_center * turbulentViscosity_up + disipation_down * turbulentViscosity_center + ) * hySquareInverse * this->sigmaEpsilon; + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaEnergyOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..27d051ce299a2c3b6e027a0662f5e7931bc81d21 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaEnergyOperatorRightHandSide.h @@ -0,0 +1,687 @@ +/*************************************************************************** + KOmegaEnergyOperatorRightHandSide.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 +#include + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + KOmegaEnergyRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaEnergyRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KOmegaEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D uT_11_x + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west + - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D_t_11_x + + + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + + + 2.0 / 3.0 * ( velocity_x_east * density_east * turbulentEnergy_east + - velocity_x_west * density_west * turbulentEnergy_west + ) * hxInverse / 2; + } + + /*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 KOmegaEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + 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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + - velocity_x_center * velocity_x_center + velocity_x_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_south + - velocity_x_northWest * velocity_y_north + velocity_x_southWest * velocity_y_south + ) * hxInverse * hyInverse / 4 + ) * this->dynamicalViscosity +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( velocity_x_east * density_east * turbulentEnergy_east + - velocity_x_west * density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ); + } + + /*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 KOmegaEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + 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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// wT_13_x + + ( ( velocity_x_upEast * velocity_z_east - velocity_x_downEast * velocity_z_east + - velocity_x_upWest * velocity_z_west + velocity_x_downWest * velocity_z_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center - velocity_z_center * velocity_z_west + - velocity_z_center * velocity_z_center + velocity_z_west * velocity_z_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + + velocity_x_center * velocity_x_center + velocity_x_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_23_y + + ( ( velocity_y_upNorth * velocity_z_north - velocity_y_downNorth * velocity_y_north + - velocity_y_upSouth * velocity_z_south + velocity_y_downSouth * velocity_z_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center - velocity_z_center * velocity_z_south + - velocity_z_center * velocity_z_center + velocity_z_south * velocity_z_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// uT_31_z + + ( ( velocity_x_up * velocity_x_center - velocity_x_center * velocity_x_center + - velocity_x_center * velocity_x_down + velocity_x_down * velocity_x_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up - velocity_z_downEast * velocity_x_down + - velocity_z_upWest * velocity_x_up + velocity_z_downWest * velocity_x_down + ) * hxInverse * hzInverse / 4 + ) * this->dynamicalViscosity +// T_32_z + + ( ( velocity_z_upNorth * velocity_y_up - velocity_z_downNorth * velocity_y_down + - velocity_z_upSouth * velocity_y_up + velocity_z_downSouth * velocity_y_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center - velocity_x_center * velocity_y_down + - velocity_x_center * velocity_y_center + velocity_x_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 +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upEast * velocity_x_east * turbulentViscosity_east - velocity_z_downEast * velocity_x_east * turbulentViscosity_east + - velocity_z_upWest * velocity_x_west * turbulentViscosity_west + velocity_z_downWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// wt_13_x + + ( ( velocity_x_upEast * velocity_z_east * turbulentViscosity_east - velocity_x_downEast * velocity_z_east * turbulentViscosity_east + - velocity_x_upWest * velocity_z_west * turbulentViscosity_west + velocity_x_downWest * velocity_z_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_west * turbulentViscosity_west + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_west * velocity_z_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + + velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upNorth * velocity_y_north * turbulentViscosity_north - velocity_z_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_z_upSouth * velocity_y_south * turbulentViscosity_south + velocity_z_downSouth * velocity_y_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_y_north * density_north * turbulentEnergy_north + - velocity_y_south * density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// wt_23_y + + ( ( velocity_y_upNorth * velocity_z_north * turbulentViscosity_north - velocity_y_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_y_upSouth * velocity_z_south * turbulentViscosity_south + velocity_y_downSouth * velocity_z_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_south * turbulentViscosity_south + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_south * velocity_z_south * turbulentViscosity_south + ) * hySquareInverse + ) +// ut_31_z + + ( ( velocity_x_up * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_center * turbulentViscosity_center + - velocity_x_center * velocity_x_down * turbulentViscosity_down + velocity_x_down * velocity_x_down * turbulentViscosity_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up * turbulentViscosity_up - velocity_z_downEast * velocity_x_down * turbulentViscosity_down + - velocity_z_upWest * velocity_x_up * turbulentViscosity_up + velocity_z_downWest * velocity_x_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + ) +// vt_32_z + + ( ( velocity_z_upNorth * velocity_y_up * turbulentViscosity_up - velocity_z_downNorth * velocity_y_down * turbulentViscosity_down + - velocity_z_upSouth * velocity_y_up * turbulentViscosity_up + velocity_z_downSouth * velocity_y_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center * turbulentViscosity_center - velocity_x_center * velocity_y_down * turbulentViscosity_down + - velocity_x_center * velocity_y_center * turbulentViscosity_center + velocity_x_down * velocity_y_down * turbulentViscosity_down + ) * hzSquareInverse + ) +// wt_33_z + + ( 4.0 / 3.0 * ( velocity_z_up * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_down * turbulentViscosity_down + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_down * velocity_z_down * turbulentViscosity_down + ) * hzSquareInverse + - 2.0 / 3.0 * ( velocity_y_upNorth * velocity_z_up * turbulentViscosity_up - velocity_y_downNorth * velocity_z_down * turbulentViscosity_down + - velocity_y_upSouth * velocity_z_up * turbulentViscosity_up + velocity_y_downSouth * velocity_z_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( velocity_x_upEast * velocity_z_up * turbulentViscosity_up - velocity_x_downEast * velocity_z_down * turbulentViscosity_down + - velocity_x_upWest * velocity_z_up * turbulentViscosity_up + velocity_x_downWest * velocity_z_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( velocity_z_up * density_up * turbulentEnergy_up + - velocity_z_down * density_down * turbulentEnergy_down + ) * hzInverse / 2 + ); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumBaseOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumBaseOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..4fa422ca84906b0941af6525f047258c9019d8ee --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumBaseOperatorRightHandSide.h @@ -0,0 +1,75 @@ +/*************************************************************************** + KOmegaMomentumRightHandSideBase.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 KOmegaMomentumRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + KOmegaMomentumRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer density; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumXOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumXOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..acbacbe4333dd14856533a884cf880c2993cce79 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumXOperatorRightHandSide.h @@ -0,0 +1,450 @@ +/*************************************************************************** + KOmegaMomentumXRightHandSide.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 +#include +#include "KOmegaMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaMomentumXRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KOmegaMomentumXRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< 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& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D T_11_x + 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D t_11_x + + + 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2; + } + + /*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 KOmegaMomentumXRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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 + ) * hySquareInverse + ) * this->dynamicalViscosity +// t_11_x + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ); + + } + + /*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 KOmegaMomentumXRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& density_west = this->density.template getData< DeviceType >()[ west ]; + const RealType& density_east = this->density.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_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 + ) * hxSquareInverse + ) * this->dynamicalViscosity +// T_31_z + + ( ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse / 4 + + ( velocity_x_up - 2 * velocity_x_center + velocity_x_down + ) * hzSquareInverse + ) * this->dynamicalViscosity +//t_11_x + + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_east * (velocity_z_upEast - velocity_z_downEast ) - turbulentViscosity_west * ( velocity_z_upWest - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_east * turbulentEnergy_east + - density_west * turbulentEnergy_west + ) * hxInverse / 2 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ) +// t_31_z + + ( ( turbulentViscosity_up * ( velocity_z_upEast - velocity_z_upWest ) - turbulentViscosity_down * ( velocity_z_downEast - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_x_up - ( turbulentViscosity_up + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_down + ) * hzSquareInverse + ); + + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumYOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumYOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..e246ec6fd366dfb8ba6c6d689917572b2afc8ef5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumYOperatorRightHandSide.h @@ -0,0 +1,417 @@ +/*************************************************************************** + KOmegaMomentumYRightHandSide.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 +#include +#include "KOmegaMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaMomentumYRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KOmegaMomentumYRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< 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 KOmegaMomentumYRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + + return +// 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 + + +// t_22_y + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + + 2.0 / 3.0 * ( density_north * turbulentEnergy_north + - density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// t_12_x + + ( ( turbulentViscosity_east * (velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * (velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ); + } + + /*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 KOmegaMomentumYRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& density_north = this->density.template getData< DeviceType >()[ north ]; + const RealType& density_south = this->density.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_12_y + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east - 2 * velocity_y_center + velocity_y_west + ) * hxSquareInverse + ) * 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_up - 2 * velocity_y_center + velocity_y_down + ) * hzSquareInverse + ) * this->dynamicalViscosity + + +// t_12_x + ( ( turbulentViscosity_east * ( velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * ( velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ) +// t_22_y + + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_south * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_z_upNorth - velocity_z_downNorth ) - turbulentViscosity_south * ( velocity_z_upSouth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_north * turbulentEnergy_north + - density_south * turbulentEnergy_south + ) * hyInverse / 2 + ) +// t_32_z + + ( ( turbulentViscosity_up * ( velocity_z_upNorth - velocity_z_upSouth ) - turbulentViscosity_down * ( velocity_z_downNorth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_y_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_down + ) * hzSquareInverse + ); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumZOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumZOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..f6087c4022f67a44e1957d7874d65fd02735ff9f --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaMomentumZOperatorRightHandSide.h @@ -0,0 +1,343 @@ +/*************************************************************************** + KOmegaMomentumZRightHandSide.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 +#include +#include "KOmegaMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaMomentumZRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KOmegaMomentumZRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< 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 KOmegaMomentumZRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< 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 KOmegaMomentumZRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& density_up = this->density.template getData< DeviceType >()[ up ]; + const RealType& density_down = this->density.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_13_x + ( ( velocity_z_east - 2 * velocity_z_center + velocity_z_west ) + * hxSquareInverse + + ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) + * hxInverse * hzInverse / 4 + ) + * this->dynamicalViscosity +// T_23_y + + ( ( velocity_y_upNorth - velocity_y_downNorth - velocity_y_upSouth + velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + + ( velocity_z_north - 2 * velocity_z_center + velocity_z_south ) + * hySquareInverse + ) + * 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 +// t_13_x + + ( ( turbulentViscosity_east * velocity_z_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_west ) + * hxSquareInverse + + ( turbulentViscosity_east * ( velocity_x_upEast - velocity_x_downEast ) - turbulentViscosity_west * ( velocity_x_upWest - velocity_x_downWest ) ) + * hxInverse * hzInverse / 4 + ) +// t_23_y + + ( ( turbulentViscosity_north * ( velocity_y_upNorth - velocity_y_downNorth ) - turbulentViscosity_south * ( velocity_y_upSouth - velocity_y_downSouth ) ) + * hyInverse * hzInverse / 4 + + ( turbulentViscosity_north * velocity_z_north - (turbulentViscosity_north + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_south ) + * hySquareInverse + ) +// t_33_z + + ( 4.0 / 3.0 * ( turbulentViscosity_up * velocity_z_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_down ) + * hzSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_y_upNorth - turbulentViscosity_down * velocity_y_downNorth - turbulentViscosity_up * velocity_y_upSouth + turbulentViscosity_down * velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_x_upEast - turbulentViscosity_down * velocity_x_downEast - turbulentViscosity_up * velocity_x_upWest + turbulentViscosity_down * velocity_x_downWest ) + * hxInverse * hzInverse / 4 + + + 2.0 / 3.0 * ( density_up * turbulentEnergy_up + - density_down * turbulentEnergy_down + ) * hzInverse / 2 + ); + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..58daab984e028a50b9b0d21734e5728c5ba480a7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h @@ -0,0 +1,169 @@ +/*************************************************************************** + KOmegaOpratorRightHandSide.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 +#include +#include + +#include "KOmegaContinuityOperatorRightHandSide.h" +#include "KOmegaEnergyOperatorRightHandSide.h" +#include "KOmegaMomentumXOperatorRightHandSide.h" +#include "KOmegaMomentumYOperatorRightHandSide.h" +#include "KOmegaMomentumZOperatorRightHandSide.h" +#include "KOmegaTurbulentEnergyOperatorRightHandSide.h" +#include "KOmegaDisipationOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaOperatorRightHandSide +{ + 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 KOmegaContinuityRightHandSide< Mesh, Real, Index > ContinuityOperatorRightHandSideType; + typedef KOmegaMomentumXRightHandSide< Mesh, Real, Index > MomentumXOperatorRightHandSideType; + typedef KOmegaMomentumYRightHandSide< Mesh, Real, Index > MomentumYOperatorRightHandSideType; + typedef KOmegaMomentumZRightHandSide< Mesh, Real, Index > MomentumZOperatorRightHandSideType; + typedef KOmegaEnergyRightHandSide< Mesh, Real, Index > EnergyOperatorRightHandSideType; + typedef KOmegaTurbulentEnergyRightHandSide< Mesh, Real, Index > TurbulentEnergyOperatorRightHandSideType; + typedef KOmegaDisipationRightHandSide< Mesh, Real, Index > DisipationOperatorRightHandSideType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorRightHandSideType > ContinuityOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumXOperatorRightHandSideType > MomentumXOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumYOperatorRightHandSideType > MomentumYOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumZOperatorRightHandSideType > MomentumZOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< EnergyOperatorRightHandSideType > EnergyOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< TurbulentEnergyOperatorRightHandSideType > TurbulentEnergyOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< DisipationOperatorRightHandSideType > DisipationOperatorRightHandSidePointer; + + 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 ); + } + + KOmegaOperatorRightHandSide() + : dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->turbulentEnergyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + return true; + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + this->continuityOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumXOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumYOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumZOperatorRightHandSidePointer->setVelocity( velocity ); + this->energyOperatorRightHandSidePointer->setVelocity( velocity ); + this->turbulentEnergyOperatorRightHandSidePointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->turbulentEnergyOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->momentumXOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumYOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->momentumZOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->energyOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + this->turbulentEnergyOperatorRightHandSidePointer->setTurbulentEnergy( turbulentEnergy ); + } + + void setDensity( const MeshFunctionPointer& density ) + { + this->momentumXOperatorRightHandSidePointer->setDensity( density ); + this->momentumYOperatorRightHandSidePointer->setDensity( density ); + this->momentumZOperatorRightHandSidePointer->setDensity( density ); + this->energyOperatorRightHandSidePointer->setDensity( density ); + this->turbulentEnergyOperatorRightHandSidePointer->setDenity( density ); + } + + const ContinuityOperatorRightHandSidePointer& getContinuityOperatorRightHandSide() const + { + return this->continuityOperatorRightHandSidePointer; + } + + const MomentumXOperatorRightHandSidePointer& getMomentumXOperatorRightHandSide() const + { + return this->momentumXOperatorRightHandSidePointer; + } + + const MomentumYOperatorRightHandSidePointer& getMomentumYOperatorRightHandSide() const + { + return this->momentumYOperatorRightHandSidePointer; + } + + const MomentumZOperatorRightHandSidePointer& getMomentumZOperatorRightHandSide() const + { + return this->momentumZOperatorRightHandSidePointer; + } + + const EnergyOperatorRightHandSidePointer& getEnergyOperatorRightHandSide() const + { + return this->energyOperatorRightHandSidePointer; + } + + const TurbulentEnergyOperatorRightHandSidePointer& getTurbulentEnergyOperatorRightHandSide() const + { + return this->turbulentEnergyOperatorRightHandSidePointer; + } + + const DisipationOperatorRightHandSidePointer& getDisipationOperatorRightHandSide() const + { + return this->disipationOperatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorRightHandSidePointer continuityOperatorPointer; + MomentumXOperatorRightHandSidePointer momentumXOperatorPointer; + MomentumYOperatorRightHandSidePointer momentumYOperatorPointer; + MomentumZOperatorRightHandSidePointer momentumZOperatorPointer; + EnergyOperatorRightHandSidePointer energyOperatorPointer; + TurbulentEnergyOperatorRightHandSidePointer turbulentEnergyOperatorPointer; + DisipationOperatorRightHandSidePointer disipationOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaTurbulentEnergyOperatorRightHandSide.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaTurbulentEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..696018bf377b3f00786d8bf3ff81d6cd7bc65a4b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaTurbulentEnergyOperatorRightHandSide.h @@ -0,0 +1,553 @@ +/*************************************************************************** + KOmegaTurbulentEnergyOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaTurbulentEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + + + static String getType() + { + return String( "LaxFridrichsTurbulentEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + void setSigmaK( const RealType& sigmaK ) + { + this->sigmaK = sigmaK; + } + + void setTurbulentEnergy( const MeshFunctionPointer& turbulentEnergy ) + { + this->turbulentEnergy = turbulentEnergy; + } + + void setDisipation( const MeshFunctionPointer& disipation ) + { + this->disipation = disipation; + } + + void setBetaStar( const RealType& betaStar ) + { + this->betaStar = betaStar; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + MeshFunctionPointer turbulentEnergy; + + MeshFunctionPointer disipation; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; + + RealType sigmaK; + + RealType betaStar; +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class KOmegaTurbulentEnergyRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class KOmegaTurbulentEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaTurbulentEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaTurbulentEnergyRightHandSideBase< 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 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return + 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - + this->betaStar * turbulentEnergy_center * disipation_center + + + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse * this->sigmaK; + } + + /*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 KOmegaTurbulentEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaTurbulentEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaTurbulentEnergyRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return + ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - + this->betaStar * turbulentEnergy_center * disipation_center + + + this->dynamicalViscosity + * ( turbulentEnergy_north - 2 * turbulentEnergy_center + turbulentEnergy_south ) + * hySquareInverse + + ( turbulentEnergy_north * turbulentViscosity_north - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_north + turbulentEnergy_south * turbulentViscosity_center + ) * hySquareInverse * this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse * this->sigmaK; + } + + /*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 KOmegaTurbulentEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public KOmegaTurbulentEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef KOmegaTurbulentEnergyRightHandSideBase< 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(); + + 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& turbulentEnergy_center = this->turbulentEnergy.template getData< DeviceType >()[ center ]; + const RealType& turbulentEnergy_west = this->turbulentEnergy.template getData< DeviceType >()[ west ]; + const RealType& turbulentEnergy_east = this->turbulentEnergy.template getData< DeviceType >()[ east ]; + const RealType& turbulentEnergy_north = this->turbulentEnergy.template getData< DeviceType >()[ north ]; + const RealType& turbulentEnergy_south = this->turbulentEnergy.template getData< DeviceType >()[ south ]; + const RealType& turbulentEnergy_up = this->turbulentEnergy.template getData< DeviceType >()[ up ]; + const RealType& turbulentEnergy_down = this->turbulentEnergy.template getData< DeviceType >()[ down ]; + + const RealType& disipation_center = this->disipation.template getData< DeviceType >()[ center ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 3D uT_11_x + ( 4.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_x_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 +// vT_12_x + + ( ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + + ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_east - velocity_y_west ) * hxInverse / 2 +// wT_13_x + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_east - velocity_z_west ) * hxInverse / 2 +// uT_21_y + + ( ( velocity_y_east - velocity_y_west ) * hxInverse / 2 + + ( velocity_x_north - velocity_x_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_north - velocity_x_south ) * hyInverse / 2 +// 3D vT_22_y + + ( 4.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + - 2.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 +// wT_23_y + + ( ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + + ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_north - velocity_z_south ) * hyInverse / 2 +// uT_31_z + + ( ( velocity_x_up - velocity_x_down ) * hzInverse / 2 + + ( velocity_z_east - velocity_z_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_x_up - velocity_x_down ) * hzInverse / 2 +// T_32_z + + ( ( velocity_z_north - velocity_z_south ) * hyInverse / 2 + + ( velocity_y_up - velocity_y_down ) * hzInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_y_up - velocity_y_down ) * hzInverse / 2 +// 3D T_33_z + + ( 4.0 / 3.0 * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - 2.0 / 3.0 * ( velocity_y_north - velocity_y_south ) * hyInverse / 2 + - 2.0 / 3.0 * ( velocity_x_east - velocity_x_west ) * hxInverse / 2 + ) * this->dynamicalViscosity + * ( velocity_z_up - velocity_z_down ) * hzInverse / 2 + - + this->betaStar * turbulentEnergy_center * disipation_center + + + this->dynamicalViscosity + * ( turbulentEnergy_east - 2 * turbulentEnergy_center + turbulentEnergy_west ) + * hxSquareInverse + + ( turbulentEnergy_east * turbulentViscosity_east - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_east + turbulentEnergy_west * turbulentViscosity_center + ) * hxSquareInverse * this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_north - 2 * turbulentEnergy_center + turbulentEnergy_south ) + * hySquareInverse + + ( turbulentEnergy_north * turbulentViscosity_north - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_north + turbulentEnergy_south * turbulentViscosity_center + ) * hySquareInverse * this->sigmaK + + + this->dynamicalViscosity + * ( turbulentEnergy_up - 2 * turbulentEnergy_center + turbulentEnergy_down ) + * hySquareInverse + + ( turbulentEnergy_up * turbulentViscosity_up - turbulentEnergy_center * turbulentViscosity_center + - turbulentEnergy_center * turbulentViscosity_up + turbulentEnergy_down * turbulentViscosity_center + ) * hySquareInverse * this->sigmaK; + } + + /*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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/PhysicalVariablesGetter.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/PhysicalVariablesGetter.h new file mode 100644 index 0000000000000000000000000000000000000000..1ead039975073f43018e9a8d14df7331eec209e3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/PhysicalVariablesGetter.h @@ -0,0 +1,234 @@ +/*************************************************************************** + 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 +#include +#include +#include +#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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef Pointers::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; + }; + + class TurbulentEnergyGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + TurbulentEnergyGetter( MeshFunctionPointer density, + MeshFunctionPointer turbulentEnergyXDensity ) + : density( density ), turbulentEnergyXDensity( turbulentEnergyXDensity ) {} + + 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 turbulentEnergyXDensity.template getData< DeviceType >()( meshEntity ) / + density.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer density, turbulentEnergyXDensity; + }; + + class DisipationGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + DisipationGetter( MeshFunctionPointer density, + MeshFunctionPointer disipationXDensity ) + : density( density ), disipationXDensity( disipationXDensity ) {} + + 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 disipationXDensity.template getData< DeviceType >()( meshEntity ) / + density.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer density, disipationXDensity; + }; + + class TurbulentViscosityGetter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + TurbulentViscosityGetter( MeshFunctionPointer turbulentEnergy, + MeshFunctionPointer disipation ) + :turbulentEnergy( turbulentEnergy ), disipation( disipation ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + if( disipation.template getData< DeviceType >()( meshEntity ) == 0.0 ) + return 0; + else + return turbulentEnergy.template getData< DeviceType >()( meshEntity ) + / disipation.template getData< DeviceType >()( meshEntity ); + } + + protected: + const MeshFunctionPointer disipation, turbulentEnergy; + }; + + + void getVelocity( const ConservativeVariablesPointer& conservativeVariables, + VelocityFieldPointer& velocity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, VelocityGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::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; + Pointers::SharedPointer< PressureGetter, DeviceType > pressureGetter( conservativeVariables->getDensity(), + conservativeVariables->getEnergy(), + conservativeVariables->getMomentum(), + gamma ); + evaluator.evaluate( pressure, pressureGetter ); + } + + void getTurbulentEnergy( const ConservativeVariablesPointer& conservativeVariables, + MeshFunctionPointer& turbulentEnergy_no_rho ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, TurbulentEnergyGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< TurbulentEnergyGetter, DeviceType > turbulentEnergyGetter( conservativeVariables->getDensity(), + conservativeVariables->getTurbulentEnergy() ); + evaluator.evaluate( turbulentEnergy_no_rho, turbulentEnergyGetter ); + } + } + + void getDisipation( const ConservativeVariablesPointer& conservativeVariables, + MeshFunctionPointer& disipation_no_rho ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, DisipationGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< DisipationGetter, DeviceType > disipationGetter( conservativeVariables->getDensity(), + conservativeVariables->getDisipation() ); + evaluator.evaluate( disipation_no_rho, disipationGetter ); + } + } + + void getTurbulentViscosity( MeshFunctionPointer& turbulentEnergy_no_rho, + MeshFunctionPointer& disipation_no_rho, + MeshFunctionPointer& turbulentViscosity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, TurbulentViscosityGetter > evaluator; + for( int i = 0; i < Dimensions; i++ ) + { + Pointers::SharedPointer< TurbulentViscosityGetter, DeviceType > turbulentViscosityGetter( turbulentEnergy_no_rho, + disipation_no_rho); + evaluator.evaluate( turbulentViscosity, turbulentViscosityGetter ); + } + } + +}; + +} //namespace TNL diff --git a/src/Examples/inviscid-flow-sw/RiemannProblemInitialCondition.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/RiemannProblemInitialCondition.h similarity index 75% rename from src/Examples/inviscid-flow-sw/RiemannProblemInitialCondition.h rename to src/Examples/turbulent-flows/two-equation-model/KOmega-model/RiemannProblemInitialCondition.h index b8e53d60178f44111018dcc67fe5e244eda942d5..e503e5be8e2143446d520e02d08ba964a6cafe5b 100644 --- a/src/Examples/inviscid-flow-sw/RiemannProblemInitialCondition.h +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/RiemannProblemInitialCondition.h @@ -108,6 +108,44 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, Me this->SEDEnergy = SEDEnergy; }; + void setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + + void setDisipation(RealType NWUDisipation, + RealType NEUDisipation, + RealType SWUDisipation, + RealType SEUDisipation, + RealType NWDDisipation, + RealType NEDDisipation, + RealType SWDDisipation, + RealType SEDDisipation) + { + this->NWUDisipation = NWUDisipation; + this->NEUDisipation = NEUDisipation; + this->SWUDisipation = SWUDisipation; + this->SEUDisipation = SEUDisipation; + this->NWDDisipation = NWDDisipation; + this->NEDDisipation = NEDDisipation; + this->SWDDisipation = SWDDisipation; + this->SEDDisipation = SEDDisipation; + }; + void setGamma(RealType gamma) { this->gamma = gamma; @@ -173,9 +211,53 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 1,MeshReal, Device, Me } }; + + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + }; + + void placeDisipation(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.getDisipation()).setValue(cell, this->SWDDisipation); + } + else + { + CellType cell(mesh, CoordinatesType(i)); + cell.refresh(); + (* conservativeVariables.getDisipation()).setValue(cell, this->SEDDisipation); + } + }; + PointType discontinuityPlacement; RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; RealType gamma; }; @@ -265,6 +347,44 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M this->SEDEnergy = SEDEnergy; }; + void setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + + void setDisipation(RealType NWUDisipation, + RealType NEUDisipation, + RealType SWUDisipation, + RealType SEUDisipation, + RealType NWDDisipation, + RealType NEDDisipation, + RealType SWDDisipation, + RealType SEDDisipation) + { + this->NWUDisipation = NWUDisipation; + this->NEUDisipation = NEUDisipation; + this->SWUDisipation = SWUDisipation; + this->SEUDisipation = SEUDisipation; + this->NWDDisipation = NWDDisipation; + this->NEDDisipation = NEDDisipation; + this->SWDDisipation = SWDDisipation; + this->SEDDisipation = SEDDisipation; + }; + void setGamma(RealType gamma) { this->gamma = gamma; @@ -394,9 +514,92 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 2, MeshReal, Device, M } }; + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NEDTurbulentEnergy); + } + }; + + void placeDisipation(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.getDisipation()).setValue(cell, this->SWDDisipation); + } + 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.getDisipation()).setValue(cell, this->SEDDisipation); + } + 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.getDisipation()).setValue(cell, this->NWDDisipation); + } + 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.getDisipation()).setValue(cell, this->NEDDisipation); + } + }; + PointType discontinuityPlacement; RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; RealType gamma; }; @@ -485,6 +688,44 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M this->SEDEnergy = SEDEnergy; }; + void setTurbulentEnergy(RealType NWUTurbulentEnergy, + RealType NEUTurbulentEnergy, + RealType SWUTurbulentEnergy, + RealType SEUTurbulentEnergy, + RealType NWDTurbulentEnergy, + RealType NEDTurbulentEnergy, + RealType SWDTurbulentEnergy, + RealType SEDTurbulentEnergy) + { + this->NWUTurbulentEnergy = NWUTurbulentEnergy; + this->NEUTurbulentEnergy = NEUTurbulentEnergy; + this->SWUTurbulentEnergy = SWUTurbulentEnergy; + this->SEUTurbulentEnergy = SEUTurbulentEnergy; + this->NWDTurbulentEnergy = NWDTurbulentEnergy; + this->NEDTurbulentEnergy = NEDTurbulentEnergy; + this->SWDTurbulentEnergy = SWDTurbulentEnergy; + this->SEDTurbulentEnergy = SEDTurbulentEnergy; + }; + + void setDisipation(RealType NWUDisipation, + RealType NEUDisipation, + RealType SWUDisipation, + RealType SEUDisipation, + RealType NWDDisipation, + RealType NEDDisipation, + RealType SWDDisipation, + RealType SEDDisipation) + { + this->NWUDisipation = NWUDisipation; + this->NEUDisipation = NEUDisipation; + this->SWUDisipation = SWUDisipation; + this->SEUDisipation = SEUDisipation; + this->NWDDisipation = NWDDisipation; + this->NEDDisipation = NEDDisipation; + this->SWDDisipation = SWDDisipation; + this->SEDDisipation = SEDDisipation; + }; + void setGamma(RealType gamma) { this->gamma = gamma; @@ -749,9 +990,174 @@ class RiemannProblemInitialConditionSetter< Meshes::Grid< 3, MeshReal, Device, M } }; + void placeTurbulentEnergy(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.getTurbulentEnergy()).setValue(cell, this->SWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NWDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->NEDTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SWUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SWUTurbulentEnergy); + } + 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.getTurbulentEnergy()).setValue(cell, this->SEUTurbulentEnergy); + } + }; + + void placeDisipation(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.getDisipation()).setValue(cell, this->SWDDisipation); + } + 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.getDisipation()).setValue(cell, this->SEDDisipation); + } + 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.getDisipation()).setValue(cell, this->NWDDisipation); + } + 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.getDisipation()).setValue(cell, this->NEDDisipation); + } + 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.getDisipation()).setValue(cell, this->SWUDisipation); + } + 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.getDisipation()).setValue(cell, this->SEUDisipation); + } + 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.getDisipation()).setValue(cell, this->SWUDisipation); + } + 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.getDisipation()).setValue(cell, this->SEUDisipation); + } + }; + PointType discontinuityPlacement; RealType NWUDensity, NEUDensity, SWUDensity, SEUDensity, NWDDensity, NEDDensity, SWDDensity, SEDDensity; RealType NWUEnergy, NEUEnergy, SWUEnergy, SEUEnergy, NWDEnergy, NEDEnergy, SWDEnergy, SEDEnergy; + RealType NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; PointType NWUMomentum, NEUMomentum, SWUMomentum, SEUMomentum, NWDMomentum, NEDMomentum, SWDMomentum, SEDMomentum; RealType gamma; }; @@ -861,6 +1267,9 @@ class RiemannProblemInitialCondition String initial = parameters.getParameter< String >( prefix + "initial" ); if(initial == prefix + "none") { + this->intensity = parameters.getParameter< double >( "turbulence-intensity" ); + this->turbulenceConstant = parameters.getParameter< double >( "turbulence-constant" ); + this->lengthScale = parameters.getParameter< double >( "turbulence-length-scale" ); this->discontinuityPlacement.setup( parameters, prefix + "discontinuity-placement-" ); this->gamma = parameters.getParameter< double >( prefix + "gamma" ); /* @@ -877,49 +1286,64 @@ class RiemannProblemInitialCondition this->NWUPressure = parameters.getParameter< RealType >( prefix + "NWU-pressure" ); this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); this->NWUMomentum = NWUVelocity * NWUDensity; + this->NWUTurbulentEnergy = this->NWUDensity * TurbulentEnergy( NWUVelocity, this->intensity); + this->NWUDisipation = std::sqrt(NWUTurbulentEnergy) / this->lengthScale; 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->SWUTurbulentEnergy = SWUDensity * TurbulentEnergy( SWUVelocity, this->intensity); + this->SWUDisipation = std::sqrt(SWDTurbulentEnergy) / this->lengthScale; 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->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); this->NWDMomentum = NWDVelocity * NWDDensity; + this->NWDTurbulentEnergy = NWDDensity * TurbulentEnergy( NWDVelocity, this->intensity); + this->NWDDisipation = std::sqrt(NWDTurbulentEnergy) / this->lengthScale; 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->SWDTurbulentEnergy = SWDDensity * TurbulentEnergy( SWDVelocity, this->intensity); + this->SWDDisipation = std::sqrt(SWDTurbulentEnergy) / this->lengthScale; 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->NEUTurbulentEnergy = NEUDensity * TurbulentEnergy( NEUVelocity, this->intensity); + this->NEUDisipation = std::sqrt(NEUTurbulentEnergy) / this->lengthScale; 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->SEUTurbulentEnergy = SEUDensity * TurbulentEnergy( SEUVelocity, this->intensity); + this->SEUDisipation = std::sqrt(SEUTurbulentEnergy) / this->lengthScale; 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->NEDTurbulentEnergy = NEDDensity * TurbulentEnergy( NEDVelocity, this->intensity); + this->NEDDisipation = std::sqrt(NEDTurbulentEnergy) / this->lengthScale; 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; - + this->SEDTurbulentEnergy = SEDDensity * TurbulentEnergy( SEDVelocity, this->intensity); + this->SEDDisipation = std::sqrt(SEDTurbulentEnergy) / this->lengthScale; } if(initial == prefix + "1D_2") predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, @@ -990,11 +1414,11 @@ class RiemannProblemInitialCondition 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, + 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, - 0.1, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + 1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_Noh") predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, @@ -1208,6 +1632,9 @@ class RiemannProblemInitialCondition ) { + this->intensity = 1.0; + this->turbulenceConstant = 1.0; + this->lengthScale = 1.0; this->discontinuityPlacement = PointLoad(preDiscX, preDiscY, preDiscZ); this->gamma = preGamma; @@ -1216,51 +1643,64 @@ class RiemannProblemInitialCondition this->NWUPressure = preNWUPressure; this->NWUEnergy = Energy( NWUDensity, NWUPressure, gamma, NWUVelocity); this->NWUMomentum = NWUVelocity * NWUDensity; + this->NWUTurbulentEnergy = NWUDensity * TurbulentEnergy( NWUVelocity, this->intensity); + this->NWUDisipation = std::sqrt(NWUTurbulentEnergy) / this->lengthScale; this->SWUDensity = preNWUDensity; this->SWUVelocity = PointLoad(preSWUVelocityX, preSWUVelocityY, preSWUVelocityZ); this->SWUPressure = preSWUPressure; this->SWUEnergy = Energy( SWUDensity, SWUPressure, gamma, SWUVelocity); this->SWUMomentum = SWUVelocity * SWUDensity; + this->SWUTurbulentEnergy = SWUDensity * TurbulentEnergy( SWUVelocity, this->intensity); + this->SWUDisipation = std::sqrt(SWUTurbulentEnergy) / this->lengthScale; this->NWDDensity = preNWDDensity; this->NWDVelocity = PointLoad(preNWDVelocityX, preNWDVelocityY, preNWDVelocityZ); this->NWDPressure = preNWDPressure; this->NWDEnergy = Energy( NWDDensity, NWDPressure, gamma, NWDVelocity); this->NWDMomentum = NWDVelocity * NWDDensity; + this->NWDTurbulentEnergy = NWDDensity * TurbulentEnergy( NWDVelocity, this->intensity); + this->NWDDisipation = std::sqrt(NWDTurbulentEnergy) / this->lengthScale; this->SWDDensity = preSWDDensity; this->SWDVelocity = PointLoad(preSWDVelocityX, preSWDVelocityY, preSWDVelocityZ); this->SWDPressure = preSWDPressure; this->SWDEnergy = Energy( SWDDensity, SWDPressure, gamma, SWDVelocity); this->SWDMomentum = SWDVelocity * SWDDensity; + this->SWDTurbulentEnergy = SWDDensity * TurbulentEnergy( SWDVelocity, this->intensity); + this->SWDDisipation = std::sqrt(SWDTurbulentEnergy) / this->lengthScale; this->NEUDensity = preNEUDensity; this->NEUVelocity = PointLoad(preNEUVelocityX, preNEUVelocityY, preNEUVelocityZ); this->NEUPressure = preNEUPressure; this->NEUEnergy = Energy( NEUDensity, NEUPressure, gamma, NEUVelocity); this->NEUMomentum = NEUVelocity * NEUDensity; + this->NEUTurbulentEnergy = NEUDensity * TurbulentEnergy( NEUVelocity, this->intensity); + this->NEUDisipation = std::sqrt(NEUTurbulentEnergy) / this->lengthScale; this->SEUDensity = preSEUDensity; this->SEUVelocity = PointLoad(preSEUVelocityX, preSEUVelocityY, preSEUVelocityZ); this->SEUPressure = preSEUPressure; this->SEUEnergy = Energy( SEUDensity, SEUPressure, gamma, SEUVelocity); this->SEUMomentum = SEUVelocity * SEUDensity; + this->SEUTurbulentEnergy = TurbulentEnergy( SEUVelocity, this->intensity); + this->SEUDisipation = std::sqrt(SEUTurbulentEnergy) / this->lengthScale; this->NEDDensity = preNEDDensity; this->NEDVelocity = PointLoad(preNEDVelocityX, preNEDVelocityY, preNEDVelocityZ); this->NEDPressure = preNEDPressure; this->NEDEnergy = Energy( NEDDensity, NEDPressure, gamma, NEDVelocity); this->NEDMomentum = NEDVelocity * NEDDensity; + this->NEDTurbulentEnergy = NEDDensity * TurbulentEnergy( NEDVelocity, this->intensity); + this->NEDDisipation = std::sqrt(NEDTurbulentEnergy) / this->lengthScale; 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; + this->SEDTurbulentEnergy = SEDDensity * TurbulentEnergy( SEDVelocity, this->intensity); + this->SEDDisipation = std::sqrt(SEDTurbulentEnergy) / this->lengthScale; } @@ -1291,11 +1731,26 @@ class RiemannProblemInitialCondition 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 ))); + case 3: energy = (Pressure / (gamma -1.0) + 0.5 * Density * (std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 2 ], 2 ))); break; // druhou mocninu ps8t jako sou4in } return energy; } + + RealType TurbulentEnergy( PointType Velocity, RealType intensity ) + { + RealType turbulentEnergy; + switch (Dimensions) + { + case 1: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ))); + break; + case 2: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ))); + break; + case 3: turbulentEnergy = 3.0 / 2.0 * intensity * intensity * ((std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 2 ], 2 ))); + break; // druhou mocninu ps8t jako sou4in + } + return turbulentEnergy; + } void setInitialCondition( CompressibleConservativeVariables< MeshType >& conservativeVariables, const PointType& center = PointType( 0.0 ) ) @@ -1326,10 +1781,28 @@ class RiemannProblemInitialCondition this->NEDEnergy, this->SWDEnergy, this->SEDEnergy); + variablesSetter->setTurbulentEnergy(this->NWUTurbulentEnergy, + this->NEUTurbulentEnergy, + this->SWUTurbulentEnergy, + this->SEUTurbulentEnergy, + this->NWDTurbulentEnergy, + this->NEDTurbulentEnergy, + this->SWDTurbulentEnergy, + this->SEDTurbulentEnergy); + variablesSetter->setDisipation(this->NWUDisipation, + this->NEUDisipation, + this->SWUDisipation, + this->SEUDisipation, + this->NWDDisipation, + this->NEDDisipation, + this->SWDDisipation, + this->SEDDisipation); variablesSetter->setDiscontinuity(this->discontinuityPlacement); variablesSetter->placeDensity(conservativeVariables); variablesSetter->placeMomentum(conservativeVariables); variablesSetter->placeEnergy(conservativeVariables); + variablesSetter->placeTurbulentEnergy(conservativeVariables); + variablesSetter->placeDisipation(conservativeVariables); // for cyklus i = 0 to mesh.getDimensions().x() j pro .y() a k pro .z() // typedef typename MeshType::Cell CellType @@ -1342,7 +1815,7 @@ class RiemannProblemInitialCondition typedef Functions::Analytic::VectorNorm< Dimensions, RealType > VectorNormType; typedef Operators::Analytic::Sign< Dimensions, RealType > SignType; typedef Functions::OperatorFunction< SignType, VectorNormType > InitialConditionType; - typedef Pointers::SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; + typedef SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; InitialConditionPointer initialCondition; initialCondition->getFunction().setCenter( center ); @@ -1407,6 +1880,12 @@ class RiemannProblemInitialCondition 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 NWUTurbulentEnergy, NEUTurbulentEnergy, SWUTurbulentEnergy, SEUTurbulentEnergy; + RealType NWDTurbulentEnergy, NEDTurbulentEnergy, SWDTurbulentEnergy, SEDTurbulentEnergy; + RealType NWUDisipation, NEUDisipation, SWUDisipation, SEUDisipation, NWDDisipation, NEDDisipation, SWDDisipation, SEDDisipation; + RealType intensity; + RealType turbulenceConstant; + RealType lengthScale; RealType leftDensity, rightDensity; PointType leftVelocity, rightVelocity; RealType leftPressure, rightPressure; diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/flowsBuildConfigTag.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/flowsBuildConfigTag.h new file mode 100644 index 0000000000000000000000000000000000000000..c40b793b9e237d0ad756a66c57088373cad3e41b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/flowsBuildConfigTag.h @@ -0,0 +1,72 @@ +#ifndef FLOWSBUILDCONFIGTAG_H_ +#define FLOWSBUILDCONFIGTAG_H_ + +#include +#include + +namespace TNL { + +class flowsBuildConfigTag{}; + +namespace Solvers { + +/**** + * Turn off support for float and long double. + */ +template<> struct ConfigTagReal< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct ConfigTagReal< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct ConfigTagIndex< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct ConfigTagIndex< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +//template< int Dimension > struct ConfigTagDimension< flowsBuildConfigTag, 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< flowsBuildConfigTag, Meshes::Grid< Dimension, Real, Device, Index > > + { enum { enabled = ConfigTagDimension< flowsBuildConfigTag, Dimension >::enabled && + ConfigTagReal< flowsBuildConfigTag, Real >::enabled && + ConfigTagDevice< flowsBuildConfigTag, Device >::enabled && + ConfigTagIndex< flowsBuildConfigTag, Index >::enabled }; }; +*/ +/**** + * Please, chose your preferred time discretisation here. + */ +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ExplicitTimeDiscretisationTag >{ enum { enabled = true }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, SemiImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; + +/**** + * Only the Runge-Kutta-Merson solver is enabled by default. + */ +template<> struct ConfigTagExplicitSolver< flowsBuildConfigTag, ExplicitEulerSolverTag >{ enum { enabled = true }; }; + +} // namespace Solvers + +namespace Meshes { +namespace BuildConfigTags { + +template< int Dimensions > struct GridDimensionTag< flowsBuildConfigTag, Dimensions >{ enum { enabled = true }; }; + +/**** + * Turn off support for float and long double. + */ +template<> struct GridRealTag< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct GridRealTag< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct GridIndexTag< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct GridIndexTag< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +} // namespace BuildConfigTags +} // namespace Meshes +} // namespace TNL + +#endif /* FLOWSBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/flow/navierStokesRhs.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/flowsRhs.h similarity index 69% rename from src/Examples/flow/navierStokesRhs.h rename to src/Examples/turbulent-flows/two-equation-model/KOmega-model/flowsRhs.h index 3c82ad4539292a4470fd88e9e3a6d03cd8ae2833..e0b8c7fac887f2b8ea588020ede105d9c8950888 100644 --- a/src/Examples/flow/navierStokesRhs.h +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/flowsRhs.h @@ -1,11 +1,11 @@ -#ifndef navierStokesRHS_H_ -#define navierStokesRHS_H_ +#ifndef FLOWSRHS_H_ +#define FLOWSRHS_H_ #include namespace TNL { -template< typename Mesh, typename Real >class navierStokesRhs +template< typename Mesh, typename Real >class flowsRhs : public Functions::Domain< Mesh::getMeshDimension(), Functions::MeshDomain > { public: @@ -24,12 +24,12 @@ template< typename Mesh, typename Real >class navierStokesRhs Real operator()( const MeshEntity& entity, const Real& time = 0.0 ) const { - typedef typename MeshEntity::MeshType::PointType PointType; - PointType v = entity.getCenter(); +// typedef typename MeshEntity::MeshType::PointType PointType; +// PointType v = entity.getCenter(); return 0.0; } }; } //namespace TNL -#endif /* navierStokesRHS_H_ */ +#endif /* FLOWSRHS_H_ */ diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model new file mode 100644 index 0000000000000000000000000000000000000000..cd0c1bbb1426405814d32e2e1f3222e79bb11c8d --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model @@ -0,0 +1,40 @@ +#!/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-euler-navier-stokes + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --differential-operator Steger-Warming \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-AUSM-plus b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-AUSM-plus new file mode 100644 index 0000000000000000000000000000000000000000..faaad26b48f1fbea1002c066b6bfce61e323b7e7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-AUSM-plus @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Ausm-Plus + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Lax-Friedrichs b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Lax-Friedrichs new file mode 100644 index 0000000000000000000000000000000000000000..5f7bfbdc6d6e7ebe6dd69663eeea28a5c6dc770f --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Lax-Friedrichs @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Lax-Friedrichs + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Steger-Warming b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Steger-Warming new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Steger-Warming @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Van-Leer b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Van-Leer new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/run-two-equation-turbulence-model-Van-Leer @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.cpp b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4f35360ff6a853fde03482e65724cc8e15c73c3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.cu b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.cu new file mode 100644 index 0000000000000000000000000000000000000000..a4f35360ff6a853fde03482e65724cc8e15c73c3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.h new file mode 100644 index 0000000000000000000000000000000000000000..047a44e006a83b4cd08f12535662ec7dffb11a23 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModel.h @@ -0,0 +1,276 @@ +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/Lax-Friedrichs/LaxFridrichs.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/Steger-Warming/StegerWarming.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/VanLeer/VanLeer.h" +#include "DifferentialOperators/Two-Equation-Turbulence-Model/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlKolmogorovRightHandSide/PrandtlKolmogorovOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "differential-operator", "Choose the differential operator.", "Lax-Friedrichs"); + config.addEntryEnum< String >( "Lax-Friedrichs" ); + config.addEntryEnum< String >( "Steger-Warming" ); + config.addEntryEnum< String >( "VanLeer" ); + config.addEntryEnum< String >( "AUSMPlus" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef twoEquationTurbulenceModelOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + String differentialOperatorType = parameters.getParameter< String >( "differential-operator"); + if( differentialOperatorType == "Lax-Friedrichs" ) + { + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "Steger-Warming" ) + { + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "VanLeer" ) + { + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "AUSMPlus" ) + { + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + + + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.cpp b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9c751db2a977e309c47122b52f7a76597f913d5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.cu b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.cu new file mode 100644 index 0000000000000000000000000000000000000000..c9c751db2a977e309c47122b52f7a76597f913d5 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..51d4d574e78bb3547d2a1574e983c9304ee24e49 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelAUSMPlus.h @@ -0,0 +1,146 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "beta", "Value of viscosity constant beta", 1.0 ); + config.addEntry< double >( "beta-star", "Value of viscosity constant beta_star", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "alpha", "Value of alpha constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + AUSMPlus< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KOmegaOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.cpp b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a17eddc7694ea4d253abb4dbc51445246f2725b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.cu b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.cu new file mode 100644 index 0000000000000000000000000000000000000000..0a17eddc7694ea4d253abb4dbc51445246f2725b --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..9540333145866d75dd6fdf1e0fcdd58799d4a04c --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelLaxFriedrichs.h @@ -0,0 +1,146 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/Lax-Friedrichs/LaxFridrichs.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "beta", "Value of viscosity constant beta", 1.0 ); + config.addEntry< double >( "beta-star", "Value of viscosity constant beta_star", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "alpha", "Value of alpha constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KOmegaOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/inviscid-flow-sw/eulerProblem.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelProblem.h similarity index 60% rename from src/Examples/inviscid-flow-sw/eulerProblem.h rename to src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelProblem.h index a91e56176dbe8e5b507a61a8d27aaa5050855693..25a175179b5d74a777983c7ac5ca48e6d4e66b65 100644 --- a/src/Examples/inviscid-flow-sw/eulerProblem.h +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelProblem.h @@ -1,5 +1,5 @@ /*************************************************************************** - eulerProblem.h - description + twoEquationTurbulenceModelProblem.h - description ------------------- begin : Feb 13, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -12,7 +12,7 @@ #include #include -#include +#include #include "CompressibleConservativeVariables.h" @@ -23,9 +23,9 @@ namespace TNL { template< typename Mesh, typename BoundaryCondition, typename RightHandSide, - typename InviscidOperators, - typename Communicator > -class eulerProblem: + typename Communicator, + typename InviscidOperators > +class twoEquationTurbulenceModelProblem: public PDEProblem< Mesh, Communicator, typename InviscidOperators::RealType, @@ -38,12 +38,13 @@ class eulerProblem: typedef typename Mesh::DeviceType DeviceType; typedef typename InviscidOperators::IndexType IndexType; typedef PDEProblem< Mesh, Communicator, RealType, DeviceType, IndexType > BaseType; + + typedef Communicator CommunicatorType; using typename BaseType::MeshType; using typename BaseType::MeshPointer; using typename BaseType::DofVectorType; using typename BaseType::DofVectorPointer; - static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::MeshFunction< Mesh > MeshFunctionType; @@ -55,9 +56,8 @@ class eulerProblem: typedef Pointers::SharedPointer< InviscidOperators > InviscidOperatorsPointer; typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - using CommunicatorType = Communicator; - static String getTypeStatic(); + static String getType(); String getPrologHeader() const; @@ -85,12 +85,10 @@ class eulerProblem: const RealType& tau, DofVectorPointer& _u, DofVectorPointer& _fu ); + void applyBoundaryConditions( const RealType& time, - DofVectorPointer& dofs ) - { - throw Exceptions::NotImplementedError( "TODO: implement BC ... see HeatEquationProblem" ); - } + DofVectorPointer& dofs ); template< typename Matrix > void assemblyLinearSystem( const RealType& time, @@ -112,14 +110,42 @@ class eulerProblem: ConservativeVariablesPointer conservativeVariables, conservativeVariablesRHS; + + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::ContinuityOperatorType, typename BoundaryCondition::DensityBoundaryConditionsType, RightHandSide > explicitUpdaterContinuity; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumXOperatorType, typename BoundaryCondition::MomentumXBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumX; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumYOperatorType, typename BoundaryCondition::MomentumYBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumY; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumZOperatorType, typename BoundaryCondition::MomentumZBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumZ; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::EnergyOperatorType, typename BoundaryCondition::EnergyBoundaryConditionsType, RightHandSide > explicitUpdaterEnergy; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::TurbulentEnergyOperatorType, typename BoundaryCondition::TurbulentEnergyBoundaryConditionsType, RightHandSide > explicitUpdaterTurbulentEnergy; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::DisipationOperatorType, typename BoundaryCondition::DisipationBoundaryConditionsType, RightHandSide > explicitUpdaterDisipation; + VelocityFieldPointer velocity; MeshFunctionPointer pressure; + MeshFunctionPointer turbulentViscosity; + MeshFunctionPointer turbulentEnergy; + MeshFunctionPointer disipation; - RealType gamma; + RealType gamma; + RealType speedIncrement; + RealType cavitySpeed; + RealType speedIncrementUntil; + RealType finalSpeed; + RealType startSpeed; + RealType speedIncrementUntilHThrottle; + RealType finalSpeedHThrottle; + RealType startSpeedHThrottle; + RealType turbulenceConstant; + RealType sigmaK; + RealType sigmaEpsilon; + RealType beta; + RealType betaStar; + RealType alpha; + RealType intensity; + RealType lengthScale; }; } // namespace TNL -#include "eulerProblem_impl.h" +#include "twoEquationTurbulenceModelProblem_impl.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelProblem_impl.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..0c3d4ec2962e492a00633e215008f244a5e25b35 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelProblem_impl.h @@ -0,0 +1,569 @@ +/*************************************************************************** + twoEquationTurbulenceModelProblem_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 +#include +#include +#include +#include +#include + +#include "RiemannProblemInitialCondition.h" +#include "CompressibleConservativeVariables.h" +#include "PhysicalVariablesGetter.h" +#include "twoEquationTurbulenceModelProblem.h" + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getType() +{ + return String( "twoEquationTurbulenceModelProblem< " ) + Mesh :: getType() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getPrologHeader() const +{ + return String( "flow solver" ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, 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 Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setup( const Config::ParameterContainer& parameters, + const String& prefix ) +{ + if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || + ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || + ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) + return false; + this->gamma = parameters.getParameter< double >( "gamma" ); + this->startSpeed = parameters.getParameter< double >( "start-speed" ); + this->finalSpeed = parameters.getParameter< double >( "final-speed" ); + this->speedIncrementUntil = parameters.getParameter< RealType >( "speed-increment-until" ); + this->startSpeedHThrottle = parameters.getParameter< double >( "start-speed-h-throttle" ); + this->finalSpeedHThrottle = parameters.getParameter< double >( "final-speed-h-throttle" ); + this->speedIncrementUntilHThrottle = parameters.getParameter< RealType >( "speed-increment-until-h-throttle" ); + this->turbulenceConstant = parameters.getParameter< double >( "turbulence-constant" ); + this->beta = parameters.getParameter< double >( "beta" ); + this->betaStar = parameters.getParameter< double >( "beta-star" ); + this->alpha = parameters.getParameter< double >( "alpha" ); + this->sigmaK = parameters.getParameter< double >( "sigma-k" ); + this->sigmaEpsilon = parameters.getParameter< double >( "sigma-epsilon" ); + this->intensity = parameters.getParameter< double >( "turbulence-intensity" ); + this->lengthScale = parameters.getParameter< double >( "turbulence-length-scale" ); + velocity->setMesh( this->getMesh() ); + pressure->setMesh( this->getMesh() ); + turbulentViscosity->setMesh( this->getMesh() ); + turbulentEnergy->setMesh( this->getMesh() ); + disipation->setMesh( this->getMesh() ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setSigmaK( this->sigmaK ); + this->inviscidOperatorsPointer->setSigmaEpsilon( this->sigmaEpsilon ); + this->inviscidOperatorsPointer->setBetaStar( this->betaStar ); + this->inviscidOperatorsPointer->setDisipation( this->disipation ); + this->inviscidOperatorsPointer->setVelocity( this->velocity ); + this->inviscidOperatorsPointer->setPressure( this->pressure ); + this->inviscidOperatorsPointer->setDensity( this->conservativeVariables->getDensity() ); + this->inviscidOperatorsPointer->setGamma( this->gamma ); + this->inviscidOperatorsPointer->setTurbulentViscosity( this->turbulentViscosity ); + this->inviscidOperatorsPointer->setTurbulentEnergy( this->turbulentEnergy ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); + this->explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer->getDensityBoundaryCondition() ); + this->explicitUpdaterContinuity.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumXOperator() ); + this->explicitUpdaterMomentumX.setBoundaryConditions( this->boundaryConditionPointer->getMomentumXBoundaryCondition() ); + this->explicitUpdaterMomentumX.setRightHandSide( this->rightHandSidePointer ); + + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumYOperator() ); + this->explicitUpdaterMomentumY.setBoundaryConditions( this->boundaryConditionPointer->getMomentumYBoundaryCondition() ); + this->explicitUpdaterMomentumY.setRightHandSide( this->rightHandSidePointer ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumZOperator() ); + this->explicitUpdaterMomentumZ.setBoundaryConditions( this->boundaryConditionPointer->getMomentumZBoundaryCondition() ); + this->explicitUpdaterMomentumZ.setRightHandSide( this->rightHandSidePointer ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getEnergyOperator() ); + this->explicitUpdaterEnergy.setBoundaryConditions( this->boundaryConditionPointer->getEnergyBoundaryCondition() ); + this->explicitUpdaterEnergy.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getTurbulentEnergyOperator() ); + this->explicitUpdaterTurbulentEnergy.setBoundaryConditions( this->boundaryConditionPointer->getTurbulentEnergyBoundaryCondition() ); + this->explicitUpdaterTurbulentEnergy.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Disipation equation + */ + this->explicitUpdaterDisipation.setDifferentialOperator( this->inviscidOperatorsPointer->getDisipationOperator() ); + this->explicitUpdaterDisipation.setBoundaryConditions( this->boundaryConditionPointer->getDisipationBoundaryCondition() ); + this->explicitUpdaterDisipation.setRightHandSide( this->rightHandSidePointer ); + + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +typename twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >::IndexType +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getDofs() const +{ + /**** + * Return number of DOFs (degrees of freedom) i.e. number + * of unknowns to be resolved by the main solver. + */ + return this->conservativeVariables->getDofs( this->getMesh() ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +bindDofs( DofVectorPointer& dofVector ) +{ + this->conservativeVariables->bind( this->getMesh(), dofVector ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setInitialCondition( const Config::ParameterContainer& parameters, + DofVectorPointer& dofs ) +{ + CompressibleConservativeVariables< MeshType > conservativeVariables; + conservativeVariables.bind( this->getMesh(), 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 Communicator, + typename InviscidOperators > + template< typename Matrix > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setupLinearSystem( Matrix& matrix ) +{ +/* const IndexType dofs = this->getDofs(); + 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 Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +makeSnapshot( const RealType& time, + const IndexType& step, + DofVectorPointer& dofs ) +{ + std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; + + this->bindDofs( 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() ) ) + this->conservativeVariables->getDensity()->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "velocity-" ); +// if( ! this->velocity->save( fileName.getFileName() ) ) + this->velocity->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "pressure-" ); +// if( ! this->pressure->save( fileName.getFileName() ) ) + this->pressure->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "energy-" ); +// if( ! this->conservativeVariables->getEnergy()->save( fileName.getFileName() ) ) + this->conservativeVariables->getEnergy()->save( fileName.getFileName() ); +// return false; + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getExplicitUpdate( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + DofVectorPointer& _fu ) +{ + typedef typename MeshType::Cell Cell; + + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), _u ); + this->conservativeVariablesRHS->bind( this->getMesh(), _fu ); + + /**** + * Resolve the physical variables + */ + PhysicalVariablesGetter< typename MeshPointer::ObjectType > physicalVariables; + physicalVariables.getVelocity( this->conservativeVariables, this->velocity ); + physicalVariables.getPressure( this->conservativeVariables, this->gamma, this->pressure ); + physicalVariables.getTurbulentEnergy( this->conservativeVariables, this->turbulentEnergy ); + physicalVariables.getDisipation( this->conservativeVariables, this->disipation ); + physicalVariables.getTurbulentViscosity( this->turbulentEnergy, this->disipation, this->turbulentViscosity ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setTau( tau ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getDensity(), + this->conservativeVariablesRHS->getDensity() ); + +// this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, +// this->conservativeVariables->getDensity() ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 0 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 0 ] ); //, fuRhoVelocityX ); + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 1 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 1 ] ); //, fuRhoVelocityX ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 2 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 2 ] ); //, fuRhoVelocityX ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); + + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getTurbulentEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getTurbulentEnergy() ); //, fuRhoVelocityX ); + + /**** + * Disipation equation + */ + this->explicitUpdaterTurbulentEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getDisipation(), // uRhoVelocityX, + this->conservativeVariablesRHS->getDisipation() ); //, fuRhoVelocityX ); + + /*this->conservativeVariablesRHS->getDensity()->write( "density", "gnuplot" ); + this->conservativeVariablesRHS->getEnergy()->write( "energy", "gnuplot" ); + this->conservativeVariablesRHS->getMomentum()->write( "momentum", "gnuplot", 0.05 ); + getchar();*/ + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +applyBoundaryConditions( const RealType& time, + DofVectorPointer& dofs ) +{ + /**** + * Update Boundary Conditions + */ + if(this->speedIncrementUntil > time ) + { + this->boundaryConditionPointer->setTimestep(this->speedIncrement); + } + else + { + this->boundaryConditionPointer->setTimestep(0); + } + this->boundaryConditionPointer->setIntensity(this->intensity); + this->boundaryConditionPointer->setLengthScale(this->lengthScale); + this->boundaryConditionPointer->setTurbulenceConstant(this->turbulenceConstant); + this->boundaryConditionPointer->setSpeed(this->cavitySpeed); + this->boundaryConditionPointer->setCompressibleConservativeVariables(this->conservativeVariables); + this->boundaryConditionPointer->setGamma(this->gamma); + this->boundaryConditionPointer->setPressure(this->pressure); + this->boundaryConditionPointer->setVerticalThrottleSpeed( startSpeed, finalSpeed, time, speedIncrementUntil ); + this->boundaryConditionPointer->setHorizontalThrottleSpeed( startSpeedHThrottle, finalSpeedHThrottle, time, speedIncrementUntilHThrottle ); + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), dofs ); +// this->conservativeVariables->getDensity()->write( "density", "gnuplot" ); +// this->conservativeVariables->getEnergy()->write( "energy", "gnuplot" ); +// this->conservativeVariables->getMomentum()->write( "momentum", "gnuplot", 0.05 ); +// dofs->save("dofs.tnl"); +// getchar(); +// std::cout <<"applyBCC" << std::endl; + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getDensity() ); + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 0 ] ); // uRhoVelocityX, + if( Dimensions > 1 ) + { + + this->explicitUpdaterMomentumY.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 1 ] ); // uRhoVelocityX, + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 2 ] ); // uRhoVelocityX, + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getEnergy() ); // uRhoVelocityX, + + /**** + * Turbulent energy equation + */ + this->explicitUpdaterTurbulentEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getTurbulentEnergy() ); // uRhoVelocityX, + /**** + * Turbulent energy equation + */ + this->explicitUpdaterDisipation.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getDisipation() ); // uRhoVelocityX, + + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > + template< typename Matrix > +void +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +assemblyLinearSystem( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + Matrix& matrix, + DofVectorPointer& b ) +{ +/* LinearSystemAssembler< Mesh, + MeshFunctionType, + InviscidOperators, + BoundaryCondition, + RightHandSide, + BackwardTimeDiscretisation, + Matrix, + DofVectorType > systemAssembler; + + MeshFunction< Mesh > u( mesh, _u ); + systemAssembler.template assembly< typename Mesh::Cell >( time, + tau, + this->differentialOperator, + this->boundaryCondition, + this->rightHandSide, + u, + matrix, + b );*/ +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +twoEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +postIterate( const RealType& time, + const RealType& tau, + DofVectorPointer& dofs ) +{ + /* + 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/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.cpp b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30a2938a74488d83b4c6f5dfd17fe4a6560fe6f0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelStegerWarming.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.cu b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.cu new file mode 100644 index 0000000000000000000000000000000000000000..30a2938a74488d83b4c6f5dfd17fe4a6560fe6f0 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelStegerWarming.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..81ee702155eb71e0c61a2e6edca7d670015fb9bc --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelStegerWarming.h @@ -0,0 +1,146 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/Steger-Warming/StegerWarming.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "beta", "Value of viscosity constant beta", 1.0 ); + config.addEntry< double >( "beta-star", "Value of viscosity constant beta_star", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "alpha", "Value of alpha constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + StegerWarming< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KOmegaOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.cpp b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2bd33e16a63676adbe48957ceb3277b9005d23b7 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.cpp @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModelVanLeer.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.cu b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.cu new file mode 100644 index 0000000000000000000000000000000000000000..a4f35360ff6a853fde03482e65724cc8e15c73c3 --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.cu @@ -0,0 +1 @@ +#include "twoEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.h b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..2bf88fafeed7a1dc8a8bb889874852d2d79ac34e --- /dev/null +++ b/src/Examples/turbulent-flows/two-equation-model/KOmega-model/twoEquationTurbulenceModelVanLeer.h @@ -0,0 +1,146 @@ +//#include +#include +#include +#include +#include +#include +#include "twoEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Two-Equation-turbulence-model/VanLeer/VanLeer.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/KOmegaRightHandSide/KOmegaOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 twoEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "turbulence-constant", "Value of turbulence constant", 1.0 ); + config.addEntry< double >( "beta", "Value of viscosity constant beta", 1.0 ); + config.addEntry< double >( "beta-star", "Value of viscosity constant beta_star", 1.0 ); + config.addEntry< double >( "sigma-k", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "sigma-epsilon", "Value of sigma constant", 1.0 ); + config.addEntry< double >( "alpha", "Value of alpha constant", 1.0 ); + config.addEntry< double >( "turbulence-intensity", "meassure of turbulence intensity", 1.0 ); + config.addEntry< double >( "turbulence-length-scale", "meassure of turbulence intensity", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + VanLeer< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class twoEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef KOmegaOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef twoEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< twoEquationTurbulenceModelSetter, twoEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/flow/BoundaryConditionsBoiler.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h similarity index 92% rename from src/Examples/flow/BoundaryConditionsBoiler.h rename to src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h index f61f988da66f3f7476827c8f8853f4d6dbf67217..953199081f0b912fd0c4323c6d5ab26037f7abf5 100644 --- a/src/Examples/flow/BoundaryConditionsBoiler.h +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/BoundaryConditionsBoiler.h @@ -99,6 +99,22 @@ class BoundaryConditionsBoiler this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); } + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() { return this->densityBoundaryConditionsPointer; diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/DensityBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..6231f6780e24e3090c83832c9d47534a9c6104a8 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..412640b5472f0e85026e26954503a6412bba0c39 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/EnergyBoundaryConditionBoiler.h @@ -0,0 +1,853 @@ +/*************************************************************************** + 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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/MomentumXBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..dfe63e07623a6fdb6ca7ebb7da8ab445d9505372 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/MomentumYBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..83b6282ddd50033f32a382f0b48f5abe7347ccaa --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/MomentumZBoundaryConditionBoiler.h new file mode 100644 index 0000000000000000000000000000000000000000..9d887857ce97f916dcfaccd0208138afc200afd1 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Boiler/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..06228f789664fbc508cc294df6bae489941d9c2b --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h @@ -0,0 +1,194 @@ +#include + +#include "DensityBoundaryConditionBoilerModel.h" +#include "MomentumXBoundaryConditionBoilerModel.h" +#include "MomentumYBoundaryConditionBoilerModel.h" +#include "MomentumZBoundaryConditionBoilerModel.h" +#include "EnergyBoundaryConditionBoilerModel.h" + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class BoundaryConditionsBoilerModel +{ + 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::DensityBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::MomentumXBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::MomentumYBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::MomentumZBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::EnergyBoundaryConditionsBoilerModel< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType, DeviceType > MeshFunctionPointer; + + static void configSetup( Config::ConfigDescription& config, + const String& prefix = "" ) + { + config.addEntry< double >( prefix + "vertical-angle", "Vertical angle of throttle in degrees", 0 ); + config.addEntry< double >( prefix + "horizontal-angle", "Horizontal angle of throttle in degrees", 45 ); + } + + 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); + setZAngle(parameters.getParameter< double >( prefix + "vertical-angle" ) * M_PI / 180.0 ); + setXYAngle(parameters.getParameter< double >( prefix + "horizontal-angle" ) * M_PI / 180.0 ); + 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 setZAngle(const RealType zAngle) + { + this->densityBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumXBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumYBoundaryConditionsPointer->setZAngle(zAngle); + this->momentumZBoundaryConditionsPointer->setZAngle(zAngle); + this->energyBoundaryConditionsPointer->setZAngle(zAngle); + } + + void setXYAngle(const RealType xYAngle) + { + this->densityBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumXBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumYBoundaryConditionsPointer->setXYAngle(xYAngle); + this->momentumZBoundaryConditionsPointer->setXYAngle(xYAngle); + this->energyBoundaryConditionsPointer->setXYAngle(xYAngle); + } + + 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) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType horizontalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + horizontalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + horizontalThrottleSpeed = 0; + else + horizontalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + this->energyBoundaryConditionsPointer->setHorizontalThrottleSpeed(horizontalThrottleSpeed); + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + RealType verticalThrottleSpeed = 0; + if(time <= finalTime) + if( time != 0 && finalTime != 0 ) + verticalThrottleSpeed = startSpeed + ( finalSpeed - startSpeed ) * ( time / finalTime ); + else + verticalThrottleSpeed = 0; + else + verticalThrottleSpeed = finalSpeed; + this->momentumXBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumYBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->momentumZBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + this->energyBoundaryConditionsPointer->setVerticalThrottleSpeed(verticalThrottleSpeed); + } + + 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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..a58f32f7c577590801504d675dec55243e2f0b57 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/DensityBoundaryConditionBoilerModel.h @@ -0,0 +1,580 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class DensityBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class DensityBoundaryConditionsBoilerModelBase +{ + 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 DensityBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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.835 * ( entity.getMesh().getDimensions().y() - 1 )) + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + else + return u[ 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, -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 setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class DensityBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public DensityBoundaryConditionsBoilerModelBase< 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 DensityBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef DensityBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 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 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; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; + +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const DensityBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..d0475576b5fa910528eaa3c7a80ffd8047bddcc9 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/EnergyBoundaryConditionBoilerModel.h @@ -0,0 +1,962 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class EnergyBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function> +class EnergyBoundaryConditionsBoilerModelBase +{ + 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 EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + }; + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle energy + { + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + if( ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class EnergyBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public EnergyBoundaryConditionsBoilerModelBase< 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 EnergyBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef EnergyBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; +// if for chimney exit + } + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + if( (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] != 0 ) + return ( (* this->pressure)[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ] + / ( this->gamma - 1 ) + ) + + 0.5 + * ( ( (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 0 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 1 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + + (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * (* ( *this->compressibleConservativeVariables->getMomentum() )[ 2 ] )[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ) + / (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + ); + else return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 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->horizontalThrottleSpeed + * + this->horizontalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) && ( entity.getCoordinates().y() > 0.408 * ( 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->verticalThrottleSpeed + * + this->verticalThrottleSpeed + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + + } + + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType zAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const EnergyBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..893815913ba45510c520de2033d7be690faea8bb --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumXBoundaryConditionBoilerModel.h @@ -0,0 +1,940 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumXBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumXBoundaryConditionsBoilerModelBase +{ + 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 MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumXBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumXBoundaryConditionsBoilerModelBase< 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 MomentumXBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumXBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumXBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..e8aa33e885efcc06f134a94f7e6df8cb974fb417 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumYBoundaryConditionBoilerModel.h @@ -0,0 +1,941 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumYBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumYBoundaryConditionsBoilerModelBase +{ + 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 MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +//throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( - 1.0 ) + * std::sin( this->zAngle ) + ); + } + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for y axis + if( + ( + ( entity.getCoordinates().y() < 0.45 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.44 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.43 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.42 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.41 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.40 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.39 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.38 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.37 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.36 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().y() < 0.35 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.34 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + ) +// throttle speed + { + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + } +// if for chimney exit + if( entity.getCoordinates().y() > 0.835 * ( entity.getMesh().getDimensions().y() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) +// down throttle + { + if( + ( entity.getCoordinates().x() < 0.592 * ( entity.getMesh().getDimensions().x() - 1 ) ) + && + ( entity.getCoordinates().x() > 0.408 * ( entity.getMesh().getDimensions().x() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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, 0 >() ]; + /*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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumYBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumYBoundaryConditionsBoilerModelBase< 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 MomentumYBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumYBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::cos( this->xYAngle ) + * std::cos( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->xYAngle ) + * std::cos( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumYBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h new file mode 100644 index 0000000000000000000000000000000000000000..ee40b1b74066d4c5ee0491345538577525a7e4f5 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/BoilerModel/MomentumZBoundaryConditionBoilerModel.h @@ -0,0 +1,838 @@ +/*************************************************************************** + 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 + +namespace TNL { +namespace Operators { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class MomentumZBoundaryConditionsBoilerModel +{ + +}; + +/**** + * Base + */ +template< typename Function > +class MomentumZBoundaryConditionsBoilerModelBase +{ + 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 MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 2D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +/**** + * 3D grid + */ +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Function, + typename Real, + typename Index > +class MomentumZBoundaryConditionsBoilerModel< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Function, Real, Index > + : public MomentumZBoundaryConditionsBoilerModelBase< 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 MomentumZBoundaryConditionsBoilerModel< MeshType, Function, Real, Index > ThisType; + typedef MomentumZBoundaryConditionsBoilerModelBase< Function > BaseType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for y axis + { + if( entity.getCoordinates().y() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().y() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().y() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } +// if for chimney exit + if( entity.getCoordinates().z() > 0.835 * ( entity.getMesh().getDimensions().z() - 1 ) ) + return u[ neighborEntities.template getEntityIndex< -1, 0, 0 >() ]; + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::sin( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::cos( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().y() == entity.getMesh().getDimensions().y() - 1 ) + { +// if for z axis + if( + ( + ( entity.getCoordinates().z() < 0.45 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.44 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.43 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.42 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.41 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.40 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.39 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.38 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.37 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.36 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + || + ( + ( entity.getCoordinates().z() < 0.35 * ( entity.getMesh().getDimensions().z() - 1 ) ) + && + ( entity.getCoordinates().z() > 0.34 * ( entity.getMesh().getDimensions().z() - 1 ) ) + ) + ) +// if for x axis + { + if( entity.getCoordinates().x() < 0.08 * std::cos( this->xYAngle ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + if ( entity.getCoordinates().x() > ( 1 - 0.08 * std::sin( this->xYAngle ) ) * ( entity.getMesh().getDimensions().x() - 1 ) ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->horizontalThrottleSpeed * ( -1.0 ) + * std::sin( this->zAngle ) + ); + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + return u[ neighborEntities.template getEntityIndex< 0, 0, 0 >() ]; + } + if( entity.getCoordinates().z() == 0 ) + { + if( + ( entity.getCoordinates().y() < 0.592 * ( entity.getMesh().getDimensions().y() - 1 ) ) + && + ( entity.getCoordinates().y() > 0.408 * ( entity.getMesh().getDimensions().y() - 1 ) ) + ) + return (* this->compressibleConservativeVariables->getDensity())[neighborEntities.template getEntityIndex< 0, 0, 0 >()] + * ( + this->verticalThrottleSpeed + ); + 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 setHorizontalThrottleSpeed(const RealType horizontalThrottleSpeed) + { + this->horizontalThrottleSpeed = horizontalThrottleSpeed; + } + + void setVerticalThrottleSpeed(const RealType verticalThrottleSpeed) + { + this->verticalThrottleSpeed = verticalThrottleSpeed; + } + + void setZAngle(const RealType zAngle) + { + this->zAngle = zAngle; + } + + void setXYAngle(const RealType xYAngle) + { + this->xYAngle = xYAngle; + } + + + private: + CompressibleConservativeVariablesPointer compressibleConservativeVariables; + RealType timestep; + RealType horizontalThrottleSpeed; + RealType verticalThrottleSpeed; + RealType gamma; + MeshFunctionPointer pressure; + RealType zAngle; + RealType xYAngle; +}; + +template< typename Mesh, + typename Function, + typename Real, + typename Index > +std::ostream& operator << ( std::ostream& str, const MomentumZBoundaryConditionsBoilerModel< Mesh, Function, Real, Index >& bc ) +{ + str << "Neumann boundary Conditions: function = " << bc.getFunction(); + return str; +} + +} // namespace Operators +} // namespace TNL + diff --git a/src/Examples/flow-vl/BoundaryConditionsCavity.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h similarity index 92% rename from src/Examples/flow-vl/BoundaryConditionsCavity.h rename to src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h index bbae2d3e93c65383db11a53a3b16d734fc3131e2..9c3c0b0996d682c57b99c7ce05164e1e8cdc58a8 100644 --- a/src/Examples/flow-vl/BoundaryConditionsCavity.h +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/BoundaryConditionsCavity.h @@ -99,6 +99,22 @@ class BoundaryConditionsCavity this->energyBoundaryConditionsPointer->setCavitySpeed(cavitySpeed); } + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + DensityBoundaryConditionsTypePointer& getDensityBoundaryCondition() { return this->densityBoundaryConditionsPointer; diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/DensityBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..c753d324a288a331dbfb9d73e341fe962f39889e --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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< 1, 0 >() ]; + } + if( entity.getCoordinates().x() == entity.getMesh().getDimensions().x() - 1 ) + { + return u[ neighborEntities.template getEntityIndex< -1, 0 >() ]; + } + if( entity.getCoordinates().y() == 0 ) + { + return u[ 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 >() ]; + } + } + + 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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..ca5d85442d02edeb7ddd39749c6441c13e3eb6ed --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/EnergyBoundaryConditionCavity.h @@ -0,0 +1,672 @@ +/*************************************************************************** + 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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/MomentumXBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..07abfdbeb940039555ac2799d0ef374ca26faff0 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/MomentumYBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..a83dd653f92328814b8d0746bc45c8775552a310 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/MomentumZBoundaryConditionCavity.h new file mode 100644 index 0000000000000000000000000000000000000000..5fe6f22e5945513c9e9e86d835256ef84e27c054 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Cavity/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 + +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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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 Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h new file mode 100644 index 0000000000000000000000000000000000000000..930183476e5085ac80c115785f4c0eff0aa8e7d8 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function = Functions::Analytic::Constant< Mesh::getMeshDimension(), typename Mesh::RealType >, + int MeshEntitiesDimension = Mesh::getMeshDimension(), + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsDirichlet +{ + 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::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::DirichletBoundaryConditions< MeshType, FunctionType, MeshType::getMeshDimension(), RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h new file mode 100644 index 0000000000000000000000000000000000000000..ec99b86e7872ea867bdc49317e2987c04def1470 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/BoundaryConditions/Neumann/BoundaryConditionsNeumann.h @@ -0,0 +1,124 @@ +#include +#include + +namespace TNL { + +template< typename Mesh, + typename Function, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::GlobalIndexType > +class BoundaryConditionsNeumann +{ + 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::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > DensityBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumXBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumYBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > MomentumZBoundaryConditionsType; + typedef TNL::Operators::NeumannBoundaryConditions< MeshType, FunctionType, RealType, IndexType > EnergyBoundaryConditionsType; + typedef CompressibleConservativeVariables< MeshType > CompressibleConservativeVariablesType; + + typedef Pointers::SharedPointer< DensityBoundaryConditionsType > DensityBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumXBoundaryConditionsType > MomentumXBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumYBoundaryConditionsType > MomentumYBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< MomentumZBoundaryConditionsType > MomentumZBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< EnergyBoundaryConditionsType > EnergyBoundaryConditionsTypePointer; + typedef Pointers::SharedPointer< CompressibleConservativeVariablesType > CompressibleConservativeVariablesPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::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 = "" ) + { + return true; + } + + void setCompressibleConservativeVariables(const CompressibleConservativeVariablesPointer& compressibleConservativeVariables) + { + + } + + void setTimestep(const RealType timestep) + { + + } + + void setGamma(const RealType gamma) + { + + } + + void setPressure(const MeshFunctionPointer& pressure) + { + + } + + void setSpeed(const RealType cavitySpeed) + { + + } + + void setHorizontalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + void setVerticalThrottleSpeed(const RealType startSpeed, + const RealType finalSpeed, + const RealType time, + const RealType finalTime ) + { + + } + + 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/src/Examples/turbulent-flows/zero-equation-model/CMakeLists.txt b/src/Examples/turbulent-flows/zero-equation-model/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1801a61e4d51384fb7b08bd1a980eaae8421a257 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/CMakeLists.txt @@ -0,0 +1,101 @@ +#zero-equation-turbulence-model-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + zeroEquationTurbulenceModelLaxFriedrichs.cpp + zeroEquationTurbulenceModelLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-Lax-Friedrichs zeroEquationTurbulenceModelLaxFriedrichs.cu) + target_link_libraries (tnl-zero-equation-turbulence-model-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-Lax-Friedrichs zeroEquationTurbulenceModelLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-zero-equation-turbulence-model-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-zero-equation-turbulence-model-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#zero-equation-turbulence-model-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + zeroEquationTurbulenceModelStegerWarming.cpp + zeroEquationTurbulenceModelStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-Steger-Warming zeroEquationTurbulenceModelStegerWarming.cu) + target_link_libraries (tnl-zero-equation-turbulence-model-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-Steger-Warming zeroEquationTurbulenceModelStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-zero-equation-turbulence-model-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-zero-equation-turbulence-model-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#zero-equation-turbulence-model-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + zeroEquationTurbulenceModelVanLeer.cpp + zeroEquationTurbulenceModelVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-Van-Leer zeroEquationTurbulenceModelVanLeer.cu) + target_link_libraries (tnl-zero-equation-turbulence-model-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-Van-Leer zeroEquationTurbulenceModelVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-zero-equation-turbulence-model-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-zero-equation-turbulence-model-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#zero-equation-turbulence-model-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + zeroEquationTurbulenceModelAUSMPlus.cpp + zeroEquationTurbulenceModelAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-AUSM-plus zeroEquationTurbulenceModelAUSMPlus.cu) + target_link_libraries (tnl-zero-equation-turbulence-model-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-zero-equation-turbulence-model-AUSM-plus zeroEquationTurbulenceModelAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-zero-equation-turbulence-model-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-zero-equation-turbulence-model-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/zero-equation-model/CMakeLists_separate.txt b/src/Examples/turbulent-flows/zero-equation-model/CMakeLists_separate.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd8e6f8708f7029abaf81aea4050908eb47bb71b --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/CMakeLists_separate.txt @@ -0,0 +1,101 @@ +#navier-stokes-Lax-Friedrichs + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesLaxFriedrichs.cpp + navierStokesLaxFriedrichs.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cu) + target_link_libraries (tnl-navier-stokes-Lax-Friedrichs ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Lax-Friedrichs navierStokesLaxFriedrichs.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Lax-Friedrichs + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Lax-Friedrichs + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Steger-Warming + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesStegerWarming.cpp + navierStokesStegerWarming.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cu) + target_link_libraries (tnl-navier-stokes-Steger-Warming ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Steger-Warming navierStokesStegerWarming.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Steger-Warming + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Steger-Warming + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-Van-Leer + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesVanLeer.cpp + navierStokesVanLeer.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cu) + target_link_libraries (tnl-navier-stokes-Van-Leer ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-Van-Leer navierStokesVanLeer.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-Van-Leer + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-Van-Leer + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + +#navier-stokes-AUSM-plus + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokesAUSMPlus.cpp + navierStokesAUSMPlus.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cu) + target_link_libraries (tnl-navier-stokes-AUSM-plus ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes-AUSM-plus navierStokesAUSMPlus.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes-AUSM-plus + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes-AUSM-plus + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/zero-equation-model/CMakeLists_together.txt b/src/Examples/turbulent-flows/zero-equation-model/CMakeLists_together.txt new file mode 100644 index 0000000000000000000000000000000000000000..f26fc6d34635dad513d36fd9c4ea21d3c1e95489 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/CMakeLists_together.txt @@ -0,0 +1,26 @@ +#navier-stokes + +set( tnl_flow_HEADERS + CompressibleConservativeVariables.h ) + +set( tnl_flow_SOURCES + navierStokes.cpp + navierStokes.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cu) + target_link_libraries (tnl-navier-stokes ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-navier-stokes navierStokes.cpp) +ENDIF( BUILD_CUDA ) + + +INSTALL( TARGETS tnl-navier-stokes + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES run-navier-stokes + ${tnl_flow_SOURCES} + DESTINATION ${TNL_TARGET_DATA_DIRECTORY}/examples/flow ) + + diff --git a/src/Examples/turbulent-flows/zero-equation-model/CompressibleConservativeVariables.h b/src/Examples/turbulent-flows/zero-equation-model/CompressibleConservativeVariables.h new file mode 100644 index 0000000000000000000000000000000000000000..b66f4d5c52e67a440d9dfca7350266c71977f3f7 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/CompressibleConservativeVariables.h @@ -0,0 +1,156 @@ +/*************************************************************************** + 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 +#include +#include + +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 Pointers::SharedPointer< MeshType > MeshPointer; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::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 ); + } + + __cuda_callable__ + MeshFunctionPointer& getDensity() + { + return this->density; + } + + __cuda_callable__ + const MeshFunctionPointer& getDensity() const + { + return this->density; + } + + void setDensity( MeshFunctionPointer& density ) + { + this->density = density; + } + + __cuda_callable__ + MomentumFieldPointer& getMomentum() + { + return this->momentum; + } + + __cuda_callable__ + const MomentumFieldPointer& getMomentum() const + { + return this->momentum; + } + + void setMomentum( MomentumFieldPointer& momentum ) + { + this->momentum = momentum; + } + + /* + __cuda_callable__ + MeshFunctionPointer& getPressure() + { + return this->pressure; + } + + __cuda_callable__ + const MeshFunctionPointer& getPressure() const + { + return this->pressure; + } + + void setPressure( MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }*/ + + __cuda_callable__ + MeshFunctionPointer& getEnergy() + { + return this->energy; + } + + __cuda_callable__ + 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 TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..0ef0575f22d0d0922c7b2f5ebe0934a6b5910047 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h @@ -0,0 +1,185 @@ +/*************************************************************************** + AUSMPlus.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 +#include +#include + +#include "AUSMPlusContinuity.h" +#include "AUSMPlusEnergy.h" +#include "AUSMPlusMomentumX.h" +#include "AUSMPlusMomentumY.h" +#include "AUSMPlusMomentumZ.h" + +#include "Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = PrandtlOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlus +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + + typedef AUSMPlusContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef AUSMPlusMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef AUSMPlusMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef AUSMPlusMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef AUSMPlusEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + + typedef Pointers::SharedPointer< OperatorRightHandSide > OperatorRightHandSidePointer; + + 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 ); + } + + AUSMPlus() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "AUSMPlus" << std::endl; + 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 ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + 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; + } + + const OperatorRightHandSidePointer& getOperatorRightHandSide() const + { + return this->operatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + + OperatorRightHandSidePointer operatorRightHandSidePointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusContinuity.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..1c90c16623d1878986e129fd00936a6663f5c7e0 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusContinuity.h @@ -0,0 +1,401 @@ +/*************************************************************************** + AUSMPlusContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "AUSMPlusContinuity< " ) + + 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 DensityFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity + MachBorderMinus * RightDensity ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + return hxInverse * ( + this->DensityFlux( u[ west ], u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ], u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return hxInverse * ( + this->DensityFlux( u[ west ] , u[ center ], velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->DensityFlux( u[ center ], u[ east ] , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->DensityFlux( u[ south ] , u[ center ], velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->DensityFlux( u[ center ], u[ north ] , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->DensityFlux( u[ down ] , u[ center ], velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->DensityFlux( u[ center ], u[ up ] , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusEnergy.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..f8a722d39916a3aca542c19b7ba906eedf11a644 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusEnergy.h @@ -0,0 +1,516 @@ +/*************************************************************************** + AUSMPlusEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + AUSMPlusEnergyBase() + : artificialViscosity( 1.0 ){}; + + static String getType() + { + return String( "AUSMPlusEnergy< " ) + + 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; + this->rightHandSide.setVelocity(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; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + RealType EnergyFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure, + const RealType& LeftEnergy, + const RealType& RightEnergy ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * ( LeftEnergy + LeftPressure) + MachBorderMinus * ( RightEnergy + RightPressure ) ); + }; + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType artificialViscosity, dynamicalViscosity; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusEnergyBase< MeshType, OperatorRightHandSide, 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& 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->EnergyFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center, u[ west ], u[ center ] ) + - this->EnergyFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east , u[ center ], u[ east ] ) + ) + + hyInverse * ( + this->EnergyFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center, u[ south ], u[ center ] ) + - this->EnergyFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north , u[ center ], u[ north ] ) + ) + + hzInverse * ( + this->EnergyFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center, u[ down ], u[ center ] ) + - this->EnergyFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up , u[ center ], u[ up ] ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumBase.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumBase.h new file mode 100644 index 0000000000000000000000000000000000000000..161a6f9bc75a303a7b6942d17807dcf9b3c0da5b --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumBase.h @@ -0,0 +1,200 @@ +/*************************************************************************** + AUSMPlusMomentumBase.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 OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + + void setTau(const Real& tau) + { + this->tau = tau; + }; + + void setGamma(const Real& gamma) + { + this->gamma = gamma; + }; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + this->rightHandSide.setVelocity(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; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + + RealType MainMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + RealType PressureSplitingPlus = 0; + RealType PressureSplitingMinus = 0; + RealType PressureBorder = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + PressureSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + PressureSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) * (2.0 - LeftMachNumber ) + + 3.0 / 16.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + PressureSplitingPlus = 1.0; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + PressureSplitingMinus = 1.0; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + PressureSplitingMinus = 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) * (2.0 + RightMachNumber ) + - 3.0 / 16.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + PressureSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + PressureBorder = PressureSplitingPlus * LeftPressure + PressureSplitingMinus * RightPressure; + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftVelocity + MachBorderMinus * RightDensity * RightVelocity ) + PressureBorder; + } + + RealType OtherMomentumFlux( const RealType& LeftDensity, + const RealType& RightDensity, + const RealType& LeftVelocity, + const RealType& RightVelocity, + const RealType& LeftOtherVelocity, + const RealType& RightOtherVelocity, + const RealType& LeftPressure, + const RealType& RightPressure ) const + { + const RealType& LeftSpeedOfSound = std::sqrt( std::abs( this->gamma * LeftPressure / LeftDensity ) ); + const RealType& RightSpeedOfSound = std::sqrt( std::abs( this->gamma * RightPressure / RightDensity ) ); + const RealType& BorderSpeedOfSound = 0.5 * ( LeftSpeedOfSound + RightSpeedOfSound ); + const RealType& LeftMachNumber = LeftVelocity / BorderSpeedOfSound; + const RealType& RightMachNumber = RightVelocity / BorderSpeedOfSound; + RealType MachSplitingPlus = 0; + RealType MachSplitingMinus = 0; + RealType MachBorderPlus = 0; + RealType MachBorderMinus = 0; + if ( LeftMachNumber <= -1.0 ) + { + MachSplitingPlus = 0; + } + else if ( LeftMachNumber <= 1.0 ) + { + MachSplitingPlus = 1.0 / 4.0 * ( LeftMachNumber + 1.0 ) * ( LeftMachNumber + 1.0 ) + + 1.0 / 8.0 * ( LeftMachNumber * LeftMachNumber - 1.0 ) * ( LeftMachNumber * LeftMachNumber - 1.0 ); + } + else + { + MachSplitingPlus = LeftMachNumber; + } + if ( RightMachNumber <= -1.0 ) + { + MachSplitingMinus = RightMachNumber; + } + else if ( RightMachNumber <= 1.0 ) + { + MachSplitingMinus = - 1.0 / 4.0 * ( RightMachNumber - 1.0 ) * ( RightMachNumber - 1.0 ) + - 1.0 / 8.0 * ( RightMachNumber * RightMachNumber - 1.0 ) * ( RightMachNumber * RightMachNumber - 1.0 ); + } + else + { + MachSplitingMinus = 0; + } + MachBorderPlus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) + std::abs( MachSplitingPlus + MachSplitingMinus )); + MachBorderMinus = 0.5 * ( ( MachSplitingPlus + MachSplitingMinus ) - std::abs( MachSplitingPlus + MachSplitingMinus )); + return BorderSpeedOfSound * ( MachBorderPlus * LeftDensity * LeftOtherVelocity + MachBorderMinus * RightDensity * RightOtherVelocity ); + } + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + RealType dynamicalViscosity; + + MeshFunctionPointer density; + +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumX.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..24f4c5e780ecb2d640b65ec8bd139f3207efd9c9 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumX.h @@ -0,0 +1,398 @@ +/*************************************************************************** + AUSMPlusMomentumX.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->MainMomentumFlux( density_west , density_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->MainMomentumFlux( density_center, density_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_x_south , velocity_x_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_x_center, velocity_x_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_x_down , velocity_x_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_x_center, velocity_x_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumY.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..d1a8d43041623a06152ac07c2fb114d2095e73ab --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumY.h @@ -0,0 +1,371 @@ +/*************************************************************************** + AUSMPlusMomentumY.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_y_west , velocity_y_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_y_center, velocity_y_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->MainMomentumFlux( density_south , density_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->MainMomentumFlux( density_center, density_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->OtherMomentumFlux( density_down , density_center, velocity_y_down , velocity_y_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->OtherMomentumFlux( density_center, density_up , velocity_y_center, velocity_y_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumZ.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..8915da35c870f05f85e91fa38afda392ad29b23b --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlusMomentumZ.h @@ -0,0 +1,316 @@ +/*************************************************************************** + AUSMPlusMomentumZ.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 +#include +#include "AUSMPlusMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class AUSMPlusMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class AUSMPlusMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public AUSMPlusMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef AUSMPlusMomentumBase< MeshType, OperatorRightHandSide, 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( "AUSMPlusMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return hxInverse * ( + this->OtherMomentumFlux( density_west , density_center, velocity_z_west , velocity_z_center, velocity_x_west , velocity_x_center, pressure_west , pressure_center ) + - this->OtherMomentumFlux( density_center, density_east , velocity_z_center, velocity_z_east , velocity_x_center, velocity_x_east , pressure_center, pressure_east ) + ) + + hyInverse * ( + this->OtherMomentumFlux( density_south , density_center, velocity_z_south , velocity_z_center, velocity_y_south , velocity_y_center, pressure_south , pressure_center ) + - this->OtherMomentumFlux( density_center, density_north , velocity_z_center, velocity_z_north , velocity_y_center, velocity_y_north , pressure_center, pressure_north ) + ) + + hzInverse * ( + this->MainMomentumFlux( density_down , density_center, velocity_z_down , velocity_z_center, pressure_down , pressure_center ) + - this->MainMomentumFlux( density_center, density_up , velocity_z_center, velocity_z_up , pressure_center, pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/flow-vl/LaxFridrichs.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h similarity index 63% rename from src/Examples/flow-vl/LaxFridrichs.h rename to src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h index c56d20aed9947bd16796a5bf7ceb22adb237bf0c..4be9de0efac9f07aec8331039ca3f69f29d82d15 100644 --- a/src/Examples/flow-vl/LaxFridrichs.h +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h @@ -21,9 +21,12 @@ #include "LaxFridrichsMomentumY.h" #include "LaxFridrichsMomentumZ.h" +#include "Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + namespace TNL { template< typename Mesh, + typename OperatorRightHandSide = PrandtlOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichs @@ -36,12 +39,18 @@ class LaxFridrichs typedef Functions::MeshFunction< Mesh > MeshFunctionType; static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; - 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 LaxFridrichsContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef LaxFridrichsMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef LaxFridrichsMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef LaxFridrichsMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef LaxFridrichsEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; @@ -53,10 +62,13 @@ class LaxFridrichs typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + typedef Pointers::SharedPointer< OperatorRightHandSide > OperatorRightHandSidePointer; + static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) { config.addEntry< double >( prefix + "numerical-viscosity", "Value of artificial (numerical) viscosity in the Lax-Fridrichs scheme", 1.0 ); + config.addEntry< double >( prefix + "dynamical-viscosity", "Value of dynamical (real) viscosity in the Navier-Stokes equation", 1.0 ); } LaxFridrichs() @@ -66,6 +78,12 @@ class LaxFridrichs const Config::ParameterContainer& parameters, const String& prefix = "" ) { + std::cout << "Lax-Friedrichs" << std::endl; + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorPointer->setDynamicalViscosity( dynamicalViscosity ); this->artificialViscosity = parameters.getParameter< double >( prefix + "numerical-viscosity" ); this->continuityOperatorPointer->setArtificialViscosity( artificialViscosity ); this->momentumXOperatorPointer->setArtificialViscosity( artificialViscosity ); @@ -84,6 +102,10 @@ class LaxFridrichs this->momentumZOperatorPointer->setTau( tau ); this->energyOperatorPointer->setTau( tau ); } + + void setGamma( const RealType& gamma ) + { + } void setPressure( const MeshFunctionPointer& pressure ) { @@ -92,6 +114,10 @@ class LaxFridrichs this->momentumZOperatorPointer->setPressure( pressure ); this->energyOperatorPointer->setPressure( pressure ); } + + void setDensity( const MeshFunctionPointer& density ) + { + } void setVelocity( const VectorFieldPointer& velocity ) { @@ -101,6 +127,14 @@ class LaxFridrichs this->momentumZOperatorPointer->setVelocity( velocity ); this->energyOperatorPointer->setVelocity( velocity ); } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } const ContinuityOperatorPointer& getContinuityOperator() const { @@ -127,15 +161,23 @@ class LaxFridrichs return this->energyOperatorPointer; } + const OperatorRightHandSidePointer& getOperatorRightHandSide() const + { + return this->operatorRightHandSidePointer; + } + protected: ContinuityOperatorPointer continuityOperatorPointer; MomentumXOperatorPointer momentumXOperatorPointer; MomentumYOperatorPointer momentumYOperatorPointer; MomentumZOperatorPointer momentumZOperatorPointer; - EnergyOperatorPointer energyOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + + OperatorRightHandSidePointer operatorRightHandSidePointer; RealType artificialViscosity; + RealType dynamicalViscosity; }; } //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsContinuity.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..e82c9d4242d426adb2f21b238b05f0773e3b1c3b --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsContinuity.h @@ -0,0 +1,310 @@ +/*************************************************************************** + 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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + 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; + + OperatorRightHandSideType rightHandSide; + + RealType artificialViscosity; +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + +// return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) +// - 0.5 * ( u[ west ] * velocity_x_west - u[ east ] * velocity_x_east ) * hxInverse; + return 1.0 / ( 2.0 * this->tau ) * this->artificialViscosity * ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) + - 0.5 * ( u[ east ] * velocity_x_east - u[ west ] * velocity_x_west ) * hxInverse + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/flow-vl/LaxFridrichsEnergy.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsEnergy.h similarity index 70% rename from src/Examples/flow-vl/LaxFridrichsEnergy.h rename to src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsEnergy.h index 03019ed23c85f82ee489c95d8173c0f100cff3c8..18ef0ed4a624487d81a5a332eeb8d3e751d69add 100644 --- a/src/Examples/flow-vl/LaxFridrichsEnergy.h +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsEnergy.h @@ -16,6 +16,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergyBase @@ -32,6 +33,7 @@ class LaxFridrichsEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsEnergyBase() : artificialViscosity( 1.0 ){}; @@ -52,6 +54,7 @@ class LaxFridrichsEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -63,12 +66,24 @@ class LaxFridrichsEnergyBase { this->artificialViscosity = artificialViscosity; } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; protected: RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; @@ -76,6 +91,7 @@ class LaxFridrichsEnergyBase }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsEnergy @@ -85,15 +101,16 @@ class LaxFridrichsEnergy template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -115,18 +132,23 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, 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& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + const IndexType& center = entity.getIndex(); - const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + 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_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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; - + - ( e[ west ] + pressure_west ) * velocity_x_west ) * hxInverse + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -150,14 +172,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -180,27 +203,33 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ); + -( ( e[ south ] + pressure_south ) * velocity_y_south ) ) * hyInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > @@ -224,14 +253,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef LaxFridrichsEnergyBase< MeshType, Real, Index > BaseType; + typedef LaxFridrichsEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -253,16 +283,17 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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& 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 ]; @@ -270,13 +301,15 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, 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 ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ] ) @@ -285,7 +318,9 @@ class LaxFridrichsEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, + ( ( ( 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 ); + -( ( e[ down ] + pressure_down ) * velocity_z_down ) ) * hzInverse ) + + + this->rightHandSide(e, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumBase.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumBase.h similarity index 80% rename from src/Examples/inviscid-flow-sw/LaxFridrichsMomentumBase.h rename to src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumBase.h index cc2561748968a2bd808fa434d4f3d87d41765f45..6ed4935f5683098b9f92d27972a930158f2b5316 100644 --- a/src/Examples/inviscid-flow-sw/LaxFridrichsMomentumBase.h +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumBase.h @@ -14,6 +14,7 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > class LaxFridrichsMomentumBase @@ -30,6 +31,7 @@ class LaxFridrichsMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; LaxFridrichsMomentumBase() : artificialViscosity( 1.0 ){}; @@ -42,6 +44,7 @@ class LaxFridrichsMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -54,11 +57,23 @@ class LaxFridrichsMomentumBase this->artificialViscosity = artificialViscosity; } + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + protected: RealType tau; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumX.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..57258d1a534721a5887ad8affb0e60acdf66943d --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumX.h @@ -0,0 +1,295 @@ +/*************************************************************************** + 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 +#include +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 + + + this->rightHandSide(rho_u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + + const 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(rho_u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, 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& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(rho_u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumY.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..4cca02779d04d1395051035156d30b8a998ffa64 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumY.h @@ -0,0 +1,280 @@ +/*************************************************************************** + 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 +#include +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, 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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(rho_v, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + + const 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(rho_v, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumZ.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..1f394bfef12c16125be4a674d08f2defbc455f12 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichsMomentumZ.h @@ -0,0 +1,251 @@ +/*************************************************************************** + 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 +#include +#include "LaxFridrichsMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class LaxFridrichsMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, 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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, 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 OperatorRightHandSide, + typename Real, + typename Index > +class LaxFridrichsMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public LaxFridrichsMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef LaxFridrichsMomentumBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + + + this->rightHandSide(rho_w, entity, time); + } + + /*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/src/Examples/inviscid-flow-sw/Upwind.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h similarity index 63% rename from src/Examples/inviscid-flow-sw/Upwind.h rename to src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h index 529e0aadf7e68c86c97393e122927142014c8c45..c00deb195924f2dfbcef19fb48886bf304f2a4e8 100644 --- a/src/Examples/inviscid-flow-sw/Upwind.h +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h @@ -1,5 +1,5 @@ /*************************************************************************** - Upwind.h - description + StegerWarming.h - description ------------------- begin : Feb 18, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -15,18 +15,21 @@ #include #include -#include "UpwindContinuity.h" -#include "UpwindEnergy.h" -#include "UpwindMomentumX.h" -#include "UpwindMomentumY.h" -#include "UpwindMomentumZ.h" +#include "StegerWarmingContinuity.h" +#include "StegerWarmingEnergy.h" +#include "StegerWarmingMomentumX.h" +#include "StegerWarmingMomentumY.h" +#include "StegerWarmingMomentumZ.h" + +#include "Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" namespace TNL { template< typename Mesh, + typename OperatorRightHandSide = PrandtlOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class Upwind +class StegerWarming { public: typedef Mesh MeshType; @@ -36,12 +39,18 @@ class Upwind typedef Functions::MeshFunction< Mesh > MeshFunctionType; static const int Dimensions = Mesh::getMeshDimension(); typedef Functions::VectorField< Dimensions, MeshFunctionType > VectorFieldType; + + typedef typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; - 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 StegerWarmingContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef StegerWarmingMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef StegerWarmingMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef StegerWarmingMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef StegerWarmingEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; @@ -56,15 +65,23 @@ class Upwind 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() - : artificialViscosity( 1.0 ) {} + StegerWarming() + :dynamicalViscosity( 1.0 ) {} bool setup( const MeshPointer& meshPointer, const Config::ParameterContainer& parameters, const String& prefix = "" ) { + std::cout << "Steger-Warming"<< std::endl; + 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; } @@ -111,6 +128,14 @@ class Upwind this->momentumZOperatorPointer->setVelocity( velocity ); this->energyOperatorPointer->setVelocity( velocity ); } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } const ContinuityOperatorPointer& getContinuityOperator() const { @@ -145,7 +170,7 @@ class Upwind MomentumZOperatorPointer momentumZOperatorPointer; EnergyOperatorPointer energyOperatorPointer; - RealType artificialViscosity; + RealType dynamicalViscosity; }; } //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingContinuity.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..a27d3e1399f2633c0e0f6b01a29ec516c8763df1 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingContinuity.h @@ -0,0 +1,396 @@ +/*************************************************************************** + StegerWarmingContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingContinuity< " ) + + 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber + 1.0 ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 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 <= 0.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound / ( 2 * this->gamma ) * ( machNumber - 1.0 ); + else + return 0.0; + }; + + + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingEnergy.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingEnergy.h new file mode 100644 index 0000000000000000000000000000000000000000..81037b5db9b500c46a196dfed518d492eee36f70 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingEnergy.h @@ -0,0 +1,555 @@ +/*************************************************************************** + StegerWarmingEnergy.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 +#include + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingEnergyBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "StegerWarmingEnergy< " ) + + 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; + this->rightHandSide.setVelocity(velocity); + }; + + void setPressure( const MeshFunctionPointer& pressure ) + { + this->pressure = pressure; + }; + + void setDensity( const MeshFunctionPointer& density ) + { + this->density = density; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + } + + protected: + + RealType tau; + + RealType gamma; + + VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + + MeshFunctionPointer density; +}; + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingEnergy +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingEnergyBase< MeshType, OperatorRightHandSide, 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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber + 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + + ( machNumber * ( machNumber + 1.0 ) ) + + ( ( machNumber + 1.0 ) / ( this->gamma - 1.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 <= 0.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( ( 2.0 * this->gamma - 1.0 ) * machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.0 ) ) + ); + else if ( machNumber <= 1.0 ) + return density * speedOfSound * speedOfSound * speedOfSound / ( 2.0 * this->gamma ) + * ( + ( ( machNumber - 1.0 ) * 0.5 * ( machNumber * machNumber + ( velocity_other1 * velocity_other1 + velocity_other2 * velocity_other2 ) / ( speedOfSound * speedOfSound ) ) ) + - ( machNumber * ( machNumber - 1.0 ) ) + + ( ( machNumber - 1.0 ) / ( this->gamma - 1.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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_up , pressure_up ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/inviscid-flow-sw/UpwindMomentumBase.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumBase.h similarity index 89% rename from src/Examples/inviscid-flow-sw/UpwindMomentumBase.h rename to src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumBase.h index be1333f810b2e168d6821aa6c1b362ae41d5dade..ce0a7125ba10372816c8c5084bea058aa9769121 100644 --- a/src/Examples/inviscid-flow-sw/UpwindMomentumBase.h +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumBase.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumBase.h - description + StegerWarmingMomentumBase.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -14,9 +14,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumBase +class StegerWarmingMomentumBase { public: @@ -30,6 +31,7 @@ class UpwindMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; void setTau(const Real& tau) @@ -45,6 +47,7 @@ class UpwindMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setDensity( const MeshFunctionPointer& density ) @@ -57,7 +60,16 @@ class UpwindMomentumBase this->pressure = pressure; }; - __cuda_callable__ + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + RealType positiveMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -72,7 +84,6 @@ class UpwindMomentumBase return density * velocity * velocity + pressure; }; - __cuda_callable__ RealType negativeMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -87,7 +98,6 @@ class UpwindMomentumBase return 0; }; - __cuda_callable__ 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 ); @@ -102,7 +112,6 @@ class UpwindMomentumBase return density * velocity_main * velocity_other; }; - __cuda_callable__ 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 ); @@ -124,6 +133,8 @@ class UpwindMomentumBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumX.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..c6588083cd9efdd02864d6200cff678de8d0a76d --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumX.h @@ -0,0 +1,356 @@ +/*************************************************************************** + StegerWarmingMomentumX.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumY.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..210fb60878d9da9f6f44bb55972997d73be63df7 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumY.h @@ -0,0 +1,326 @@ +/*************************************************************************** + StegerWarmingMomentumY.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumZ.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..135352d2fdf260a2310e5c6e45f2cc581d0e9ff0 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarmingMomentumZ.h @@ -0,0 +1,282 @@ +/*************************************************************************** + StegerWarmingMomentumZ.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 +#include +#include "StegerWarmingMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class StegerWarmingMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class StegerWarmingMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public StegerWarmingMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef StegerWarmingMomentumBase< MeshType, OperatorRightHandSide, 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( "StegerWarmingMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + + return 0-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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..e413c4b10ada7317ec35fb9a0017baa107ac01dc --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h @@ -0,0 +1,185 @@ +/*************************************************************************** + VanLeer.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 +#include +#include + +#include "VanLeerContinuity.h" +#include "VanLeerEnergy.h" +#include "VanLeerMomentumX.h" +#include "VanLeerMomentumY.h" +#include "VanLeerMomentumZ.h" + +#include "Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide = PrandtlOperatorRightHandSide < Mesh, typename Mesh::RealType, typename Mesh::IndexType >, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeer +{ + 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 typename OperatorRightHandSide::ContinuityOperatorRightHandSideType ContinuityOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumXOperatorRightHandSideType MomentumXOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumYOperatorRightHandSideType MomentumYOperatorRightHandSideType; + typedef typename OperatorRightHandSide::MomentumZOperatorRightHandSideType MomentumZOperatorRightHandSideType; + typedef typename OperatorRightHandSide::EnergyOperatorRightHandSideType EnergyOperatorRightHandSideType; + + typedef VanLeerContinuity< Mesh, ContinuityOperatorRightHandSideType, Real, Index > ContinuityOperatorType; + typedef VanLeerMomentumX< Mesh, MomentumXOperatorRightHandSideType, Real, Index > MomentumXOperatorType; + typedef VanLeerMomentumY< Mesh, MomentumYOperatorRightHandSideType, Real, Index > MomentumYOperatorType; + typedef VanLeerMomentumZ< Mesh, MomentumZOperatorRightHandSideType, Real, Index > MomentumZOperatorType; + typedef VanLeerEnergy< Mesh, EnergyOperatorRightHandSideType, Real, Index > EnergyOperatorType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorType > ContinuityOperatorPointer; + typedef Pointers::SharedPointer< MomentumXOperatorType > MomentumXOperatorPointer; + typedef Pointers::SharedPointer< MomentumYOperatorType > MomentumYOperatorPointer; + typedef Pointers::SharedPointer< MomentumZOperatorType > MomentumZOperatorPointer; + typedef Pointers::SharedPointer< EnergyOperatorType > EnergyOperatorPointer; + + typedef Pointers::SharedPointer< OperatorRightHandSide > OperatorRightHandSidePointer; + + 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 ); + } + + VanLeer() + :dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + std::cout << "VanLeer" << std::endl; + 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 ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorPointer->setTurbulentViscosity( turbulentViscosity ); + } + + 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; + } + + const OperatorRightHandSidePointer& getOperatorRightHandSide() const + { + return this->operatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorPointer continuityOperatorPointer; + MomentumXOperatorPointer momentumXOperatorPointer; + MomentumYOperatorPointer momentumYOperatorPointer; + MomentumZOperatorPointer momentumZOperatorPointer; + EnergyOperatorPointer energyOperatorPointer; + + OperatorRightHandSidePointer operatorRightHandSidePointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerContinuity.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerContinuity.h new file mode 100644 index 0000000000000000000000000000000000000000..3b497125a6a291990c61c4fed6f158a73472e084 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerContinuity.h @@ -0,0 +1,396 @@ +/*************************************************************************** + VanLeerContinuity.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerContinuityBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; + + static String getType() + { + return String( "VanLeerContinuity< " ) + + 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; + + OperatorRightHandSideType rightHandSide; + + MeshFunctionPointer pressure; + +}; + + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerContinuity +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerContinuity< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerContinuityBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerContinuityBase< MeshType, OperatorRightHandSide, 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + } + + /*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/src/Examples/flow-vl/UpwindEnergy.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerEnergy.h similarity index 55% rename from src/Examples/flow-vl/UpwindEnergy.h rename to src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerEnergy.h index 8fa7a046a24d37c832746d6f17396e39582f7f5e..9805faddb518e2939c67d2e930b86d9ba2ad6461 100644 --- a/src/Examples/flow-vl/UpwindEnergy.h +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerEnergy.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindEnergy.h - description + VanLeerEnergy.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -16,9 +16,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergyBase +class VanLeerEnergyBase { public: @@ -32,13 +33,14 @@ class UpwindEnergyBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; - UpwindEnergyBase() + VanLeerEnergyBase() : artificialViscosity( 1.0 ){}; static String getType() { - return String( "UpwindEnergy< " ) + + return String( "VanLeerEnergy< " ) + MeshType::getType() + ", " + TNL::getType< Real >() + ", " + TNL::getType< Index >() + " >"; @@ -57,6 +59,7 @@ class UpwindEnergyBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setPressure( const MeshFunctionPointer& pressure ) @@ -77,8 +80,14 @@ class UpwindEnergyBase void setDynamicalViscosity( const RealType& dynamicalViscosity ) { this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); } + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + protected: RealType tau; @@ -86,6 +95,8 @@ class UpwindEnergyBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; @@ -95,24 +106,26 @@ class UpwindEnergyBase }; template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindEnergy +class VanLeerEnergy { }; template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -124,7 +137,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index using typename BaseType::VelocityFieldPointer; using BaseType::Dimensions; - __cuda_callable__ RealType positiveEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -142,7 +154,6 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index return velocity_main * ( pressure + pressure / ( this->gamma - 1.0 ) + 0.5 * density * ( velocity_main * velocity_main ) ); }; - __cuda_callable__ RealType negativeEnergyFlux( const RealType& density, const RealType& velocity_main, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -171,11 +182,12 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 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 ]; @@ -185,9 +197,9 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, pressure_center) @@ -195,11 +207,8 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index - 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; + + + this->rightHandSide(u, entity, time); } @@ -224,14 +233,15 @@ class UpwindEnergy< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -289,20 +299,21 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 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 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 ]; @@ -316,25 +327,25 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, pressure_center) @@ -348,38 +359,8 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index - 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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > @@ -403,14 +384,15 @@ class UpwindEnergy< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index template< typename MeshReal, typename Device, typename MeshIndex, + typename OperatorRightHandSide, typename Real, typename Index > -class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > - : public UpwindEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +class VanLeerEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerEnergyBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > { public: typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; - typedef UpwindEnergyBase< MeshType, Real, Index > BaseType; + typedef VanLeerEnergyBase< MeshType, OperatorRightHandSide, Real, Index > BaseType; using typename BaseType::RealType; using typename BaseType::IndexType; @@ -470,32 +452,33 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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 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& 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& 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& 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& 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 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 ]; @@ -513,53 +496,53 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index 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 ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; return -hxInverse * ( this->positiveEnergyFlux( density_center, velocity_x_center, velocity_y_center, velocity_z_center, pressure_center) @@ -573,93 +556,14 @@ class UpwindEnergy< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index - 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 ) + -hzInverse * ( + this->positiveEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + - this->positiveEnergyFlux( density_down , velocity_z_down , velocity_x_down , velocity_y_down , pressure_down ) + - this->negativeEnergyFlux( density_center, velocity_z_center, velocity_x_center, velocity_y_center, pressure_center) + + this->negativeEnergyFlux( density_up , velocity_z_up , velocity_x_up , velocity_y_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; + + + this->rightHandSide(u, entity, time); } /*template< typename MeshEntity > diff --git a/src/Examples/inviscid-flow-vl/UpwindMomentumBase.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumBase.h similarity index 79% rename from src/Examples/inviscid-flow-vl/UpwindMomentumBase.h rename to src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumBase.h index 93b470a2822c6e4d33b700a41eadf4953ec1d01c..b1a52af2ffe4c98d72fdded552b812c17b2a35dd 100644 --- a/src/Examples/inviscid-flow-vl/UpwindMomentumBase.h +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumBase.h @@ -1,5 +1,5 @@ /*************************************************************************** - UpwindMomentumBase.h - description + VanLeerMomentumBase.h - description ------------------- begin : Feb 17, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -14,9 +14,10 @@ namespace TNL { template< typename Mesh, + typename OperatorRightHandSide, typename Real = typename Mesh::RealType, typename Index = typename Mesh::IndexType > -class UpwindMomentumBase +class VanLeerMomentumBase { public: @@ -30,6 +31,7 @@ class UpwindMomentumBase typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + typedef OperatorRightHandSide OperatorRightHandSideType; void setTau(const Real& tau) @@ -45,6 +47,7 @@ class UpwindMomentumBase void setVelocity( const VelocityFieldPointer& velocity ) { this->velocity = velocity; + this->rightHandSide.setVelocity(velocity); }; void setDensity( const MeshFunctionPointer& density ) @@ -57,7 +60,17 @@ class UpwindMomentumBase this->pressure = pressure; }; - __cuda_callable__ + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + this->rightHandSide.setDynamicalViscosity(dynamicalViscosity); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->rightHandSide.setTurbulentViscosity(turbulentViscosity); + }; + RealType positiveMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -65,14 +78,11 @@ class UpwindMomentumBase if ( machNumber <= -1.0 ) return 0; else if ( machNumber <= 1.0 ) - return density * speedOfSound / 4.0 * ( machNumber + 1.0 ) * ( machNumber + 1.0 ) - * ( ( 2.0 * speedOfSound ) / this->gamma ) - * ( 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.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; }; - __cuda_callable__ RealType negativeMainMomentumFlux( const RealType& density, const RealType& velocity, const RealType& pressure ) const { const RealType& speedOfSound = std::sqrt( this->gamma * pressure / density ); @@ -80,14 +90,11 @@ class UpwindMomentumBase if ( machNumber <= -1.0 ) return density * velocity * velocity + pressure; else if ( machNumber <= 1.0 ) - return - density * speedOfSound / 4.0 * ( machNumber - 1.0 ) * ( machNumber - 1.0 ) - * ( ( 2.0 * speedOfSound ) / this->gamma ) - * ( - 1.0 + ( this->gamma - 1.0 ) * machNumber / 2.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; }; - __cuda_callable__ 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 ); @@ -100,7 +107,6 @@ class UpwindMomentumBase return density * velocity_main * velocity_other; }; - __cuda_callable__ 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 ); @@ -120,9 +126,13 @@ class UpwindMomentumBase RealType gamma; VelocityFieldPointer velocity; + + OperatorRightHandSideType rightHandSide; MeshFunctionPointer pressure; + RealType dynamicalViscosity; + MeshFunctionPointer density; }; diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumX.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumX.h new file mode 100644 index 0000000000000000000000000000000000000000..04e41c015c6193ec3c7e45d5d737512a2762f38a --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumX.h @@ -0,0 +1,410 @@ +/*************************************************************************** + VanLeerMomentumX.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumX +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + + + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumX< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumX< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumY.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumY.h new file mode 100644 index 0000000000000000000000000000000000000000..65ac8482807903cb2e98f8fbc25a4627d1ef7a4b --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumY.h @@ -0,0 +1,381 @@ +/*************************************************************************** + VanLeerMomentumY.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumY +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumY< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumY< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumZ.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumZ.h new file mode 100644 index 0000000000000000000000000000000000000000..125166cb885b65a8f14049a90dcf92449d644498 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperators/Navier-Stokes/VanLeer/VanLeerMomentumZ.h @@ -0,0 +1,322 @@ +/*************************************************************************** + VanLeerMomentumZ.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 +#include +#include "VanLeerMomentumBase.h" + +namespace TNL { + +template< typename Mesh, + typename OperatorRightHandSide, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class VanLeerMomentumZ +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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 OperatorRightHandSide, + typename Real, + typename Index > +class VanLeerMomentumZ< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > + : public VanLeerMomentumBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, OperatorRightHandSide, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef VanLeerMomentumBase< MeshType, OperatorRightHandSide, 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( "VanLeerMomentumZ< " ) + + 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< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 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 ) + ) + + + this->rightHandSide(u, entity, time); + } + + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlContinuityOperatorRightHandSide.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlContinuityOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..2202fc217c41bad103aecbe98fc318ca12359fd9 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlContinuityOperatorRightHandSide.h @@ -0,0 +1,218 @@ +/*************************************************************************** + PrandtlContinuityOperatorRightHandSide.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 +#include +#include +#include + +namespace TNL { + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlContinuityRightHandSideBase +{ + 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 Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + + static String getType() + { + return String( "LaxFridrichsContinuity< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + + protected: + +}; + + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlContinuityRightHandSide +{ +}; + + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlContinuityRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlContinuityRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlContinuityRightHandSideBase< 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" ); + + return 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 PrandtlContinuityRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlContinuityRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlContinuityRightHandSideBase< 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" ); + + return 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 PrandtlContinuityRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlContinuityRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlContinuityRightHandSideBase< 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" ); + + return 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;*/ +}; + + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlEnergyOperatorRightHandSide.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlEnergyOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..132277f0a7e0d591531937a2532b8f423cadc0e5 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlEnergyOperatorRightHandSide.h @@ -0,0 +1,619 @@ +/*************************************************************************** + PrandtlEnergyOperatorRightHandSide.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 +#include + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlEnergyRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + PrandtlEnergyRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + static String getType() + { + return String( "LaxFridrichsEnergy< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + } + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + } + + protected: + + MeshFunctionPointer turbulentViscosity; + + VelocityFieldPointer velocity; + + RealType dynamicalViscosity; +}; + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlEnergyRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlEnergyRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlEnergyRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 1, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 1, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 1 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D uT_11_x + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center - velocity_x_center * velocity_x_west + - velocity_x_center * velocity_x_center + velocity_x_west * velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D_t_11_x + + + 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse; + } + + /*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 PrandtlEnergyRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlEnergyRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + - velocity_x_center * velocity_x_center + velocity_x_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_south + - velocity_x_northWest * velocity_y_north + velocity_x_southWest * velocity_y_south + ) * hxInverse * hyInverse / 4 + ) * this->dynamicalViscosity +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + ); + } + + /*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 PrandtlEnergyRightHandSide< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlEnergyRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlEnergyRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& e, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_12_x + + ( ( velocity_x_northEast * velocity_y_east - velocity_x_southEast * velocity_y_east + - velocity_x_northWest * velocity_y_west + velocity_x_southWest * velocity_y_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center - velocity_y_center * velocity_y_west + - velocity_y_center * velocity_y_center + velocity_y_west * velocity_y_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// wT_13_x + + ( ( velocity_x_upEast * velocity_z_east - velocity_x_downEast * velocity_z_east + - velocity_x_upWest * velocity_z_west + velocity_x_downWest * velocity_z_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center - velocity_z_center * velocity_z_west + - velocity_z_center * velocity_z_center + velocity_z_west * velocity_z_west + ) * hxSquareInverse + ) * this->dynamicalViscosity +// uT_21_y + + ( ( velocity_y_northEast * velocity_x_north - velocity_y_southEast * velocity_x_south + - velocity_y_northWest * velocity_x_north + velocity_y_southWest * velocity_x_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center - velocity_x_center * velocity_x_south + + velocity_x_center * velocity_x_center + velocity_x_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_23_y + + ( ( velocity_y_upNorth * velocity_z_north - velocity_y_downNorth * velocity_y_north + - velocity_y_upSouth * velocity_z_south + velocity_y_downSouth * velocity_z_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center - velocity_z_center * velocity_z_south + - velocity_z_center * velocity_z_center + velocity_z_south * velocity_z_south + ) * hySquareInverse + ) * this->dynamicalViscosity +// uT_31_z + + ( ( velocity_x_up * velocity_x_center - velocity_x_center * velocity_x_center + - velocity_x_center * velocity_x_down + velocity_x_down * velocity_x_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up - velocity_z_downEast * velocity_x_down + - velocity_z_upWest * velocity_x_up + velocity_z_downWest * velocity_x_down + ) * hxInverse * hzInverse / 4 + ) * this->dynamicalViscosity +// T_32_z + + ( ( velocity_z_upNorth * velocity_y_up - velocity_z_downNorth * velocity_y_down + - velocity_z_upSouth * velocity_y_up + velocity_z_downSouth * velocity_y_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center - velocity_x_center * velocity_y_down + - velocity_x_center * velocity_y_center + velocity_x_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 +// ut_11_x + + + ( 4.0 / 3.0 * ( velocity_x_east * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_west * turbulentViscosity_west + - velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_west * velocity_x_west * turbulentViscosity_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( velocity_y_northEast * velocity_x_east * turbulentViscosity_east - velocity_y_southEast * velocity_x_east * turbulentViscosity_east + - velocity_y_northWest * velocity_x_west * turbulentViscosity_west + velocity_y_southWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upEast * velocity_x_east * turbulentViscosity_east - velocity_z_downEast * velocity_x_east * turbulentViscosity_east + - velocity_z_upWest * velocity_x_west * turbulentViscosity_west + velocity_z_downWest * velocity_x_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + ) +// vt_12_x + + ( ( velocity_x_northEast * velocity_y_east * turbulentViscosity_east - velocity_x_southEast * velocity_y_east * turbulentViscosity_east + - velocity_x_northWest * velocity_y_west * turbulentViscosity_west + velocity_x_southWest * velocity_y_west * turbulentViscosity_west + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_west * turbulentViscosity_west + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_west * velocity_y_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// wt_13_x + + ( ( velocity_x_upEast * velocity_z_east * turbulentViscosity_east - velocity_x_downEast * velocity_z_east * turbulentViscosity_east + - velocity_x_upWest * velocity_z_west * turbulentViscosity_west + velocity_x_downWest * velocity_z_west * turbulentViscosity_west + ) * hxInverse * hzInverse / 4 + + ( velocity_z_east * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_west * turbulentViscosity_west + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_west * velocity_z_west * turbulentViscosity_west + ) * hxSquareInverse + ) +// ut_21_y + + ( ( velocity_y_northEast * velocity_x_north * turbulentViscosity_north - velocity_y_southEast * velocity_x_south * turbulentViscosity_south + - velocity_y_northWest * velocity_x_north * turbulentViscosity_north + velocity_y_southWest * velocity_x_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + + ( velocity_x_north * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_south * turbulentViscosity_south + + velocity_x_center * velocity_x_center * turbulentViscosity_center + velocity_x_south * velocity_x_south * turbulentViscosity_south + ) * hySquareInverse + ) +// vt_22_y + + ( 4.0 / 3.0 * ( velocity_y_north * velocity_y_center * turbulentViscosity_center - velocity_y_center * velocity_y_south * turbulentViscosity_south + - velocity_y_center * velocity_y_center * turbulentViscosity_center + velocity_y_south * velocity_y_south * turbulentViscosity_south + ) * hySquareInverse + - 2.0 / 3.0 * ( velocity_x_northEast * velocity_y_north * turbulentViscosity_north - velocity_x_southEast * velocity_y_south * turbulentViscosity_south + - velocity_x_northWest * velocity_y_north * turbulentViscosity_north + velocity_x_southWest * velocity_y_south * turbulentViscosity_south + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( velocity_z_upNorth * velocity_y_north * turbulentViscosity_north - velocity_z_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_z_upSouth * velocity_y_south * turbulentViscosity_south + velocity_z_downSouth * velocity_y_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + ) +// wt_23_y + + ( ( velocity_y_upNorth * velocity_z_north * turbulentViscosity_north - velocity_y_downNorth * velocity_y_north * turbulentViscosity_north + - velocity_y_upSouth * velocity_z_south * turbulentViscosity_south + velocity_y_downSouth * velocity_z_south * turbulentViscosity_south + ) * hyInverse * hzInverse / 4 + + ( velocity_z_north * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_south * turbulentViscosity_south + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_south * velocity_z_south * turbulentViscosity_south + ) * hySquareInverse + ) +// ut_31_z + + ( ( velocity_x_up * velocity_x_center * turbulentViscosity_center - velocity_x_center * velocity_x_center * turbulentViscosity_center + - velocity_x_center * velocity_x_down * turbulentViscosity_down + velocity_x_down * velocity_x_down * turbulentViscosity_down + ) * hzSquareInverse + + ( velocity_z_upEast * velocity_x_up * turbulentViscosity_up - velocity_z_downEast * velocity_x_down * turbulentViscosity_down + - velocity_z_upWest * velocity_x_up * turbulentViscosity_up + velocity_z_downWest * velocity_x_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + ) +// vt_32_z + + ( ( velocity_z_upNorth * velocity_y_up * turbulentViscosity_up - velocity_z_downNorth * velocity_y_down * turbulentViscosity_down + - velocity_z_upSouth * velocity_y_up * turbulentViscosity_up + velocity_z_downSouth * velocity_y_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + + ( velocity_x_up * velocity_y_center * turbulentViscosity_center - velocity_x_center * velocity_y_down * turbulentViscosity_down + - velocity_x_center * velocity_y_center * turbulentViscosity_center + velocity_x_down * velocity_y_down * turbulentViscosity_down + ) * hzSquareInverse + ) +// wt_33_z + + ( 4.0 / 3.0 * ( velocity_z_up * velocity_z_center * turbulentViscosity_center - velocity_z_center * velocity_z_down * turbulentViscosity_down + - velocity_z_center * velocity_z_center * turbulentViscosity_center + velocity_z_down * velocity_z_down * turbulentViscosity_down + ) * hzSquareInverse + - 2.0 / 3.0 * ( velocity_y_upNorth * velocity_z_up * turbulentViscosity_up - velocity_y_downNorth * velocity_z_down * turbulentViscosity_down + - velocity_y_upSouth * velocity_z_up * turbulentViscosity_up + velocity_y_downSouth * velocity_z_down * turbulentViscosity_down + ) * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( velocity_x_upEast * velocity_z_up * turbulentViscosity_up - velocity_x_downEast * velocity_z_down * turbulentViscosity_down + - velocity_x_upWest * velocity_z_up * turbulentViscosity_up + velocity_x_downWest * velocity_z_down * turbulentViscosity_down + ) * hxInverse * hzInverse / 4 + ); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumBaseOperatorRightHandSide.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumBaseOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..1e6b807ceba30a2a140b9cc72c4a9e223d23bf5f --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumBaseOperatorRightHandSide.h @@ -0,0 +1,66 @@ +/*************************************************************************** + PrandtlMomentumRightHandSideBase.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 PrandtlMomentumRightHandSideBase +{ + 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 Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + PrandtlMomentumRightHandSideBase() + : dynamicalViscosity( 1.0 ){}; + + void setVelocity( const VelocityFieldPointer& velocity ) + { + this->velocity = velocity; + }; + + void setDynamicalViscosity( const RealType& dynamicalViscosity ) + { + this->dynamicalViscosity = dynamicalViscosity; + }; + + void setDensity( const MeshFunctionType& density ) + { + this->density = density; + }; + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->turbulentViscosity = turbulentViscosity; + }; + + protected: + + VelocityFieldPointer velocity; + + MeshFunctionPointer turbulentViscosity; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumXOperatorRightHandSide.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumXOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..262ccb54f94fc5898ae7aadef88d6c323d016ef6 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumXOperatorRightHandSide.h @@ -0,0 +1,419 @@ +/*************************************************************************** + PrandtlMomentumXRightHandSide.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 +#include +#include "PrandtlMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlMomentumXRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlMomentumXRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< 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& 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& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + return +// 1D T_11_x + 4.0 / 3.0 *( velocity_x_east - 2 * velocity_x_center + velocity_x_west + ) * hxSquareInverse + * this->dynamicalViscosity +// 1D t_11_x + + + 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse; + } + + /*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 PrandtlMomentumXRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + return +// 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 + ) * hySquareInverse + ) * this->dynamicalViscosity +// t_11_x + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ); + + } + + /*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 PrandtlMomentumXRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumX< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_u, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_x_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// 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_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 + ) * hxSquareInverse + ) * this->dynamicalViscosity +// T_31_z + + ( ( velocity_z_upEast - velocity_z_downEast - velocity_z_upWest + velocity_z_downWest + ) * hxInverse * hzInverse / 4 + + ( velocity_x_up - 2 * velocity_x_center + velocity_x_down + ) * hzSquareInverse + ) * this->dynamicalViscosity +//t_11_x + + + ( 4.0 / 3.0 * ( turbulentViscosity_east * velocity_x_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_west + ) * hxSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_east * ( velocity_y_northEast - velocity_y_southEast ) - turbulentViscosity_west * ( velocity_y_northWest - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_east * (velocity_z_upEast - velocity_z_downEast ) - turbulentViscosity_west * ( velocity_z_upWest - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + ) +// t_21_y + + ( ( turbulentViscosity_north * ( velocity_y_northEast - velocity_y_northWest ) - turbulentViscosity_south * ( velocity_y_southEast - velocity_y_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_north * velocity_x_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_x_center + turbulentViscosity_center * velocity_x_south + ) * hySquareInverse + ) +// t_31_z + + ( ( turbulentViscosity_up * ( velocity_z_upEast - velocity_z_upWest ) - turbulentViscosity_down * ( velocity_z_downEast - velocity_z_downWest ) + ) * hxInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_x_up - ( turbulentViscosity_up + turbulentViscosity_center) * velocity_x_center + turbulentViscosity_center * velocity_x_down + ) * hzSquareInverse + ); + + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumYOperatorRightHandSide.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumYOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..0c2eb95062901ac19d0982e124c6d65b82df9158 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumYOperatorRightHandSide.h @@ -0,0 +1,397 @@ +/*************************************************************************** + PrandtlMomentumYRightHandSide.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 +#include +#include "PrandtlMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlMomentumYRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlMomentumYRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< 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 PrandtlMomentumYRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 2, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 2, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 2 >& neighborEntities = entity.getNeighborEntities(); + + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + + + return +// 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 + + +// t_22_y + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + ) +// t_12_x + + ( ( turbulentViscosity_east * (velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * (velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ); + } + + /*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 PrandtlMomentumYRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumY< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_v, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_12_y + ( ( velocity_x_northEast - velocity_x_southEast - velocity_x_northWest + velocity_x_southWest + ) * hxInverse * hyInverse / 4 + + ( velocity_y_east - 2 * velocity_y_center + velocity_y_west + ) * hxSquareInverse + ) * 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_up - 2 * velocity_y_center + velocity_y_down + ) * hzSquareInverse + ) * this->dynamicalViscosity + + +// t_12_x + ( ( turbulentViscosity_east * ( velocity_x_northEast - velocity_x_southEast ) - turbulentViscosity_west * ( velocity_x_northWest - velocity_x_southWest ) + ) * hxInverse * hyInverse / 4 + + ( turbulentViscosity_east * velocity_y_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_west + ) * hxSquareInverse + ) +// t_22_y + + ( 4.0 / 3.0 * ( turbulentViscosity_north * velocity_y_north - ( turbulentViscosity_north + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_south * velocity_y_south + ) * hySquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_x_northEast - velocity_x_northWest ) - turbulentViscosity_south * ( velocity_x_southEast - velocity_x_southWest) + ) * hxInverse * hyInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_north * ( velocity_z_upNorth - velocity_z_downNorth ) - turbulentViscosity_south * ( velocity_z_upSouth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + ) +// t_32_z + + ( ( turbulentViscosity_up * ( velocity_z_upNorth - velocity_z_upSouth ) - turbulentViscosity_down * ( velocity_z_downNorth - velocity_z_downSouth ) + ) * hyInverse * hzInverse / 4 + + ( turbulentViscosity_up * velocity_y_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_y_center + turbulentViscosity_center * velocity_y_down + ) * hzSquareInverse + ); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumZOperatorRightHandSide.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumZOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..2504a870d737aa891122af97432cbed1ded26ee0 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlMomentumZOperatorRightHandSide.h @@ -0,0 +1,333 @@ +/*************************************************************************** + PrandtlMomentumZRightHandSide.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 +#include +#include "PrandtlMomentumBaseOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlMomentumZRightHandSide +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class PrandtlMomentumZRightHandSide< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + + typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< 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 PrandtlMomentumZRightHandSide< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< 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 PrandtlMomentumZRightHandSide< Meshes::Grid< 3,MeshReal, Device, MeshIndex >, Real, Index > + : public PrandtlMomentumRightHandSideBase< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + public: + typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef PrandtlMomentumRightHandSideBase< MeshType, Real, Index > BaseType; + + using typename BaseType::RealType; + using typename BaseType::IndexType; + using typename BaseType::DeviceType; + using typename BaseType::CoordinatesType; + using typename BaseType::MeshFunctionType; + using typename BaseType::MeshFunctionPointer; + using typename BaseType::VelocityFieldType; + using typename BaseType::VelocityFieldPointer; + using BaseType::Dimensions; + + static String getType() + { + return String( "LaxFridrichsMomentumZ< " ) + + MeshType::getType() + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< Index >() + " >"; + } + + template< typename MeshFunction, typename MeshEntity > + __cuda_callable__ + Real operator()( const MeshFunction& rho_w, + const MeshEntity& entity, + const RealType& time = 0.0 ) const + { + static_assert( MeshEntity::getEntityDimension() == 3, "Wrong mesh entity dimensions." ); + static_assert( MeshFunction::getEntitiesDimension() == 3, "Wrong preimage function" ); + const typename MeshEntity::template NeighborEntities< 3 >& neighborEntities = entity.getNeighborEntities(); + + const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >(); + const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >(); + const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >(); + + const IndexType& center = entity.getIndex(); + const IndexType& east = neighborEntities.template getEntityIndex< 1, 0, 0 >(); + const IndexType& west = neighborEntities.template getEntityIndex< -1, 0, 0 >(); + const IndexType& north = neighborEntities.template getEntityIndex< 0, 1, 0 >(); + const IndexType& south = neighborEntities.template getEntityIndex< 0, -1, 0 >(); + const IndexType& up = neighborEntities.template getEntityIndex< 0, 0, 1 >(); + const IndexType& down = neighborEntities.template getEntityIndex< 0, 0, -1 >(); + const IndexType& northWest = neighborEntities.template getEntityIndex< -1, 1, 0 >(); + const IndexType& northEast = neighborEntities.template getEntityIndex< 1, 1, 0 >(); + const IndexType& southWest = neighborEntities.template getEntityIndex< -1, -1, 0 >(); + const IndexType& southEast = neighborEntities.template getEntityIndex< 1, -1, 0 >(); + const IndexType& upWest = neighborEntities.template getEntityIndex< -1, 0, 1 >(); + const IndexType& upEast = neighborEntities.template getEntityIndex< 1, 0, 1 >(); + const IndexType& upSouth = neighborEntities.template getEntityIndex< 0, -1, 1 >(); + const IndexType& upNorth = neighborEntities.template getEntityIndex< 0, 1, 1 >(); + const IndexType& downWest = neighborEntities.template getEntityIndex< -1, 0, -1 >(); + const IndexType& downEast = neighborEntities.template getEntityIndex< 1, 0, -1 >(); + const IndexType& downSouth = neighborEntities.template getEntityIndex< 0, -1, -1 >(); + const IndexType& downNorth = neighborEntities.template getEntityIndex< 0, 1, -1 >(); + + const RealType& turbulentViscosity_center = this->turbulentViscosity.template getData< DeviceType >()[ center ]; + const RealType& turbulentViscosity_west = this->turbulentViscosity.template getData< DeviceType >()[ west ]; + const RealType& turbulentViscosity_east = this->turbulentViscosity.template getData< DeviceType >()[ east ]; + const RealType& turbulentViscosity_north = this->turbulentViscosity.template getData< DeviceType >()[ north ]; + const RealType& turbulentViscosity_south = this->turbulentViscosity.template getData< DeviceType >()[ south ]; + const RealType& turbulentViscosity_up = this->turbulentViscosity.template getData< DeviceType >()[ up ]; + const RealType& turbulentViscosity_down = this->turbulentViscosity.template getData< DeviceType >()[ down ]; + + const RealType& velocity_x_east = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_x_west = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_x_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_x_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_x_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_x_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_x_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_x_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_x_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ downEast ]; + + const RealType& velocity_y_north = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_y_south = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_northWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northWest ]; + const RealType& velocity_y_northEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ northEast ]; + const RealType& velocity_y_southWest = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southWest ]; + const RealType& velocity_y_southEast = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ southEast ]; + const RealType& velocity_y_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_y_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_y_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_y_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ downSouth ]; + + const RealType& velocity_z_up = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_z_down = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ down ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_z_upWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upWest ]; + const RealType& velocity_z_upEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upEast ]; + const RealType& velocity_z_upNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upNorth ]; + const RealType& velocity_z_upSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ upSouth ]; + const RealType& velocity_z_downWest = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downWest ]; + const RealType& velocity_z_downEast = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downEast ]; + const RealType& velocity_z_downNorth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downNorth ]; + const RealType& velocity_z_downSouth = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ downSouth ]; + + return +// T_13_x + ( ( velocity_z_east - 2 * velocity_z_center + velocity_z_west ) + * hxSquareInverse + + ( velocity_x_upEast - velocity_x_downEast - velocity_x_upWest + velocity_x_downWest ) + * hxInverse * hzInverse / 4 + ) + * this->dynamicalViscosity +// T_23_y + + ( ( velocity_y_upNorth - velocity_y_downNorth - velocity_y_upSouth + velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + + ( velocity_z_north - 2 * velocity_z_center + velocity_z_south ) + * hySquareInverse + ) + * 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 +// t_13_x + + ( ( turbulentViscosity_east * velocity_z_east - ( turbulentViscosity_east + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_west ) + * hxSquareInverse + + ( turbulentViscosity_east * ( velocity_x_upEast - velocity_x_downEast ) - turbulentViscosity_west * ( velocity_x_upWest - velocity_x_downWest ) ) + * hxInverse * hzInverse / 4 + ) +// t_23_y + + ( ( turbulentViscosity_north * ( velocity_y_upNorth - velocity_y_downNorth ) - turbulentViscosity_south * ( velocity_y_upSouth - velocity_y_downSouth ) ) + * hyInverse * hzInverse / 4 + + ( turbulentViscosity_north * velocity_z_north - (turbulentViscosity_north + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_south ) + * hySquareInverse + ) +// t_33_z + + ( 4.0 / 3.0 * ( turbulentViscosity_up * velocity_z_up - ( turbulentViscosity_up + turbulentViscosity_center ) * velocity_z_center + turbulentViscosity_center * velocity_z_down ) + * hzSquareInverse + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_y_upNorth - turbulentViscosity_down * velocity_y_downNorth - turbulentViscosity_up * velocity_y_upSouth + turbulentViscosity_down * velocity_y_downSouth ) + * hyInverse * hzInverse / 4 + - 2.0 / 3.0 * ( turbulentViscosity_up * velocity_x_upEast - turbulentViscosity_down * velocity_x_downEast - turbulentViscosity_up * velocity_x_upWest + turbulentViscosity_down * velocity_x_downWest ) + * hxInverse * hzInverse / 4 + ); + } + + /*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/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h new file mode 100644 index 0000000000000000000000000000000000000000..9df47e1e8a43c6c7c21f4985f6e0242286a10436 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h @@ -0,0 +1,130 @@ +/*************************************************************************** + PrandtlOpratorRightHandSide.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 +#include +#include + +#include "PrandtlContinuityOperatorRightHandSide.h" +#include "PrandtlEnergyOperatorRightHandSide.h" +#include "PrandtlMomentumXOperatorRightHandSide.h" +#include "PrandtlMomentumYOperatorRightHandSide.h" +#include "PrandtlMomentumZOperatorRightHandSide.h" + +namespace TNL { + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class PrandtlOperatorRightHandSide +{ + 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 PrandtlContinuityRightHandSide< Mesh, Real, Index > ContinuityOperatorRightHandSideType; + typedef PrandtlMomentumXRightHandSide< Mesh, Real, Index > MomentumXOperatorRightHandSideType; + typedef PrandtlMomentumYRightHandSide< Mesh, Real, Index > MomentumYOperatorRightHandSideType; + typedef PrandtlMomentumZRightHandSide< Mesh, Real, Index > MomentumZOperatorRightHandSideType; + typedef PrandtlEnergyRightHandSide< Mesh, Real, Index > EnergyOperatorRightHandSideType; + + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef Pointers::SharedPointer< VectorFieldType > VectorFieldPointer; + typedef Pointers::SharedPointer< MeshType > MeshPointer; + + typedef Pointers::SharedPointer< ContinuityOperatorRightHandSideType > ContinuityOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumXOperatorRightHandSideType > MomentumXOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumYOperatorRightHandSideType > MomentumYOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< MomentumZOperatorRightHandSideType > MomentumZOperatorRightHandSidePointer; + typedef Pointers::SharedPointer< EnergyOperatorRightHandSideType > EnergyOperatorRightHandSidePointer; + + 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 ); + } + + PrandtlOperatorRightHandSide() + : dynamicalViscosity( 1.0 ) {} + + bool setup( const MeshPointer& meshPointer, + const Config::ParameterContainer& parameters, + const String& prefix = "" ) + { + this->dynamicalViscosity = parameters.getParameter< double >( prefix + "dynamical-viscosity" ); + this->momentumXOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumYOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->momentumZOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + this->energyOperatorRightHandSidePointer->setDynamicalViscosity( dynamicalViscosity ); + return true; + } + + void setVelocity( const VectorFieldPointer& velocity ) + { + this->continuityOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumXOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumYOperatorRightHandSidePointer->setVelocity( velocity ); + this->momentumZOperatorRightHandSidePointer->setVelocity( velocity ); + this->energyOperatorRightHandSidePointer->setVelocity( velocity ); + } + + void setTurbulentViscosity( const MeshFunctionPointer& turbulentViscosity ) + { + this->momentumXOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumYOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->momentumZOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + this->energyOperatorRightHandSidePointer->setTurbulentViscosity( turbulentViscosity ); + } + + const ContinuityOperatorRightHandSidePointer& getContinuityOperatorRightHandSide() const + { + return this->continuityOperatorRightHandSidePointer; + } + + const MomentumXOperatorRightHandSidePointer& getMomentumXOperatorRightHandSide() const + { + return this->momentumXOperatorRightHandSidePointer; + } + + const MomentumYOperatorRightHandSidePointer& getMomentumYOperatorRightHandSide() const + { + return this->momentumYOperatorRightHandSidePointer; + } + + const MomentumZOperatorRightHandSidePointer& getMomentumZOperatorRightHandSide() const + { + return this->momentumZOperatorRightHandSidePointer; + } + + const EnergyOperatorRightHandSidePointer& getEnergyOperatorRightHandSide() const + { + return this->energyOperatorRightHandSidePointer; + } + + protected: + + ContinuityOperatorRightHandSidePointer continuityOperatorPointer; + MomentumXOperatorRightHandSidePointer momentumXOperatorPointer; + MomentumYOperatorRightHandSidePointer momentumYOperatorPointer; + MomentumZOperatorRightHandSidePointer momentumZOperatorPointer; + EnergyOperatorRightHandSidePointer energyOperatorPointer; + + RealType dynamicalViscosity; +}; + +} //namespace TNL diff --git a/src/Examples/turbulent-flows/zero-equation-model/Getter.h b/src/Examples/turbulent-flows/zero-equation-model/Getter.h new file mode 100644 index 0000000000000000000000000000000000000000..a9a87847880ce349cc21ff907e75070980ed438a --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/Getter.h @@ -0,0 +1,306 @@ +/*************************************************************************** + 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 +#include +#include +#include +#include "CompressibleConservativeVariables.h" + +namespace TNL { + template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class TurbulentViscosityGetter +{ +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class TurbulentViscosityGetter< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index > +{ + 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 Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + class Getter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + Getter( MeshFunctionPointer density, + VelocityFieldPointer velocity, + const RealType& mixingLength ) + : density( density ), velocity( velocity ), mixingLength( mixingLength ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + return 0; + } + + protected: + const MeshFunctionPointer density; + + const VelocityFieldPointer velocity; + + const RealType mixingLength; + }; + + void getTurbulentViscocsity( const ConservativeVariablesPointer& conservativeVariables, + VelocityFieldPointer& velocity, + const RealType& mixingLength, + MeshFunctionPointer& turbulentViscosity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, Getter > evaluator; + Pointers::SharedPointer< Getter, DeviceType > turbulentViscosityGetter( conservativeVariables->getDensity(), + velocity, + mixingLength ); + evaluator.evaluate( turbulentViscosity, turbulentViscosityGetter ); + } +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class TurbulentViscosityGetter< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index > +{ + 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 Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + class Getter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + Getter( MeshFunctionPointer density, + VelocityFieldPointer velocity, + const RealType& mixingLength ) + : density( density ), velocity( velocity ), mixingLength( mixingLength ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + const typename EntityType::template NeighborEntities< 2 >& neighborEntities = meshEntity.getNeighborEntities(); + const RealType rho = this->density.template getData< DeviceType >()( meshEntity ); + const RealType& hxInverse = meshEntity.getMesh().template getSpaceStepsProducts< -1, 0 >(); + const RealType& hyInverse = meshEntity.getMesh().template getSpaceStepsProducts< 0, -1 >(); + if( ! ( ( ( meshEntity.getCoordinates().x() == 0 ) || ( meshEntity.getCoordinates().x() == meshEntity.getMesh().getDimensions().x() - 1 ) ) + ||( ( meshEntity.getCoordinates().y() == 0 ) || ( meshEntity.getCoordinates().y() == meshEntity.getMesh().getDimensions().y() - 1 ) ) ) ) + { + + const IndexType& center = meshEntity.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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + + return rho * this->mixingLength * this->mixingLength * + (-1.0) * + ( ( velocity_y_east - velocity_y_west ) * hxInverse * 0.5 + - ( velocity_x_north - velocity_x_south ) * hyInverse * 0.5 + ) + * + ( ( velocity_x_north - velocity_x_south ) * hyInverse * 0.5 + - ( velocity_y_east - velocity_y_west ) * hxInverse * 0.5 + ); + } + else return 0; + } + + protected: + const MeshFunctionPointer density; + + const VelocityFieldPointer velocity; + + const RealType mixingLength; + }; + + void getTurbulentViscocsity( const ConservativeVariablesPointer& conservativeVariables, + VelocityFieldPointer& velocity, + const RealType& mixingLength, + MeshFunctionPointer& turbulentViscosity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, Getter > evaluator; + Pointers::SharedPointer< Getter, DeviceType > turbulentViscosityGetter( conservativeVariables->getDensity(), + velocity, + mixingLength ); + evaluator.evaluate( turbulentViscosity, turbulentViscosityGetter ); + } +}; + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class TurbulentViscosityGetter< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index > +{ + 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 Functions::MeshFunction< MeshType > MeshFunctionType; + typedef Pointers::SharedPointer< MeshFunctionType > MeshFunctionPointer; + typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType; + typedef Pointers::SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer; + typedef Functions::VectorField< Dimensions, MeshFunctionType > VelocityFieldType; + typedef Pointers::SharedPointer< VelocityFieldType > VelocityFieldPointer; + + class Getter : public Functions::Domain< Dimensions, Functions::MeshDomain > + { + public: + typedef typename MeshType::RealType RealType; + + Getter( MeshFunctionPointer density, + VelocityFieldPointer velocity, + const RealType& mixingLength ) + : density( density ), velocity( velocity ), mixingLength( mixingLength ) {} + + template< typename EntityType > + __cuda_callable__ + RealType operator()( const EntityType& meshEntity, + const RealType& time = 0.0 ) const + { + const typename EntityType::template NeighborEntities< 3 >& neighborEntities = meshEntity.getNeighborEntities(); + const RealType rho = this->density.template getData< DeviceType >()( meshEntity ); + + const RealType& hxInverse = meshEntity.getMesh().template getSpaceStepsProducts< -1, 0, 0 >(); + const RealType& hyInverse = meshEntity.getMesh().template getSpaceStepsProducts< 0, -1, 0 >(); + const RealType& hzInverse = meshEntity.getMesh().template getSpaceStepsProducts< 0, 0, -1 >(); + + if( ! ( ( ( meshEntity.getCoordinates().x() == 0 ) || ( meshEntity.getCoordinates().x() == meshEntity.getMesh().getDimensions().x() - 1 ) ) + ||( ( meshEntity.getCoordinates().y() == 0 ) || ( meshEntity.getCoordinates().y() == meshEntity.getMesh().getDimensions().y() - 1 ) ) + ||( ( meshEntity.getCoordinates().z() == 0 ) || ( meshEntity.getCoordinates().z() == meshEntity.getMesh().getDimensions().z() - 1 ) ) ) ) + { + const IndexType& center = meshEntity.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_north = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_x_south = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_x_center = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_x_up = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_x_down = this->velocity.template getData< TNL::Devices::Host >()[ 0 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_y_east = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_y_west = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_y_center = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ center ]; + const RealType& velocity_y_up = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ up ]; + const RealType& velocity_y_down = this->velocity.template getData< TNL::Devices::Host >()[ 1 ].template getData< DeviceType >()[ down ]; + + const RealType& velocity_z_north = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ north ]; + const RealType& velocity_z_south = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ south ]; + const RealType& velocity_z_east = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ east ]; + const RealType& velocity_z_west = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ west ]; + const RealType& velocity_z_center = this->velocity.template getData< TNL::Devices::Host >()[ 2 ].template getData< DeviceType >()[ center ]; + + return rho * this->mixingLength * this->mixingLength * + ( + ( ( velocity_y_east - velocity_y_west ) * hxInverse * 0.5 + - ( velocity_x_north - velocity_x_south ) * hyInverse * 0.5 + ) + * + ( ( velocity_z_north - velocity_z_south ) * hyInverse * 0.5 + - ( velocity_y_up - velocity_y_down ) * hzInverse * 0.5 + ) + * + ( ( velocity_x_up - velocity_x_down ) * hzInverse * 0.5 + - ( velocity_z_east - velocity_z_west ) * hxInverse * 0.5 + ) + + + ( ( velocity_z_east - velocity_z_west ) * hxInverse * 0.5 + - ( velocity_x_up - velocity_x_down ) * hzInverse * 0.5 + ) + * + ( ( velocity_x_north - velocity_x_south ) * hyInverse * 0.5 + - ( velocity_y_east - velocity_y_west ) * hxInverse * 0.5 + ) + * + ( ( velocity_y_up - velocity_y_down ) * hzInverse * 0.5 + - ( velocity_z_north - velocity_z_south ) *hyInverse * 0.5 + ) + ); + } + else return 0; + } + + protected: + const MeshFunctionPointer density; + + const VelocityFieldPointer velocity; + + const RealType mixingLength; + }; + + void getTurbulentViscocsity( const ConservativeVariablesPointer& conservativeVariables, + VelocityFieldPointer& velocity, + const RealType& mixingLength, + MeshFunctionPointer& turbulentViscosity ) + { + Functions::MeshFunctionEvaluator< MeshFunctionType, Getter > evaluator; + Pointers::SharedPointer< Getter, DeviceType > turbulentViscosityGetter( conservativeVariables->getDensity(), + velocity, + mixingLength ); + evaluator.evaluate( turbulentViscosity, turbulentViscosityGetter ); + } +}; + +} //namespace TNL diff --git a/src/Examples/flow-sw/PhysicalVariablesGetter.h b/src/Examples/turbulent-flows/zero-equation-model/PhysicalVariablesGetter.h similarity index 97% rename from src/Examples/flow-sw/PhysicalVariablesGetter.h rename to src/Examples/turbulent-flows/zero-equation-model/PhysicalVariablesGetter.h index d7eeb7618657c34485b3e4842ea04e12d3ee725c..957c9219c5ed5aaa2808e825979c9fc1fa03d66a 100644 --- a/src/Examples/flow-sw/PhysicalVariablesGetter.h +++ b/src/Examples/turbulent-flows/zero-equation-model/PhysicalVariablesGetter.h @@ -79,7 +79,7 @@ class PhysicalVariablesGetter { const RealType e = energy.template getData< DeviceType >()( meshEntity ); const RealType rho = density.template getData< DeviceType >()( meshEntity ); - const RealType momentumNorm = lpNorm( momentum.template getData< DeviceType >().getVector( meshEntity ), 2.0 ); + const RealType momentumNorm = momentum.template getData< DeviceType >().getVector( meshEntity ).lpNorm( 2.0 ); if( rho == 0.0 ) return 0; else @@ -115,8 +115,7 @@ class PhysicalVariablesGetter conservativeVariables->getMomentum(), gamma ); evaluator.evaluate( pressure, pressureGetter ); - } - + } }; } //namespace TNL diff --git a/src/Examples/flow-vl/RiemannProblemInitialCondition.h b/src/Examples/turbulent-flows/zero-equation-model/RiemannProblemInitialCondition.h similarity index 99% rename from src/Examples/flow-vl/RiemannProblemInitialCondition.h rename to src/Examples/turbulent-flows/zero-equation-model/RiemannProblemInitialCondition.h index dfde32625973ef72161ebed80d633a089666049f..ff66ff8b7a69905be758ecb43693192c2c5a0045 100644 --- a/src/Examples/flow-vl/RiemannProblemInitialCondition.h +++ b/src/Examples/turbulent-flows/zero-equation-model/RiemannProblemInitialCondition.h @@ -919,7 +919,6 @@ class RiemannProblemInitialCondition 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, @@ -990,11 +989,11 @@ class RiemannProblemInitialCondition 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, + 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, - 0.1, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ + 1.0, 0.0, 0.0 //double preSEDVelocityX, double preSEDVelocityY,double preSEDVelocityZ ); if(initial == prefix + "1D_Noh") predefinedInitialCondition( 1.4, 0.5, 0.0, 0.0, // double preGamma, double preDiscX, double preDiscY, double preDiscZ, @@ -1258,9 +1257,6 @@ class RiemannProblemInitialCondition this->SEDPressure = preSEDPressure; this->SEDEnergy = Energy( SEDDensity, SEDPressure, gamma, SEDVelocity); this->SEDMomentum = SEDVelocity * SEDDensity; - - std::cout << this->SEDEnergy; - std::cout << this->SWDEnergy; } @@ -1291,7 +1287,7 @@ class RiemannProblemInitialCondition 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 ))); + case 3: energy = (Pressure / (gamma -1.0) + 0.5 * Density * (std::pow(Velocity[ 0 ], 2 ) + std::pow(Velocity[ 1 ], 2 ) + std::pow(Velocity[ 2 ], 2 ))); break; // druhou mocninu ps8t jako sou4in } return energy; @@ -1342,7 +1338,7 @@ class RiemannProblemInitialCondition typedef Functions::Analytic::VectorNorm< Dimensions, RealType > VectorNormType; typedef Operators::Analytic::Sign< Dimensions, RealType > SignType; typedef Functions::OperatorFunction< SignType, VectorNormType > InitialConditionType; - typedef Pointers::SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; + typedef SharedPointer< InitialConditionType, DeviceType > InitialConditionPointer; InitialConditionPointer initialCondition; initialCondition->getFunction().setCenter( center ); diff --git a/src/Examples/turbulent-flows/zero-equation-model/flowsBuildConfigTag.h b/src/Examples/turbulent-flows/zero-equation-model/flowsBuildConfigTag.h new file mode 100644 index 0000000000000000000000000000000000000000..c40b793b9e237d0ad756a66c57088373cad3e41b --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/flowsBuildConfigTag.h @@ -0,0 +1,72 @@ +#ifndef FLOWSBUILDCONFIGTAG_H_ +#define FLOWSBUILDCONFIGTAG_H_ + +#include +#include + +namespace TNL { + +class flowsBuildConfigTag{}; + +namespace Solvers { + +/**** + * Turn off support for float and long double. + */ +template<> struct ConfigTagReal< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct ConfigTagReal< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct ConfigTagIndex< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct ConfigTagIndex< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +//template< int Dimension > struct ConfigTagDimension< flowsBuildConfigTag, 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< flowsBuildConfigTag, Meshes::Grid< Dimension, Real, Device, Index > > + { enum { enabled = ConfigTagDimension< flowsBuildConfigTag, Dimension >::enabled && + ConfigTagReal< flowsBuildConfigTag, Real >::enabled && + ConfigTagDevice< flowsBuildConfigTag, Device >::enabled && + ConfigTagIndex< flowsBuildConfigTag, Index >::enabled }; }; +*/ +/**** + * Please, chose your preferred time discretisation here. + */ +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ExplicitTimeDiscretisationTag >{ enum { enabled = true }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, SemiImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; +template<> struct ConfigTagTimeDiscretisation< flowsBuildConfigTag, ImplicitTimeDiscretisationTag >{ enum { enabled = false }; }; + +/**** + * Only the Runge-Kutta-Merson solver is enabled by default. + */ +template<> struct ConfigTagExplicitSolver< flowsBuildConfigTag, ExplicitEulerSolverTag >{ enum { enabled = true }; }; + +} // namespace Solvers + +namespace Meshes { +namespace BuildConfigTags { + +template< int Dimensions > struct GridDimensionTag< flowsBuildConfigTag, Dimensions >{ enum { enabled = true }; }; + +/**** + * Turn off support for float and long double. + */ +template<> struct GridRealTag< flowsBuildConfigTag, float > { enum { enabled = false }; }; +template<> struct GridRealTag< flowsBuildConfigTag, long double > { enum { enabled = false }; }; + +/**** + * Turn off support for short int and long int indexing. + */ +template<> struct GridIndexTag< flowsBuildConfigTag, short int >{ enum { enabled = false }; }; +template<> struct GridIndexTag< flowsBuildConfigTag, long int >{ enum { enabled = false }; }; + +} // namespace BuildConfigTags +} // namespace Meshes +} // namespace TNL + +#endif /* FLOWSBUILDCONFIGTAG_H_ */ diff --git a/src/Examples/turbulent-flows/zero-equation-model/flowsRhs.h b/src/Examples/turbulent-flows/zero-equation-model/flowsRhs.h new file mode 100644 index 0000000000000000000000000000000000000000..e0b8c7fac887f2b8ea588020ede105d9c8950888 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/flowsRhs.h @@ -0,0 +1,35 @@ +#ifndef FLOWSRHS_H_ +#define FLOWSRHS_H_ + +#include + +namespace TNL { + +template< typename Mesh, typename Real >class flowsRhs + : 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 /* FLOWSRHS_H_ */ diff --git a/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model new file mode 100644 index 0000000000000000000000000000000000000000..cd0c1bbb1426405814d32e2e1f3222e79bb11c8d --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model @@ -0,0 +1,40 @@ +#!/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-euler-navier-stokes + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --differential-operator Steger-Warming \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-AUSM-plus b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-AUSM-plus new file mode 100644 index 0000000000000000000000000000000000000000..faaad26b48f1fbea1002c066b6bfce61e323b7e7 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-AUSM-plus @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Ausm-Plus + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Lax-Friedrichs b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Lax-Friedrichs new file mode 100644 index 0000000000000000000000000000000000000000..5f7bfbdc6d6e7ebe6dd69663eeea28a5c6dc770f --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Lax-Friedrichs @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Lax-Friedrichs + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Steger-Warming b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Steger-Warming new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Steger-Warming @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Van-Leer b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Van-Leer new file mode 100644 index 0000000000000000000000000000000000000000..1c3b5ba6587a4f8959c2549b3a22507c013d9955 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/run-zero-equation-turbulence-model-Van-Leer @@ -0,0 +1,39 @@ +#!/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-navier-stokes-Steger-Warming + --initial-condition riemann-problem \ + --time-discretisation explicit \ + --boundary-conditions-type cavity \ + --boundary-conditions-constant 0 \ + --operator-right-hand-side Navier-Stokes \ + --discrete-solver euler \ + --time-step 2e-6 \ + --snapshot-period 2e-4 \ + --convergence-residue 0.0 \ + --final-time 2e-2 \ + --initial none \ + --speed-increment 0.05 \ + --inviscid-operators-dynamical-viscosity 1.0 \ + --SED-pressure 10000 \ + --SWD-pressure 10000 \ + --NED-pressure 10000 \ + --NWD-pressure 10000 \ + --SED-velocity-0 0 \ + --SWD-velocity-0 0 \ + --NED-velocity-0 0 \ + --NWD-velocity-0 0 \ + --SED-velocity-1 0 \ + --SWD-velocity-1 0 \ + --NED-velocity-1 0 \ + --NWD-velocity-1 0 \ + --cavity-speed 2.0 + +tnl-view --mesh mesh.tnl --input-files *tnl diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.cpp b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..338a9f059000d744aef88c70254dae0f4779bddb --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.cpp @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.cu b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.cu new file mode 100644 index 0000000000000000000000000000000000000000..338a9f059000d744aef88c70254dae0f4779bddb --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.cu @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.h b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.h new file mode 100644 index 0000000000000000000000000000000000000000..aaf4f729b1a5e9941e597fa38249905a6f8408ff --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModel.h @@ -0,0 +1,276 @@ +#include +#include +#include +#include +#include +#include "zeroEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h" +#include "DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h" +#include "DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h" +#include "DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 zeroEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "differential-operator", "Choose the differential operator.", "Lax-Friedrichs"); + config.addEntryEnum< String >( "Lax-Friedrichs" ); + config.addEntryEnum< String >( "Steger-Warming" ); + config.addEntryEnum< String >( "VanLeer" ); + config.addEntryEnum< String >( "AUSMPlus" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class zeroEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + String differentialOperatorType = parameters.getParameter< String >( "differential-operator"); + if( differentialOperatorType == "Lax-Friedrichs" ) + { + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "Steger-Warming" ) + { + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "VanLeer" ) + { + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + if( differentialOperatorType == "AUSMPlus" ) + { + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + } + + + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< zeroEquationTurbulenceModelSetter, zeroEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.cpp b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5863b3135dcb32eb9f313f4eafd97193b6dab111 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.cpp @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.cu b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.cu new file mode 100644 index 0000000000000000000000000000000000000000..5863b3135dcb32eb9f313f4eafd97193b6dab111 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.cu @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModelAUSMPlus.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.h b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.h new file mode 100644 index 0000000000000000000000000000000000000000..6fd07ef64b04f744c87f97f3e3015f9f202f4ff3 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelAUSMPlus.h @@ -0,0 +1,139 @@ +//#include +#include +#include +#include +#include +#include +#include "zeroEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Navier-Stokes/AUSM+/AUSMPlus.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 zeroEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "mixing-length", "Value of characteristic mixing length", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + AUSMPlus< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class zeroEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef AUSMPlus< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< zeroEquationTurbulenceModelSetter, zeroEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.cpp b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4104390fee6dda9252ce540a4001dcebd6721a60 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.cpp @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.cu b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.cu new file mode 100644 index 0000000000000000000000000000000000000000..4104390fee6dda9252ce540a4001dcebd6721a60 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.cu @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModelLaxFriedrichs.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.h b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.h new file mode 100644 index 0000000000000000000000000000000000000000..8f86274c7d195a0e07fe273448652f274c812f77 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelLaxFriedrichs.h @@ -0,0 +1,139 @@ +//#include +#include +#include +#include +#include +#include +#include "zeroEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Navier-Stokes/Lax-Friedrichs/LaxFridrichs.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 zeroEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "mixing-length", "Value of characteristic mixing length", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + LaxFridrichs< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class zeroEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef LaxFridrichs< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< zeroEquationTurbulenceModelSetter, zeroEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/flow-sw/navierStokesProblem.h b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelProblem.h similarity index 69% rename from src/Examples/flow-sw/navierStokesProblem.h rename to src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelProblem.h index 0252a5c46dc392566cde6ad8d454d341d8331b05..7acc686bc9801a8c4bd83378852dd463fa3bbaba 100644 --- a/src/Examples/flow-sw/navierStokesProblem.h +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelProblem.h @@ -1,5 +1,5 @@ /*************************************************************************** - navierStokesProblem.h - description + zeroEquationTurbulenceModelProblem.h - description ------------------- begin : Feb 13, 2017 copyright : (C) 2017 by Tomas Oberhuber @@ -12,7 +12,7 @@ #include #include -#include +#include #include "CompressibleConservativeVariables.h" @@ -23,9 +23,9 @@ namespace TNL { template< typename Mesh, typename BoundaryCondition, typename RightHandSide, - typename InviscidOperators, - typename Communicator > -class navierStokesProblem: + typename Communicator, + typename InviscidOperators > +class zeroEquationTurbulenceModelProblem: public PDEProblem< Mesh, Communicator, typename InviscidOperators::RealType, @@ -38,6 +38,8 @@ class navierStokesProblem: typedef typename Mesh::DeviceType DeviceType; typedef typename InviscidOperators::IndexType IndexType; typedef PDEProblem< Mesh, Communicator, RealType, DeviceType, IndexType > BaseType; + + typedef Communicator CommunicatorType; using typename BaseType::MeshType; using typename BaseType::MeshPointer; @@ -54,9 +56,8 @@ class navierStokesProblem: typedef Pointers::SharedPointer< InviscidOperators > InviscidOperatorsPointer; typedef Pointers::SharedPointer< BoundaryCondition > BoundaryConditionPointer; typedef Pointers::SharedPointer< RightHandSide, DeviceType > RightHandSidePointer; - using CommunicatorType = Communicator; - - static String getTypeStatic(); + + static String getType(); String getPrologHeader() const; @@ -84,12 +85,10 @@ class navierStokesProblem: const RealType& tau, DofVectorPointer& _u, DofVectorPointer& _fu ); + void applyBoundaryConditions( const RealType& time, - DofVectorPointer& dofs ) - { - throw Exceptions::NotImplementedError("TODO:Implement"); - } + DofVectorPointer& dofs ); template< typename Matrix > void assemblyLinearSystem( const RealType& time, @@ -111,17 +110,31 @@ class navierStokesProblem: ConservativeVariablesPointer conservativeVariables, conservativeVariablesRHS; + + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::ContinuityOperatorType, typename BoundaryCondition::DensityBoundaryConditionsType, RightHandSide > explicitUpdaterContinuity; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumXOperatorType, typename BoundaryCondition::MomentumXBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumX; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumYOperatorType, typename BoundaryCondition::MomentumYBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumY; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::MomentumZOperatorType, typename BoundaryCondition::MomentumZBoundaryConditionsType, RightHandSide > explicitUpdaterMomentumZ; + Solvers::PDE::ExplicitUpdater< Mesh, MeshFunctionType, typename InviscidOperators::EnergyOperatorType, typename BoundaryCondition::EnergyBoundaryConditionsType, RightHandSide > explicitUpdaterEnergy; + VelocityFieldPointer velocity; MeshFunctionPointer pressure; + MeshFunctionPointer turbulentViscosity; RealType gamma; RealType speedIncrement; RealType cavitySpeed; - RealType speedIncrementUntil; + RealType speedIncrementUntil; + RealType finalSpeed; + RealType startSpeed; + RealType speedIncrementUntilHThrottle; + RealType finalSpeedHThrottle; + RealType startSpeedHThrottle; + RealType mixingLength; }; } // namespace TNL -#include "navierStokesProblem_impl.h" +#include "zeroEquationTurbulenceModelProblem_impl.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelProblem_impl.h b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..73b08d1eec1446fbf986c8f1e0cc5b5e7809a166 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelProblem_impl.h @@ -0,0 +1,515 @@ +/*************************************************************************** + zeroEquationTurbulenceModelProblem_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 +#include +#include +#include +#include +#include + +#include "RiemannProblemInitialCondition.h" +#include "CompressibleConservativeVariables.h" +#include "PhysicalVariablesGetter.h" +#include "zeroEquationTurbulenceModelProblem.h" +#include "Getter.h" + +namespace TNL { + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getType() +{ + return String( "zeroEquationTurbulenceModelProblem< " ) + Mesh :: getType() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +String +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getPrologHeader() const +{ + return String( "flow solver" ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, 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 Communicator, + typename InviscidOperators > +bool +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setup( const Config::ParameterContainer& parameters, + const String& prefix ) +{ + if( ! this->inviscidOperatorsPointer->setup( this->getMesh(), parameters, prefix + "inviscid-operators-" ) || + ! this->boundaryConditionPointer->setup( this->getMesh(), parameters, prefix + "boundary-conditions-" ) || + ! this->rightHandSidePointer->setup( parameters, prefix + "right-hand-side-" ) ) + return false; + this->gamma = parameters.getParameter< double >( "gamma" ); + this->startSpeed = parameters.getParameter< double >( "start-speed" ); + this->finalSpeed = parameters.getParameter< double >( "final-speed" ); + this->speedIncrementUntil = parameters.getParameter< RealType >( "speed-increment-until" ); + this->startSpeedHThrottle = parameters.getParameter< double >( "start-speed-h-throttle" ); + this->finalSpeedHThrottle = parameters.getParameter< double >( "final-speed-h-throttle" ); + this->speedIncrementUntilHThrottle = parameters.getParameter< RealType >( "speed-increment-until-h-throttle" ); + this->mixingLength = parameters.getParameter< RealType >( "mixing-length" ); + velocity->setMesh( this->getMesh() ); + pressure->setMesh( this->getMesh() ); + turbulentViscosity->setMesh( this->getMesh() ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setVelocity( this->velocity ); + this->inviscidOperatorsPointer->setPressure( this->pressure ); + this->inviscidOperatorsPointer->setDensity( this->conservativeVariables->getDensity() ); + this->inviscidOperatorsPointer->setGamma( this->gamma ); + this->inviscidOperatorsPointer->setTurbulentViscosity(this->turbulentViscosity); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.setDifferentialOperator( this->inviscidOperatorsPointer->getContinuityOperator() ); + this->explicitUpdaterContinuity.setBoundaryConditions( this->boundaryConditionPointer->getDensityBoundaryCondition() ); + this->explicitUpdaterContinuity.setRightHandSide( this->rightHandSidePointer ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumXOperator() ); + this->explicitUpdaterMomentumX.setBoundaryConditions( this->boundaryConditionPointer->getMomentumXBoundaryCondition() ); + this->explicitUpdaterMomentumX.setRightHandSide( this->rightHandSidePointer ); + + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumYOperator() ); + this->explicitUpdaterMomentumY.setBoundaryConditions( this->boundaryConditionPointer->getMomentumYBoundaryCondition() ); + this->explicitUpdaterMomentumY.setRightHandSide( this->rightHandSidePointer ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.setDifferentialOperator( this->inviscidOperatorsPointer->getMomentumZOperator() ); + this->explicitUpdaterMomentumZ.setBoundaryConditions( this->boundaryConditionPointer->getMomentumZBoundaryCondition() ); + this->explicitUpdaterMomentumZ.setRightHandSide( this->rightHandSidePointer ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.setDifferentialOperator( this->inviscidOperatorsPointer->getEnergyOperator() ); + this->explicitUpdaterEnergy.setBoundaryConditions( this->boundaryConditionPointer->getEnergyBoundaryCondition() ); + this->explicitUpdaterEnergy.setRightHandSide( this->rightHandSidePointer ); + + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +typename zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >::IndexType +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getDofs() const +{ + /**** + * Return number of DOFs (degrees of freedom) i.e. number + * of unknowns to be resolved by the main solver. + */ + return this->conservativeVariables->getDofs( this->getMesh() ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +bindDofs( DofVectorPointer& dofVector ) +{ + this->conservativeVariables->bind( this->getMesh(), dofVector ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setInitialCondition( const Config::ParameterContainer& parameters, + DofVectorPointer& dofs ) +{ + CompressibleConservativeVariables< MeshType > conservativeVariables; + conservativeVariables.bind( this->getMesh(), 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 Communicator, + typename InviscidOperators > + template< typename Matrix > +bool +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +setupLinearSystem( Matrix& matrix ) +{ +/* const IndexType dofs = this->getDofs(); + 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 Communicator, + typename InviscidOperators > +bool +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +makeSnapshot( const RealType& time, + const IndexType& step, + DofVectorPointer& dofs ) +{ + std::cout << std::endl << "Writing output at time " << time << " step " << step << "." << std::endl; + + this->bindDofs( 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() ) ) + this->conservativeVariables->getDensity()->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "velocity-" ); +// if( ! this->velocity->save( fileName.getFileName() ) ) + this->velocity->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "pressure-" ); +// if( ! this->pressure->save( fileName.getFileName() ) ) + this->pressure->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "energy-" ); +// if( ! this->conservativeVariables->getEnergy()->save( fileName.getFileName() ) ) + this->conservativeVariables->getEnergy()->save( fileName.getFileName() ); +// return false; + + fileName.setFileNameBase( "turbulentViscosity-" ); +// if( ! this->pressure->save( fileName.getFileName() ) ) + this->turbulentViscosity->save( fileName.getFileName() ); +// return false; + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +getExplicitUpdate( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + DofVectorPointer& _fu ) +{ + typedef typename MeshType::Cell Cell; + + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), _u ); + this->conservativeVariablesRHS->bind( this->getMesh(), _fu ); + + /**** + * Resolve the physical variables + */ + PhysicalVariablesGetter< typename MeshPointer::ObjectType > physicalVariables; + physicalVariables.getVelocity( this->conservativeVariables, this->velocity ); + physicalVariables.getPressure( this->conservativeVariables, this->gamma, this->pressure ); + TurbulentViscosityGetter< typename MeshPointer::ObjectType > turbViscosity; + turbViscosity.getTurbulentViscocsity( this->conservativeVariables, this->velocity, this->mixingLength, this->turbulentViscosity ); + + /**** + * Set-up operators + */ + + this->inviscidOperatorsPointer->setTau( tau ); + + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getDensity(), + this->conservativeVariablesRHS->getDensity() ); + +// this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, +// this->conservativeVariables->getDensity() ); + + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 0 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 0 ] ); //, fuRhoVelocityX ); + if( Dimensions > 1 ) + { + this->explicitUpdaterMomentumY.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 1 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 1 ] ); //, fuRhoVelocityX ); + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + ( *this->conservativeVariables->getMomentum() )[ 2 ], // uRhoVelocityX, + ( *this->conservativeVariablesRHS->getMomentum() )[ 2 ] ); //, fuRhoVelocityX ); + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template update< typename Mesh::Cell, Communicator >( time, tau, this->getMesh(), + this->conservativeVariables->getEnergy(), // uRhoVelocityX, + this->conservativeVariablesRHS->getEnergy() ); //, fuRhoVelocityX ); + + /*this->conservativeVariablesRHS->getDensity()->write( "density", "gnuplot" ); + this->conservativeVariablesRHS->getEnergy()->write( "energy", "gnuplot" ); + this->conservativeVariablesRHS->getMomentum()->write( "momentum", "gnuplot", 0.05 ); + getchar();*/ + +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +void +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +applyBoundaryConditions( const RealType& time, + DofVectorPointer& dofs ) +{ + /**** + * 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); + this->boundaryConditionPointer->setVerticalThrottleSpeed( startSpeed, finalSpeed, time, speedIncrementUntil ); + this->boundaryConditionPointer->setHorizontalThrottleSpeed( startSpeedHThrottle, finalSpeedHThrottle, time, speedIncrementUntilHThrottle ); + /**** + * Bind DOFs + */ + this->conservativeVariables->bind( this->getMesh(), dofs ); +// this->conservativeVariables->getDensity()->write( "density", "gnuplot" ); +// this->conservativeVariables->getEnergy()->write( "energy", "gnuplot" ); +// this->conservativeVariables->getMomentum()->write( "momentum", "gnuplot", 0.05 ); +// dofs->save("dofs.tnl"); +// getchar(); +// std::cout <<"applyBCC" << std::endl; + /**** + * Continuity equation + */ + this->explicitUpdaterContinuity.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getDensity() ); + /**** + * Momentum equations + */ + this->explicitUpdaterMomentumX.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 0 ] ); // uRhoVelocityX, + if( Dimensions > 1 ) + { + + this->explicitUpdaterMomentumY.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 1 ] ); // uRhoVelocityX, + } + + if( Dimensions > 2 ) + { + this->explicitUpdaterMomentumZ.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + ( *this->conservativeVariables->getMomentum() )[ 2 ] ); // uRhoVelocityX, + } + + /**** + * Energy equation + */ + this->explicitUpdaterEnergy.template applyBoundaryConditions< typename Mesh::Cell >( this->getMesh(), time, + this->conservativeVariables->getEnergy() ); // uRhoVelocityX, +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > + template< typename Matrix > +void +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +assemblyLinearSystem( const RealType& time, + const RealType& tau, + DofVectorPointer& _u, + Matrix& matrix, + DofVectorPointer& b ) +{ +/* LinearSystemAssembler< Mesh, + MeshFunctionType, + InviscidOperators, + BoundaryCondition, + RightHandSide, + BackwardTimeDiscretisation, + Matrix, + DofVectorType > systemAssembler; + + MeshFunction< Mesh > u( mesh, _u ); + systemAssembler.template assembly< typename Mesh::Cell >( time, + tau, + this->differentialOperator, + this->boundaryCondition, + this->rightHandSide, + u, + matrix, + b );*/ +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename Communicator, + typename InviscidOperators > +bool +zeroEquationTurbulenceModelProblem< Mesh, BoundaryCondition, RightHandSide, Communicator, InviscidOperators >:: +postIterate( const RealType& time, + const RealType& tau, + DofVectorPointer& dofs ) +{ + /* + 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/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.cpp b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da6b355f9b4a905a6a230ae75c1e88d9c65699dd --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.cpp @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModelStegerWarming.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.cu b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.cu new file mode 100644 index 0000000000000000000000000000000000000000..bce6dd559cd759d177297478162da1a1d3ca23d2 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.cu @@ -0,0 +1 @@ +#include "navierStokesStegerWarming.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.h b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.h new file mode 100644 index 0000000000000000000000000000000000000000..c6ec60a70d9aadb0fb16ef31f472eb1ad943712f --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelStegerWarming.h @@ -0,0 +1,139 @@ +//#include +#include +#include +#include +#include +#include +#include "zeroEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Navier-Stokes/Steger-Warming/StegerWarming.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 zeroEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "mixing-length", "Value of characteristic mixing length", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + StegerWarming< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class zeroEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef StegerWarming< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< zeroEquationTurbulenceModelSetter, zeroEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.cpp b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13b56c8fc6a4ee45ab66022b04d6f3cdc42250d4 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.cpp @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModelVanLeer.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.cu b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.cu new file mode 100644 index 0000000000000000000000000000000000000000..338a9f059000d744aef88c70254dae0f4779bddb --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.cu @@ -0,0 +1 @@ +#include "zeroEquationTurbulenceModel.h" diff --git a/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.h b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.h new file mode 100644 index 0000000000000000000000000000000000000000..50014a9274c308b0e050ce636a010e31ae294455 --- /dev/null +++ b/src/Examples/turbulent-flows/zero-equation-model/zeroEquationTurbulenceModelVanLeer.h @@ -0,0 +1,142 @@ +//#include +#include +#include +#include +#include +#include +#include "zeroEquationTurbulenceModelProblem.h" +#include "DifferentialOperators/Navier-Stokes/VanLeer/VanLeer.h" +#include "flowsRhs.h" +#include "flowsBuildConfigTag.h" + +#include "RiemannProblemInitialCondition.h" +#include "BoundaryConditions/Cavity/BoundaryConditionsCavity.h" +#include "BoundaryConditions/Boiler/BoundaryConditionsBoiler.h" +#include "BoundaryConditions/BoilerModel/BoundaryConditionsBoilerModel.h" +#include "BoundaryConditions/Dirichlet/BoundaryConditionsDirichlet.h" +#include "BoundaryConditions/Neumann/BoundaryConditionsNeumann.h" +#include "DifferentialOperatorsRightHandSide/PrandtlRightHandSide/PrandtlOperatorRightHandSide.h" + +using namespace TNL; + +typedef flowsBuildConfigTag 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 zeroEquationTurbulenceModelConfig +{ + 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 >( "boiler-model" ); + config.addEntryEnum< String >( "cavity" ); + config.addEntryEnum< String >( "dirichlet" ); + config.addEntryEnum< String >( "neumann" ); + config.addEntry< String >( "operator-right-hand-side", "Choose equation type.", "Euler"); + config.addEntryEnum< String >( "Euler" ); + config.addEntryEnum< String >( "Navier-Stokes" ); + 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 >( "start-speed", "This sets throttle speed at begining", 0.0 ); + config.addEntry< double >( "final-speed", "This sets speed at destined time", 0.0 ); + config.addEntry< double >( "speed-increment-until-h-throttle", "This sets time until input speed will rose for horizontal throttle", -0.1 ); + config.addEntry< double >( "start-speed-h-throttle", "This sets throttle speed at begining for horizontal throttle", 0.0 ); + config.addEntry< double >( "final-speed-h-throttle", "This sets speed at destined time for horizontal throttle", 0.0 ); + config.addEntry< double >( "cavity-speed", "This sets speed parameter of cavity", 0.0 ); + config.addEntry< double >( "mixing-length", "Value of characteristic mixing length", 1.0 ); + typedef Meshes::Grid< 3 > Mesh; + VanLeer< Mesh >::configSetup( config, "inviscid-operators-" ); + RiemannProblemInitialCondition< Mesh >::configSetup( config ); + typedef Functions::Analytic::Constant< 3, double > Constant; + BoundaryConditionsBoilerModel< Mesh, Constant >::configSetup( config, "boundary-conditions-" ); + /**** + * Add definition of your solver command line arguments. + */ + + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter, + typename CommunicatorType > +class zeroEquationTurbulenceModelSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static bool run( const Config::ParameterContainer & parameters ) + { + enum { Dimension = MeshType::getMeshDimension() }; + + typedef flowsRhs< MeshType, Real > RightHandSide; + typedef Containers::StaticVector < MeshType::getMeshDimension(), Real > Point; + typedef PrandtlOperatorRightHandSide< MeshType, Real, Index > OperatorRightHandSide; + typedef VanLeer< MeshType, OperatorRightHandSide, Real, Index > ApproximateOperator; + 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 zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler" ) + { + typedef BoundaryConditionsBoiler< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "boiler-model" ) + { + typedef BoundaryConditionsBoilerModel< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + typedef Functions::MeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef BoundaryConditionsDirichlet< MeshType, Constant, MeshType::getMeshDimension(), Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator> Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + if( boundaryConditionsType == "neumann" ) + { + typedef BoundaryConditionsNeumann< MeshType, Constant, Real, Index > BoundaryConditions; + typedef zeroEquationTurbulenceModelProblem< MeshType, BoundaryConditions, RightHandSide, CommunicatorType, ApproximateOperator > Problem; + SolverStarter solverStarter; + return solverStarter.template run< Problem >( parameters ); + } + return true;} + +}; + +int main( int argc, char* argv[] ) +{ + Solvers::Solver< zeroEquationTurbulenceModelSetter, zeroEquationTurbulenceModelConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +}; diff --git a/src/TNL/Solvers/PDE/ExplicitUpdater.h b/src/TNL/Solvers/PDE/ExplicitUpdater.h index 042c0671413533ee7313d3f26ea5a88477401b2b..9644aa916118f38c02494eef8f63a6034896aa56 100644 --- a/src/TNL/Solvers/PDE/ExplicitUpdater.h +++ b/src/TNL/Solvers/PDE/ExplicitUpdater.h @@ -157,7 +157,6 @@ class ExplicitUpdater "The boundary conditions are not correctly set-up. Use method setBoundaryCondtions() to do it." ); TNL_ASSERT_TRUE( &uPointer.template modifyData< DeviceType >(), "The function u is not correctly set-up. It was not bound probably with DOFs." ); - this->userData.time = time; this->userData.u = &uPointer.template modifyData< DeviceType >(); Meshes::Traverser< MeshType, EntityType > meshTraverser; diff --git a/src/Tools/tnl-view.h b/src/Tools/tnl-view.h index cd7cd93b9a2f0729cd8e9fd1e3628e6a5e58f6dd..64462cd792a481220e73c3bbead2bc14b9e05f02 100644 --- a/src/Tools/tnl-view.h +++ b/src/Tools/tnl-view.h @@ -417,9 +417,9 @@ struct FilesProcessor bool checkOutputFile = parameters. getParameter< bool >( "check-output-file" ); std::vector< String > inputFiles = parameters. getParameter< std::vector< String > >( "input-files" ); bool error( false ); - //#ifdef HAVE_OPENMP - //#pragma omp parallel for - //#endif + #ifdef HAVE_OPENMP + #pragma omp parallel for + #endif for( int i = 0; i < (int) inputFiles.size(); i++ ) { if( verbose )