Commit 214e70d4 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing physical variables getter.

parent f82f5102
Loading
Loading
Loading
Loading
+26 −9
Original line number Diff line number Diff line
@@ -42,24 +42,34 @@ class CompressibleConservativeVariables
        
      void setMesh( const MeshPointer& meshPointer )
      {
         this->density.setMesh( meshPointer );
         this->momentum.setMesh( meshPointer );
         this->density->setMesh( meshPointer );
         this->momentum->setMesh( meshPointer );
         //this->pressure.setMesh( meshPointer );
         this->energy.setMesh( meshPointer );
         this->energy->setMesh( meshPointer );
         this->dofs = this->density->getDofs() + 
            this->momentum->getDofs() +
            this->energy->getDofs();
      }
      
      template< typename Vector >
      void bind( const MeshPointer& meshPointer,
                 const Vector& data )
                 const Vector& data,
                 IndexType offset = 0 )
      {
         this->density.bind( meshPointer, 0 );
         IndexType offset( this->density.getDofs() );
         IndexType currentOffset( offset );
         this->density->bind( meshPointer, data, currentOffset );
         currentOffset += this->density->getDofs();
         for( IndexType i = 0; i < Dimensions; i++ )
         {
            this->momentum[ i ].bind( meshPointer, offset );
            offset += this->momentum[ i ].getDofs();
            ( *this->momentum )[ i ]->bind( meshPointer, data, currentOffset );
            currentOffset += ( *this->momentum )[ i ]->getDofs();
         }
         this->energy.bind( meshPointer, offset );
         this->energy->bind( meshPointer, data, currentOffset );
      }
      
      void IndexType getDofs() const
      {
         return this->dofs;
      }
      
      MeshFunctionPointer& getDensity()
@@ -122,8 +132,15 @@ class CompressibleConservativeVariables
         this->energy = energy;
      }
      
      void getVelocityField( VelocityFieldType& velocityField )
      {
         
      }

   protected:
      
      IndexType dofs;
      
      MeshFunctionPointer density;
      MomentumFieldPointer momentum;
      //MeshFunctionPointer pressure;
+75 −0
Original line number Diff line number Diff line
/***************************************************************************
                          CompressibleConservativeVariables.h  -  description
                             -------------------
    begin                : Feb 12, 2017
    copyright            : (C) 2017 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#include <TNL/SharedPointer.h>
#include <TNL/Functions/MeshFunction.h>
#include <TNL/Functions/VectorField.h>
#include <TNL/Functions/MeshFunctionEvaluator.h>
#include "CompressibleConservativeVariables.h"

namespace TNL {
   
template< typename Mesh >
class PhysicalVariablesGetter
{
   public:
      
      typedef Mesh MeshType;
      typedef typename MeshType::RealType RealType;
      typedef typename MeshType::DeviceType DeviceType;
      typedef typename MeshType::IndexType IndexType;
      typedef Functions::MeshFunction< MeshType > MeshFunctionType;
      typedef SharedPointer< MeshFunctionType > MeshFunctionPointer;
      typedef CompressibleConservativeVariables< MeshType > ConservativeVariablesType;
      typedef SharedPointer< ConservativeVariablesType > ConservativeVariablesPointer;
      typedef Functions::VectorField< MeshType > VelocityFieldType;
      typedef SharedPointer< VelocityFieldType > VelocityFieldPointer;
      
      static const int Dimensions = MeshType::getMeshDimensions();
      
      class VelocityGetter : public Functions::Domain< Dimensions, Functions::MeshDomain >
      {
         public:
            
            VelocityGetter( MeshFunctionPointer density, 
                            MeshFunctionPointer momentum )
            : density( density ), momentum( momentum ) {}
            
            template< typename EntityType >
            __cuda_callable__
            const RealType& operator()( const EntityType& meshEntity,
                                        const RealType& time = 0.0 ) const
            {
               return momentum.template getData< DeviceType >( meshEntity ) / 
                      density.template getData< DeviceType >( meshEntity );
            }
            
         protected:
            const MeshFunctionPointer density, momentum;
      };
      
      void getVelocity( const ConservativeVariablesType& conservativeVariables,
                        VelocityFieldPointer& velocity )
      {
         Functions::MeshFunctionEvaluator< MeshFunctionType, VelocityGetter > evaluator;
         for( int i = 0; i < Dimensions; i++ )
         {
            SharedPointer< VelocityGetter, DeviceType > velocityGetter( conservativeVariables.getDensity(),
                                                                        conservativeVariables.getMomentum()[ i ] );
            evaluator.evaluate( velocity[ i ], velocityGetter );
         }
      }
      
      
};
   
} //namespace TNL
+16 −14
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ class RiemannProblemInitialCondition
      static const int Dimensions = MeshType::getMeshDimensions();
      typedef Containers::StaticVector< Dimensions, RealType > VertexType;
      typedef Functions::MeshFunction< MeshType > MeshFunctionType;
      typedef SharedPointer< MeshFunctionType > MeshFunctionPointer;
      typedef Functions::VectorField< Dimensions, MeshType > VectorFieldType;
      
      RiemannProblemInitialCondition()
@@ -148,24 +149,25 @@ class RiemannProblemInitialCondition
         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;
         
         InitialConditionType initialCondition;
         initialCondition.getFunction().setCenter( center );
         initialCondition.getFunction().setMaxNorm( true );
         initialCondition.getFunction().setRadius( discontinuityPlacement[ 0 ] );
         discontinuityPlacement /= discontinuityPlacement[ 0 ];
         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 );
         initialCondition->getFunction().setAnisotropy( discontinuityPlacement );
         initialCondition->getFunction().setMultiplicator( -1.0 );
         
         Functions::MeshFunctionEvaluator< MeshFunctionType, InitialConditionType > evaluator;

         /****
          * Density
          */
         initialCondition.getOperator().setPositiveValue( leftDensity );
         initialCondition.getOperator().setNegativeValue( rightDensity );
         initialCondition->getOperator().setPositiveValue( leftDensity );
         initialCondition->getOperator().setNegativeValue( rightDensity );
         evaluator.evaluate( conservativeVariables.getDensity(), initialCondition );
         
         /****
@@ -173,9 +175,9 @@ class RiemannProblemInitialCondition
          */
         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 );
            initialCondition->getOperator().setPositiveValue( leftDensity * leftVelocity[ i ] );
            initialCondition->getOperator().setNegativeValue( rightDensity * rightVelocity[ i ] );
            evaluator.evaluate( ( *conservativeVariables.getMomentum() )[ i ], initialCondition );
         }
         
         /****
@@ -185,8 +187,8 @@ class RiemannProblemInitialCondition
         const RealType rightKineticEnergy = rightVelocity.lpNorm( 2.0 );
         const RealType leftEnergy = leftPressure / ( gamma + 1.0 ) + 0.2 * leftDensity * leftKineticEnergy * leftKineticEnergy;
         const RealType rightEnergy = rightPressure / ( gamma + 1.0 ) + 0.2 * rightDensity * rightKineticEnergy * rightKineticEnergy;
         initialCondition.getOperator().setPositiveValue( leftEnergy );
         initialCondition.getOperator().setNegativeValue( rightEnergy );
         initialCondition->getOperator().setPositiveValue( leftEnergy );
         initialCondition->getOperator().setNegativeValue( rightEnergy );
         evaluator.evaluate( conservativeVariables.getEnergy(), initialCondition );
      }
      
+2 −2
Original line number Diff line number Diff line
@@ -16,11 +16,11 @@ using namespace TNL;
typedef eulerBuildConfigTag BuildConfig;

/****
 * Uncoment the following (and comment the previous line) for the complete build.
 * Uncomment the following (and comment the previous line) for the complete build.
 * This will include support for all floating point precisions, all indexing types
 * and more solvers. You may then choose between them from the command line.
 * The compile time may, however, take tens of minutes or even several hours,
 * esppecially if CUDA is enabled. Use this, if you want, only for the final build,
 * especially if CUDA is enabled. Use this, if you want, only for the final build,
 * not in the development phase.
 */
//typedef tnlDefaultConfigTag BuildConfig;
+15 −0
Original line number Diff line number Diff line
/***************************************************************************
                          eulerProblem.h  -  description
                             -------------------
    begin                : Feb 13, 2017
    copyright            : (C) 2017 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#include <TNL/Problems/PDEProblem.h>
#include <TNL/Functions/MeshFunction.h>
#include "CompressibleConservativeVariables.h"


using namespace TNL::Problems;

namespace TNL {
@@ -116,6 +127,10 @@ class eulerProblem:
      
      ConservativeVariablesPointer conservativeVariables;
      
      VelocityFieldPointer velocity;
      MeshFunctionPointer pressure, energy;
      
      
      //definition
	   Containers::Vector< RealType, DeviceType, IndexType > _uRho;
	   Containers::Vector< RealType, DeviceType, IndexType > _uRhoVelocityX;
Loading