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

Use ParserUBB in ExtendedBoundaryHandlingFactory

parent 7b39b2c9
No related merge requests found
...@@ -61,12 +61,15 @@ public: ...@@ -61,12 +61,15 @@ public:
{ {
public: public:
inline Parser( const Config::BlockHandle & config ); inline Parser( const Config::BlockHandle & config );
inline Parser( std::array< std::string, 3 > & equations );
Vector3< real_t > operator()( const Vector3< real_t > & x, const real_t t ) const; Vector3< real_t > operator()( const Vector3< real_t > & x, const real_t t ) const;
Vector3< real_t > operator()( const Vector3< real_t > & x ) const; Vector3< real_t > operator()( const Vector3< real_t > & x ) const;
bool isTimeDependent() const { return timeDependent_; } bool isTimeDependent() const { return timeDependent_; }
const std::array< std::string, 3 > & equations() const { return equations_; }
private: private:
std::array< math::FunctionParserOMP, 3 > parsers_; std::array< math::FunctionParserOMP, 3 > parsers_;
std::array< std::string, 3 > equations_;
bool timeDependent_; bool timeDependent_;
}; // class Parser }; // class Parser
...@@ -96,17 +99,17 @@ public: ...@@ -96,17 +99,17 @@ public:
void afterBoundaryTreatment() const {} void afterBoundaryTreatment() const {}
template< typename Buffer_T > template< typename Buffer_T >
void packCell( Buffer_T &, const cell_idx_t, const cell_idx_t, const cell_idx_t ) const {} inline void packCell( Buffer_T &, const cell_idx_t, const cell_idx_t, const cell_idx_t ) const;
template< typename Buffer_T > template< typename Buffer_T >
void registerCell( Buffer_T &, const flag_t, const cell_idx_t, const cell_idx_t, const cell_idx_t ) {} inline void registerCell( Buffer_T &, const flag_t, const cell_idx_t, const cell_idx_t, const cell_idx_t );
inline void registerCell( const flag_t, const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const BoundaryConfiguration & parser ); inline void registerCell( const flag_t, const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const BoundaryConfiguration & parser );
inline void registerCells( const flag_t, const CellInterval & cells, const BoundaryConfiguration & parser ); inline void registerCells( const flag_t, const CellInterval & cells, const BoundaryConfiguration & parser );
template< typename CellIterator > template< typename CellIterator >
inline void registerCells( const flag_t, const CellIterator & begin, const CellIterator & end, const BoundaryConfiguration & parser ); inline void registerCells( const flag_t, const CellIterator & begin, const CellIterator & end, const BoundaryConfiguration & parser );
void unregisterCell( const flag_t, const cell_idx_t, const cell_idx_t, const cell_idx_t ) const {} inline void unregisterCell( const flag_t, const cell_idx_t, const cell_idx_t, const cell_idx_t ) const;
#ifndef NDEBUG #ifndef NDEBUG
inline void treatDirection( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const stencil::Direction dir, inline void treatDirection( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const stencil::Direction dir,
...@@ -137,26 +140,53 @@ private: ...@@ -137,26 +140,53 @@ private:
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce> template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce>
inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::Parser::Parser( const Config::BlockHandle & config ) inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::Parser::Parser( const Config::BlockHandle & config )
: parsers_(), timeDependent_( false ) : parsers_(), equations_(), timeDependent_( false )
{ {
if( !config ) if( !config )
return; return;
if( config.isDefined( "x" ) ) if( config.isDefined( "x" ) )
{ {
parsers_[0].parse( config.getParameter<std::string>( "x" ) ); equations_[0] = config.getParameter<std::string>( "x" );
parsers_[0].parse( equations_[0] );
if( parsers_[0].symbolExists( "t" ) ) if( parsers_[0].symbolExists( "t" ) )
timeDependent_ = true; timeDependent_ = true;
} }
if( config.isDefined( "y" ) ) if( config.isDefined( "y" ) )
{ {
parsers_[1].parse( config.getParameter<std::string>( "y" ) ); equations_[1] = config.getParameter<std::string>( "y" );
parsers_[1].parse( equations_[1] );
if( parsers_[1].symbolExists( "t" ) ) if( parsers_[1].symbolExists( "t" ) )
timeDependent_ = true; timeDependent_ = true;
} }
if( config.isDefined( "z" ) ) if( config.isDefined( "z" ) )
{ {
parsers_[2].parse( config.getParameter<std::string>( "z" ) ); equations_[2] = config.getParameter<std::string>( "z" );
parsers_[2].parse( equations_[2] );
if( parsers_[2].symbolExists( "t" ) )
timeDependent_ = true;
}
}
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce>
inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::Parser::Parser( std::array< std::string, 3 > & equations )
: parsers_(), equations_( equations ), timeDependent_( false )
{
if( equations_[0].length() > 0 )
{
parsers_[0].parse( equations_[0] );
if( parsers_[0].symbolExists( "t" ) )
timeDependent_ = true;
}
if( equations_[1].length() > 0 )
{
parsers_[1].parse( equations_[1] );
if( parsers_[1].symbolExists( "t" ) )
timeDependent_ = true;
}
if( equations_[2].length() > 0 )
{
parsers_[2].parse( equations_[2] );
if( parsers_[2].symbolExists( "t" ) ) if( parsers_[2].symbolExists( "t" ) )
timeDependent_ = true; timeDependent_ = true;
} }
...@@ -198,9 +228,9 @@ Vector3< real_t > ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce ...@@ -198,9 +228,9 @@ Vector3< real_t > ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce> template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce>
inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB::ParserUBB( const BoundaryUID & boundaryUID, const FlagUID & uid, PDFField * const pdfField, inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB( const BoundaryUID & boundaryUID, const FlagUID & uid, PDFField * const pdfField,
FlagField<flag_t> * const flagField, const shared_ptr< TimeTracker > & timeTracker, FlagField<flag_t> * const flagField, const shared_ptr< TimeTracker > & timeTracker,
const uint_t level, const AABB & aabb ) const uint_t level, const AABB & aabb )
: Boundary<flag_t>( boundaryUID ), uid_( uid ), pdfField_( pdfField ), timeTracker_( timeTracker ), time_( real_t(0) ), level_( level ) : Boundary<flag_t>( boundaryUID ), uid_( uid ), pdfField_( pdfField ), timeTracker_( timeTracker ), time_( real_t(0) ), level_( level )
{ {
WALBERLA_ASSERT_NOT_NULLPTR( pdfField_ ); WALBERLA_ASSERT_NOT_NULLPTR( pdfField_ );
...@@ -225,9 +255,49 @@ inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUB ...@@ -225,9 +255,49 @@ inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUB
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce >
template< typename Buffer_T >
inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::packCell( Buffer_T & buffer, const cell_idx_t x, const cell_idx_t y, const cell_idx_t z ) const
{
if( parserField_->get( x, y, z ) )
{
auto & eqs = parserField_->get( x, y, z )->equations();
buffer << true << eqs[0] << eqs[1] << eqs[2];
}
else
{
buffer << false << velocityField_->get( x, y, z );
}
}
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce >
template< typename Buffer_T >
inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::registerCell( Buffer_T & buffer, const flag_t, const cell_idx_t x, const cell_idx_t y, const cell_idx_t z )
{
bool isparser;
buffer >> isparser;
if( isparser )
{
std::array< std::string, 3> eqs;
buffer >> eqs[0] >> eqs[1] >> eqs[2];
auto p = make_shared<Parser>(eqs);
parserField_->get( x, y, z ) = p;
}
else
{
buffer >> velocityField_->get( x, y, z );
parserField_->get( x, y, z ) = nullptr;
}
}
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce> template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce>
inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB::ParserUBB( const BoundaryUID & boundaryUID, const FlagUID & uid, PDFField * const pdfField, inline ParserUBB<LatticeModel_T, flag_t, AdaptVelocityToExternalForce>::ParserUBB( const BoundaryUID & boundaryUID, const FlagUID & uid, PDFField * const pdfField,
FlagField<flag_t> * const flagField, const uint_t level, const AABB & aabb ) FlagField<flag_t> * const flagField, const uint_t level, const AABB & aabb )
: ParserUBB( boundaryUID, uid, pdfField, flagField, nullptr, level, aabb ) : ParserUBB( boundaryUID, uid, pdfField, flagField, nullptr, level, aabb )
{} {}
...@@ -320,6 +390,14 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r ...@@ -320,6 +390,14 @@ inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::r
template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternalForce >
inline void ParserUBB< LatticeModel_T, flag_t, AdaptVelocityToExternalForce >::unregisterCell( const flag_t, const cell_idx_t x, const cell_idx_t y, const cell_idx_t z ) const
{
parserField_->get(x,y,z) = nullptr;
}
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,
...@@ -343,7 +421,7 @@ template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternal ...@@ -343,7 +421,7 @@ template< typename LatticeModel_T, typename flag_t, bool AdaptVelocityToExternal
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() ); WALBERLA_ASSERT_NOT_NULLPTR( getTimeTracker(), "A TimeTracker is needed for time-dependent equations" );
velocity = (*parserField_->get(nx,ny,nz))( pos, time_ ); velocity = (*parserField_->get(nx,ny,nz))( pos, time_ );
} }
else else
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "lbm/boundary/FreeSlip.h" #include "lbm/boundary/FreeSlip.h"
#include "lbm/boundary/NoSlip.h" #include "lbm/boundary/NoSlip.h"
#include "lbm/boundary/Pressure.h" #include "lbm/boundary/Pressure.h"
#include "lbm/boundary/UBB.h" #include "lbm/boundary/ParserUBB.h"
#include "lbm/boundary/Outlet.h" #include "lbm/boundary/Outlet.h"
#include "lbm/boundary/Curved.h" #include "lbm/boundary/Curved.h"
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
typedef NoSlip< LatticeModel, flag_t > BcNoSlip; typedef NoSlip< LatticeModel, flag_t > BcNoSlip;
typedef FreeSlip< LatticeModel, FlagFieldT > BcFreeSlip; typedef FreeSlip< LatticeModel, FlagFieldT > BcFreeSlip;
typedef Pressure< LatticeModel, flag_t > BcPressure; typedef Pressure< LatticeModel, flag_t > BcPressure;
typedef UBB<LatticeModel, flag_t> BcUBB; typedef ParserUBB<LatticeModel, flag_t> BcUBB;
typedef Outlet<LatticeModel, FlagFieldT > BcOutlet; typedef Outlet<LatticeModel, FlagFieldT > BcOutlet;
typedef Curved<LatticeModel, FlagFieldT > BcCurved; typedef Curved<LatticeModel, FlagFieldT > BcCurved;
...@@ -144,7 +144,7 @@ ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::ExtendedBoundaryHandl ...@@ -144,7 +144,7 @@ ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::ExtendedBoundaryHandl
template <typename LatticeModel, typename FlagFieldT > template <typename LatticeModel, typename FlagFieldT >
typename ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::BoundaryHandling * typename ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::BoundaryHandling *
ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::operator()( IBlock * const block, ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::operator()( IBlock * const block,
const walberla::StructuredBlockStorage * const /*storage*/ ) const const walberla::StructuredBlockStorage * const storage ) const
{ {
PdfFieldLM * const pdfField = block->getData< PdfFieldLM >( pdfField_ ); PdfFieldLM * const pdfField = block->getData< PdfFieldLM >( pdfField_ );
FlagFieldT * const flagField = block->getData< FlagFieldT >( flagField_ ); FlagFieldT * const flagField = block->getData< FlagFieldT >( flagField_ );
...@@ -160,7 +160,7 @@ ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::operator()( IBlock * ...@@ -160,7 +160,7 @@ ExtendedBoundaryHandlingFactory<LatticeModel, FlagFieldT>::operator()( IBlock *
BcNoSlip ( getNoSlipBoundaryUID(), getNoSlip(), pdfField ), BcNoSlip ( getNoSlipBoundaryUID(), getNoSlip(), pdfField ),
BcFreeSlip ( getFreeSlipBoundaryUID(), getFreeSlip(), pdfField, flagField, mask ), BcFreeSlip ( getFreeSlipBoundaryUID(), getFreeSlip(), pdfField, flagField, mask ),
BcPressure ( getPressureBoundaryUID(), getPressure(), pdfField ), BcPressure ( getPressureBoundaryUID(), getPressure(), pdfField ),
BcUBB ( getUBBBoundaryUID(), getUBB(), pdfField ), BcUBB ( getUBBBoundaryUID(), getUBB(), pdfField, flagField, storage->getLevel(*block), block->getAABB() ),
BcOutlet ( getOutletBoundaryUID(), getOutlet(), pdfField, flagField, mask ), BcOutlet ( getOutletBoundaryUID(), getOutlet(), pdfField, flagField, mask ),
BcCurved ( getCurvedBoundaryUID(), getCurved(), pdfField, flagField, mask ) BcCurved ( getCurvedBoundaryUID(), getCurved(), pdfField, flagField, mask )
) )
......
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