Commit dde95a60 authored by Marcus Mohr's avatar Marcus Mohr
Browse files

Extends XdmfOutput class to support 3D simulations

The XdmfOutput class is extended to also support exporting P1 and
P2 functions in 3D.
parent 75c28931
Pipeline #22797 canceled with stages
in 9 minutes and 27 seconds
......@@ -69,15 +69,17 @@ int main( int argc, char* argv[] )
MeshInfo meshInfo( MeshInfo::fromGmshFile( meshFileName ) );
SetupPrimitiveStorage* setupStorage = nullptr;
setupStorage = new SetupPrimitiveStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) );
hyteg::loadbalancing::roundRobin( *setupStorage );
// SetupPrimitiveStorage* setupStorage = nullptr;
// setupStorage = new SetupPrimitiveStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) );
SetupPrimitiveStorage setupStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) );
hyteg::loadbalancing::roundRobin( setupStorage );
const size_t minLevel = 2;
const size_t maxLevel = std::max( minLevel, (size_t) 6 );
const size_t outLevel = maxLevel;
std::shared_ptr< PrimitiveStorage > storage = std::make_shared< PrimitiveStorage >( *setupStorage );
std::shared_ptr< PrimitiveStorage > storage = std::make_shared< PrimitiveStorage >( setupStorage );
#ifdef WALBERLA_BUILD_WITH_PARMETIS
if ( loadBalancingType == PARMETIS )
......@@ -88,16 +90,11 @@ int main( int argc, char* argv[] )
#endif
std::function< real_t( const hyteg::Point3D& ) > myFunc1 = []( const hyteg::Point3D& xx ) {
return xx[0] * xx[0] - xx[1] * xx[1];
return xx[0] * xx[0] - xx[1] * xx[1] + xx[2];
};
std::function< real_t( const hyteg::Point3D& ) > myFunc2 = []( const hyteg::Point3D& xx ) {
// return ( 1.0 - xx[0] );
return 2.0 * ( 1.0 - xx[0] ) + ( 1.0 - xx[1] );
};
std::function< real_t( const hyteg::Point3D& ) > myFunc3 = []( const hyteg::Point3D& xx ) {
return xx[0] * xx[0] - 1.2 * xx[1] * xx[1];
return 4.0 + 2.0 * ( 1.0 - xx[0] ) + ( 1.0 - xx[1] ) + 3.0 * ( 1.0 - xx[2] );
};
hyteg::P1Function< real_t > p1Data( "P1 test data (myFunc1)", storage, minLevel, maxLevel );
......@@ -124,38 +121,41 @@ int main( int argc, char* argv[] )
vtkOutput.add( p1Func );
vtkOutput.add( p2Data );
vtkOutput.add( p2Func );
// vtkOutput.write( outLevel );
vtkOutput.write( outLevel );
// ----------------------
// Export a time-series
// ----------------------
Point2D center( {0.5, 0.5} );
std::function< real_t( const hyteg::Point3D& ) > bump = [center]( const hyteg::Point3D& x ) {
real_t xOff = center[0] - x[0];
real_t yOff = center[1] - x[1];
real_t dist2 = ( xOff * xOff + yOff * yOff );
real_t fac = 0.01;
real_t val = timestep * std::exp( -dist2 / fac );
return val;
};
XdmfOutput< real_t > xdmfSeries( "../output", "timeSeries", storage );
VTKOutput vtkSeries( "../output", "timeSeries", storage );
xdmfSeries.add( p2Data );
vtkSeries.add( p2Data );
uint_t nSteps = 20;
real_t delta = 1.0 / real_c( nSteps );
for ( uint_t k = 0; k <= nSteps; k++ )
if ( !storage->hasGlobalCells() )
{
timestep = real_c( k ) * delta;
p2Data.interpolate( bump, maxLevel );
xdmfSeries.write( outLevel, timestep );
// vtkSeries.write( outLevel, k );
Point2D center( {0.5, 0.5} );
std::function< real_t( const hyteg::Point3D& ) > bump = [center]( const hyteg::Point3D& x ) {
real_t xOff = center[0] - x[0];
real_t yOff = center[1] - x[1];
real_t dist2 = ( xOff * xOff + yOff * yOff );
real_t fac = 0.01;
real_t val = timestep * std::exp( -dist2 / fac );
return val;
};
XdmfOutput< real_t > xdmfSeries( "../output", "timeSeries", storage );
VTKOutput vtkSeries( "../output", "timeSeries", storage );
xdmfSeries.add( p2Data );
vtkSeries.add( p2Data );
uint_t nSteps = 20;
real_t delta = 1.0 / real_c( nSteps );
for ( uint_t k = 0; k <= nSteps; k++ )
{
timestep = real_c( k ) * delta;
p2Data.interpolate( bump, maxLevel );
xdmfSeries.write( outLevel, timestep );
// vtkSeries.write( outLevel, k );
}
}
delete setupStorage;
// delete setupStorage;
return 0;
}
This diff is collapsed.
......@@ -98,6 +98,10 @@ class XdmfOutput
p1Writer2D_->close();
if ( p2Writer2D_.get() != nullptr )
p2Writer2D_->close();
if ( p1Writer3D_.get() != nullptr )
p1Writer3D_->close();
if ( p2Writer3D_.get() != nullptr )
p2Writer3D_->close();
// clean up the mess from writer initialisation
for ( uint_t k = 0; k < nodeVarNamesP1_.size(); k++ )
......@@ -137,11 +141,21 @@ class XdmfOutput
p1Writer2D_->addTimeStep( timestep );
for ( uint_t k = 0; k < p1Functions_.size(); k++ )
{
std::unique_ptr< real_t[] > dataPtr = xdmf::extractP1Data( p1Functions_[k], *storage_, level );
std::unique_ptr< real_t[] > dataPtr = xdmf::extractData( p1Functions_[k], *storage_, level );
p1Writer2D_->writeVertexData( k, dataPtr.get() );
}
p1Writer2D_->flush();
}
else if ( p1Writer3D_.get() != nullptr )
{
p1Writer3D_->addTimeStep( timestep );
for ( uint_t k = 0; k < p1Functions_.size(); k++ )
{
std::unique_ptr< real_t[] > dataPtr = xdmf::extractData( p1Functions_[k], *storage_, level );
p1Writer3D_->writeVertexData( k, dataPtr.get() );
}
p1Writer3D_->flush();
}
// --------------------
// write P2 functions
......@@ -151,11 +165,21 @@ class XdmfOutput
p2Writer2D_->addTimeStep( timestep );
for ( uint_t k = 0; k < p2Functions_.size(); k++ )
{
std::unique_ptr< real_t[] > dataPtr = xdmf::extractP2Data( p2Functions_[k], *storage_, level );
std::unique_ptr< real_t[] > dataPtr = xdmf::extractData( p2Functions_[k], *storage_, level );
p2Writer2D_->writeVertexData( k, dataPtr.get() );
}
p2Writer2D_->flush();
}
if ( p2Writer3D_.get() != nullptr )
{
p2Writer3D_->addTimeStep( timestep );
for ( uint_t k = 0; k < p2Functions_.size(); k++ )
{
std::unique_ptr< real_t[] > dataPtr = xdmf::extractData( p2Functions_[k], *storage_, level );
p2Writer3D_->writeVertexData( k, dataPtr.get() );
}
p2Writer3D_->flush();
}
};
private:
......@@ -187,7 +211,21 @@ class XdmfOutput
if ( settingIs3D )
{
WALBERLA_ABORT( "3D support missing!" );
if ( p1Writer3D_.get() == nullptr )
{
std::string filenameP1 = walberla::format( "%s/%s_P1", dir_.c_str(), basename_.c_str() );
p1Writer3D_ = std::make_unique< writerFor3D >( xdmfwriter::H5, filenameP1.c_str() );
std::vector< const char* > cellVarNames;
p1Writer3D_->init( cellVarNames,
nodeVarNamesP1_,
true, // useVertexFilter
false // writePartitionInfo
);
p1Writer3D_->setComm( walberla::mpi::MPIManager::instance()->comm() );
p1Writer3D_->setMesh( nCells, cells.data(), nNodes, nodes.data() );
}
}
else
{
......@@ -228,7 +266,21 @@ class XdmfOutput
if ( settingIs3D )
{
WALBERLA_ABORT( "3D support missing!" );
if ( p2Writer3D_.get() == nullptr )
{
std::string filename = walberla::format( "%s/%s_P2", dir_.c_str(), basename_.c_str() );
p2Writer3D_ = std::make_unique< writerFor3D >( xdmfwriter::H5, filename.c_str() );
std::vector< const char* > cellVarNames;
p2Writer3D_->init( cellVarNames,
nodeVarNamesP2_,
true, // useVertexFilter
false // writePartitionInfo
);
p2Writer3D_->setComm( walberla::mpi::MPIManager::instance()->comm() );
p2Writer3D_->setMesh( nCells, cells.data(), nNodes, nodes.data() );
}
}
else
{
......
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