Commit 2d1946f3 authored by Daniel Bauer's avatar Daniel Bauer
Browse files

init BoundaryFromMesh from config

parent 25c27800
Pipeline #38755 failed with stages
in 182 minutes and 26 seconds
......@@ -36,6 +36,22 @@ namespace initializer {
//**********************************************************************************************************************
/*! Initializes the flag field according to a mesh and [color -> boundary] mapping.
*
* Configuration file syntax:
\verbatim
Mesh
{
fluidFlag fluid;
ColorToBoundaryMapper
{
default NoSlip;
0 { color <0.0, 0.5, 1.0>; boundary FreeSlip; }
1 { color <1.0, 0.5, 0.0>; boundary Velocity0; }
}
}
\endverbatim
*
* \ingroup geometry
*/
//**********************************************************************************************************************
template<typename FlagField_T, typename Mesh_T>
......@@ -48,7 +64,7 @@ public:
shared_ptr<mesh::DistanceOctree<Mesh_T>> distanceOctree,
const uint_t numGhostLayers );
void init( shared_ptr<mesh::ColorToBoundaryMapper<Mesh_T>> colorToBoundaryMapper,
void init( mesh::ColorToBoundaryMapper<Mesh_T> & colorToBoundaryMapper,
FlagUID fluidFlagID );
void init( BlockStorage & blockStorage, const Config::BlockHandle & blockHandle ) override;
......@@ -56,7 +72,6 @@ public:
shared_ptr<mesh::BoundaryLocation<Mesh_T>> getBoundaryLocation() const;
protected:
shared_ptr<StructuredBlockStorage> blocks_;
BlockDataID flagFieldID_;
BlockDataID flagFieldBoundarHandlingID_;
......
......@@ -32,6 +32,7 @@ namespace initializer {
namespace internal {
// TODO: move this to central place
//**********************************************************************************************************************
/*! A small helper class that makes it possible to use mesh::boundary::BoundarySetup
* to operate directly on the flag field instead of on a boundary handling.
......@@ -116,8 +117,7 @@ BoundaryFromMesh<FlagField_T, Mesh_T>::BoundaryFromMesh(
shared_ptr<Mesh_T> mesh,
shared_ptr<mesh::DistanceOctree<Mesh_T>> distanceOctree,
const uint_t numGhostLayers )
: blocks_(blocks),
flagFieldID_(flagFieldID),
: flagFieldID_(flagFieldID),
mesh_(mesh),
distanceOctree_(distanceOctree),
boundarySetup_(blocks, makeMeshDistanceFunction(distanceOctree), numGhostLayers)
......@@ -141,14 +141,14 @@ BoundaryFromMesh<FlagField_T, Mesh_T>::BoundaryFromMesh(
//*******************************************************************************************************************
template<typename FlagField_T, typename Mesh_T>
void BoundaryFromMesh<FlagField_T, Mesh_T>::init(
shared_ptr<mesh::ColorToBoundaryMapper<Mesh_T>> colorToBoundaryMapper,
mesh::ColorToBoundaryMapper<Mesh_T> & colorToBoundaryMapper,
FlagUID fluidFlagID )
{
using namespace internal;
boundarySetup_.setFlag<FlagField_T>(flagFieldID_, fluidFlagID, mesh::BoundarySetup::OUTSIDE);
boundaryLocation_ = colorToBoundaryMapper->addBoundaryInfoToMesh(*mesh_);
boundaryLocation_ = colorToBoundaryMapper.addBoundaryInfoToMesh(*mesh_);
boundarySetup_.setBoundaries<FlagFieldBoundaryHandling<FlagField_T>>(
flagFieldBoundarHandlingID_,
......@@ -158,10 +158,12 @@ void BoundaryFromMesh<FlagField_T, Mesh_T>::init(
template<typename FlagField_T, typename Mesh_T>
void BoundaryFromMesh<FlagField_T, Mesh_T>::init(
BlockStorage & blockStorage, const Config::BlockHandle & blockHandle )
BlockStorage &, const Config::BlockHandle & blockHandle )
{
// TODO: implement
WALBERLA_ABORT("Not implemented")
mesh::ColorToBoundaryMapper< Mesh_T > colorToBoundaryMapper{ blockHandle.getBlock( "ColorToBoundaryMapper") };
FlagUID fluidFlag = FlagUID{ blockHandle.getParameter< std::string >( "fluidFlag") };
init( colorToBoundaryMapper, fluidFlag );
}
//*******************************************************************************************************************
......
......@@ -23,6 +23,7 @@
#include "BoundaryInfo.h"
#include "core/config/Config.h"
#include "core/DataTypes.h"
#include "core/debug/CheckFunctions.h"
......@@ -39,6 +40,32 @@ public:
ColorToBoundaryMapper( const BoundaryInfo & defaultBoundaryInfo ) : defaultBoundaryInfo_(defaultBoundaryInfo) { }
ColorToBoundaryMapper( const Config::BlockHandle & blockHandle )
{
if ( not blockHandle.isValid() )
return;
const std::string defaultID = blockHandle.getParameter< std::string >( "default" );
defaultBoundaryInfo_ = BoundaryInfo( boundary::BoundaryUID( defaultID) );
Config::Blocks colorBoundaryMappings;
blockHandle.getBlocks( colorBoundaryMappings );
for ( const auto & mapping : colorBoundaryMappings )
{
const Vector3< real_t > colorRaw = mapping.getParameter< Vector3< real_t > >( "color" );
const std::string id = mapping.getParameter< std::string >( "boundary" );
// TODO: this conversion makes assumptions on the templated type (Color)
const Color color{ std::round( 255 * colorRaw[0]),
std::round( 255 * colorRaw[1]),
std::round( 255 * colorRaw[2]) };
const BoundaryInfo info{ boundary::BoundaryUID( id ) };
set( color, info );
}
}
void set( const Color & c, const BoundaryInfo & bi )
{
boundaryInfoMap_[c] = bi;
......@@ -70,4 +97,4 @@ private:
};
} // namespace walberla
} // namespace mesh
\ No newline at end of file
} // namespace mesh
Markdown is supported
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