Skip to content
Snippets Groups Projects
Commit 8ec34a6e authored by Michael Kuron's avatar Michael Kuron :mortar_board:
Browse files

Add Velocity class and getValue function to ParserUBB for API compatibility with UBB

parent ec6d666a
Branches
Tags
No related merge requests found
...@@ -73,6 +73,29 @@ public: ...@@ -73,6 +73,29 @@ public:
bool timeDependent_; bool timeDependent_;
}; // class Parser }; // class Parser
// constant velocity class is for API compatibility with UBB
class Velocity : public BoundaryConfiguration {
public:
Velocity( const Vector3< real_t > & _velocity ) : velocity_( _velocity ) {}
Velocity( const real_t _x, const real_t _y, const real_t _z ) : velocity_(_x,_y,_z) {}
inline Velocity( const Config::BlockHandle & config );
const Vector3< real_t > & velocity() const { return velocity_; }
const real_t & x() const { return velocity_[0]; }
const real_t & y() const { return velocity_[1]; }
const real_t & z() const { return velocity_[2]; }
Vector3< real_t > & velocity() { return velocity_; }
real_t & x() { return velocity_[0]; }
real_t & y() { return velocity_[1]; }
real_t & z() { return velocity_[2]; }
private:
Vector3< real_t > velocity_;
}; // class Velocity
typedef GhostLayerField< shared_ptr<Parser>, 1 > ParserField; typedef GhostLayerField< shared_ptr<Parser>, 1 > ParserField;
typedef GhostLayerField< Vector3<real_t>, 1 > VelocityField; typedef GhostLayerField< Vector3<real_t>, 1 > VelocityField;
...@@ -119,6 +142,9 @@ public: ...@@ -119,6 +142,9 @@ public:
const cell_idx_t nx, const cell_idx_t ny, const cell_idx_t nz, const flag_t /*mask*/ ); const cell_idx_t nx, const cell_idx_t ny, const cell_idx_t nz, const flag_t /*mask*/ );
#endif #endif
inline Vector3<real_t> getValue( const cell_idx_t x, cell_idx_t y, cell_idx_t z ) const;
inline Vector3<real_t> getValue( const cell_idx_t x, cell_idx_t y, cell_idx_t z, real_t t ) const;
private: private:
const FlagUID uid_; const FlagUID uid_;
...@@ -192,6 +218,14 @@ inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::Parser:: ...@@ -192,6 +218,14 @@ inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::Parser::
} }
} }
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce >
inline ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::Velocity::Velocity( const Config::BlockHandle & config )
{
velocity_[0] = ( config && config.isDefined( "x" ) ) ? config.getParameter<real_t>( "x" ) : real_c(0.0);
velocity_[1] = ( config && config.isDefined( "y" ) ) ? config.getParameter<real_t>( "y" ) : real_c(0.0);
velocity_[2] = ( config && config.isDefined( "z" ) ) ? config.getParameter<real_t>( "z" ) : real_c(0.0);
}
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce> template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce>
Vector3< real_t > ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::Parser::operator()( const Vector3< real_t > & x, const real_t t ) const Vector3< real_t > ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::Parser::operator()( const Vector3< real_t > & x, const real_t t ) const
{ {
...@@ -310,6 +344,13 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r ...@@ -310,6 +344,13 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r
WALBERLA_ASSERT_EQUAL( dynamic_cast< const Parser * >( &parser ), &parser ); WALBERLA_ASSERT_EQUAL( dynamic_cast< const Parser * >( &parser ), &parser );
WALBERLA_ASSERT_NOT_NULLPTR( parserField_ ); WALBERLA_ASSERT_NOT_NULLPTR( parserField_ );
if( auto v = dynamic_cast< const Velocity * >( &parser ) )
{
velocityField_->get( x, y, z ) = v->velocity();
parserField_->get( x, y, z ) = nullptr;
return;
}
auto & p = dynamic_cast< const Parser & >( parser ); auto & p = dynamic_cast< const Parser & >( parser );
if( p.isTimeDependent() ) if( p.isTimeDependent() )
...@@ -334,6 +375,16 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r ...@@ -334,6 +375,16 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r
WALBERLA_ASSERT_EQUAL( dynamic_cast< const Parser * >( &parser ), &parser ); WALBERLA_ASSERT_EQUAL( dynamic_cast< const Parser * >( &parser ), &parser );
WALBERLA_ASSERT_NOT_NULLPTR( parserField_ ); WALBERLA_ASSERT_NOT_NULLPTR( parserField_ );
if( auto v = dynamic_cast< const Velocity * >( &parser ) )
{
for( auto cell = parserField_->beginSliceXYZ( cells ); cell != parserField_->end(); ++cell )
{
velocityField_->get( cell.x(), cell.y(), cell.z() ) = v->velocity();
*cell = nullptr;
}
return;
}
auto & p = dynamic_cast< const Parser & >( parser ); auto & p = dynamic_cast< const Parser & >( parser );
if( p.isTimeDependent() ) if( p.isTimeDependent() )
...@@ -365,6 +416,16 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r ...@@ -365,6 +416,16 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r
WALBERLA_ASSERT_EQUAL( dynamic_cast< const Parser * >( &parser ), &parser ); WALBERLA_ASSERT_EQUAL( dynamic_cast< const Parser * >( &parser ), &parser );
WALBERLA_ASSERT_NOT_NULLPTR( parserField_ ); WALBERLA_ASSERT_NOT_NULLPTR( parserField_ );
if( auto v = dynamic_cast< const Velocity * >( &parser ) )
{
for( auto cell = begin; cell != end; ++cell )
{
velocityField_->get( cell.x(), cell.y(), cell.z() ) = v->velocity();
parserField_->get( cell->x(), cell->y(), cell->z() ) = nullptr;
}
return;
}
auto & p = dynamic_cast< const Parser & >( parser ); auto & p = dynamic_cast< const Parser & >( parser );
if( p.isTimeDependent() ) if( p.isTimeDependent() )
...@@ -400,11 +461,11 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::u ...@@ -400,11 +461,11 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::u
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce> template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce>
#ifndef NDEBUG #ifndef NDEBUG
inline void ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB::treatDirection( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const stencil::Direction dir, inline void ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB::treatDirection( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const stencil::Direction dir,
const cell_idx_t nx, const cell_idx_t ny, const cell_idx_t nz, const flag_t mask ) const cell_idx_t nx, const cell_idx_t ny, const cell_idx_t nz, const flag_t mask )
#else #else
inline void ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB::treatDirection( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const stencil::Direction dir, inline void ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB::treatDirection( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const stencil::Direction dir,
const cell_idx_t nx, const cell_idx_t ny, const cell_idx_t nz, const flag_t /*mask*/ ) const cell_idx_t nx, const cell_idx_t ny, const cell_idx_t nz, const flag_t /*mask*/ )
#endif #endif
{ {
WALBERLA_ASSERT_EQUAL( nx, x + cell_idx_c( stencil::cx[ dir ] ) ); WALBERLA_ASSERT_EQUAL( nx, x + cell_idx_c( stencil::cx[ dir ] ) );
...@@ -414,14 +475,13 @@ template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternal ...@@ -414,14 +475,13 @@ template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternal
WALBERLA_ASSERT_EQUAL( mask & this->mask_, this->mask_ ); // only true if "this->mask_" only contains one single flag, which is the case for the WALBERLA_ASSERT_EQUAL( mask & this->mask_, this->mask_ ); // only true if "this->mask_" only contains one single flag, which is the case for the
// current implementation of this boundary condition (ParserUBB) // current implementation of this boundary condition (ParserUBB)
const Vector3< real_t > pos( origin_[0] + real_c(nx) * dx_[0],
origin_[1] + real_c(ny) * dx_[1],
origin_[2] + real_c(nz) * dx_[2] );
Vector3<real_t> velocity; Vector3<real_t> velocity;
if( parserField_->get(nx,ny,nz) ) if( parserField_->get(nx,ny,nz) )
{ {
WALBERLA_ASSERT_NOT_NULLPTR( getTimeTracker(), "A TimeTracker is needed for time-dependent equations" ); WALBERLA_ASSERT_NOT_NULLPTR( getTimeTracker(), "A TimeTracker is needed for time-dependent equations" );
const Vector3< real_t > pos( origin_[0] + real_c(nx) * dx_[0],
origin_[1] + real_c(ny) * dx_[1],
origin_[2] + real_c(nz) * dx_[2] );
velocity = (*parserField_->get(nx,ny,nz))( pos, time_ ); velocity = (*parserField_->get(nx,ny,nz))( pos, time_ );
} }
else else
...@@ -455,5 +515,32 @@ template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternal ...@@ -455,5 +515,32 @@ template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternal
} }
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce >
inline Vector3<real_t> ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::getValue( const cell_idx_t x, cell_idx_t y, cell_idx_t z ) const
{
return getValue( x, y, z, time_ );
}
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce >
inline Vector3<real_t> ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::getValue( const cell_idx_t x, cell_idx_t y, cell_idx_t z, real_t t ) const
{
Vector3<real_t> velocity;
if( parserField_->get(x,y,z) )
{
WALBERLA_ASSERT_NOT_NULLPTR( getTimeTracker(), "A TimeTracker is needed for time-dependent equations" );
const Vector3< real_t > pos( origin_[0] + real_c(x) * dx_[0],
origin_[1] + real_c(y) * dx_[1],
origin_[2] + real_c(z) * dx_[2] );
velocity = (*parserField_->get(x,y,z))( pos, t );
}
else
{
velocity = velocityField_->get(x,y,z);
}
return velocity;
}
} // namespace lbm } // namespace lbm
} // namespace walberla } // namespace walberla
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment