Skip to content

Commit

Permalink
IO: filter mesh levels for VTK
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeltzun committed Sep 28, 2023
1 parent cbc417d commit 176e5db
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@

<VTK
name="vtkOutput"
plotLevel="3"/>
levelNames="{ FE1 }"
plotLevel="3"/>

<!-- output the displacement values to a file named displacement_history.hdf5 -->
<TimeHistory
Expand Down
1 change: 1 addition & 0 deletions inputFiles/wavePropagation/elas3D_DAS_smoke.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<Outputs>
<VTK
name="vtkOutput"
levelNames="{ FE1 }"
plotLevel="3"/>
<Restart
name="restartOutput"/>
Expand Down
1 change: 1 addition & 0 deletions inputFiles/wavePropagation/elas3D_small_base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<!-- output all the mesh values registered with a plot level LEVEL_0, LEVEL_1, LEVEL_2, LEVEL_3 -->
<VTK
name="vtkOutput"
levelNames="{ FE1 }"
plotLevel="3"/>

<!-- output the pressure values to a file named pressure_history.hdf5 -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreComponents/fileIO/Outputs/VTKOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ VTKOutput::VTKOutput( string const & name,
m_plotLevel(),
m_onlyPlotSpecifiedFieldNames(),
m_fieldNames(),
m_levelNames(),
m_writer( getOutputDirectory() + '/' + m_plotFileRoot )
{
registerWrapper( viewKeysStruct::plotFileRoot, &m_plotFileRoot ).
Expand Down Expand Up @@ -67,6 +68,10 @@ VTKOutput::VTKOutput( string const & name,
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Names of the fields to output. If this attribute is specified, GEOSX outputs all the fields specified by the user, regardless of their `plotLevel`" );

registerWrapper( viewKeysStruct::levelNames, &m_levelNames ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Names of mesh levels to output." );

registerWrapper( viewKeysStruct::binaryString, &m_writeBinaryData ).
setApplyDefaultValue( m_writeBinaryData ).
setInputFlag( InputFlags::OPTIONAL ).
Expand All @@ -85,6 +90,7 @@ void VTKOutput::postProcessInput()
{
m_writer.setOutputLocation( getOutputDirectory(), m_plotFileRoot );
m_writer.setFieldNames( m_fieldNames.toViewConst() );
m_writer.setLevelNames( m_levelNames.toViewConst() );
m_writer.setOnlyPlotSpecifiedFieldNamesFlag( m_onlyPlotSpecifiedFieldNames );

string const fieldNamesString = viewKeysStruct::fieldNames;
Expand Down
4 changes: 4 additions & 0 deletions src/coreComponents/fileIO/Outputs/VTKOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class VTKOutput : public OutputBase
static constexpr auto outputRegionTypeString = "outputRegionType";
static constexpr auto onlyPlotSpecifiedFieldNames = "onlyPlotSpecifiedFieldNames";
static constexpr auto fieldNames = "fieldNames";
static constexpr auto levelNames = "levelNames";
} vtkOutputViewKeys;
/// @endcond

Expand All @@ -120,6 +121,9 @@ class VTKOutput : public OutputBase
/// array of names of the fields to output
array1d< string > m_fieldNames;

/// array of names of the mesh levels to output
array1d< string > m_levelNames;

/// VTK output mode
vtk::VTKOutputMode m_writeBinaryData = vtk::VTKOutputMode::BINARY;

Expand Down
26 changes: 20 additions & 6 deletions src/coreComponents/fileIO/vtk/VTKPolyDataWriterInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,18 +968,27 @@ void VTKPolyDataWriterInterface::writeVtmFile( integer const cycle,
{

if( meshLevel.isShallowCopy() )
{
return;

string const & meshLevelName = meshLevel.getName();

if( !m_levelNames.empty())
{
if( m_levelNames.find( meshLevelName ) == m_levelNames.end())
return;
}

string const & meshBodyName = meshBody.getName();

ElementRegionManager const & elemManager = meshLevel.getElemManager();
string const meshPath = joinPath( getCycleSubFolder( cycle ), meshBody.getName(), meshLevel.getName() );
string const meshPath = joinPath( getCycleSubFolder( cycle ), meshBodyName, meshLevelName );
int const mpiSize = MpiWrapper::commSize();

auto addRegion = [&]( ElementRegionBase const & region )
{
std::vector< string > const blockPath{ meshBody.getName(), meshLevel.getName(), region.getCatalogName(), region.getName() };
string const regionPath = joinPath( meshPath, region.getName() );
string const & regionName = region.getName();
std::vector< string > const blockPath{ meshBodyName, meshLevelName, region.getCatalogName(), regionName };
string const regionPath = joinPath( meshPath, regionName );
for( int i = 0; i < mpiSize; i++ )
{
string const dataSetName = getRankFileName( i );
Expand Down Expand Up @@ -1085,14 +1094,19 @@ void VTKPolyDataWriterInterface::write( real64 const time,
{

if( meshLevel.isShallowCopy() )
{
return;

string const & meshLevelName = meshLevel.getName();

if( !m_levelNames.empty())
{
if( m_levelNames.find( meshLevelName ) == m_levelNames.end())
return;
}

ElementRegionManager const & elemManager = meshLevel.getElemManager();
NodeManager const & nodeManager = meshLevel.getNodeManager();
EmbeddedSurfaceNodeManager const & embSurfNodeManager = meshLevel.getEmbSurfNodeManager();
string const & meshLevelName = meshLevel.getName();
string const & meshBodyName = meshBody.getName();

if( m_requireFieldRegistrationCheck && !m_fieldNames.empty() )
Expand Down
11 changes: 11 additions & 0 deletions src/coreComponents/fileIO/vtk/VTKPolyDataWriterInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ class VTKPolyDataWriterInterface
m_fieldNames.insert( fieldNames.begin(), fieldNames.end() );
}

/**
* @brief Set the names of the mesh levels to output
* @param[in] levelNames the mesh levels to output
*/
void setLevelNames( arrayView1d< string const > const & levelNames )
{
m_levelNames.insert( levelNames.begin(), levelNames.end() );
}

/**
* @brief Main method of this class. Write all the files for one time step.
Expand Down Expand Up @@ -307,6 +315,9 @@ class VTKPolyDataWriterInterface
/// Names of the fields to output
std::set< string > m_fieldNames;

/// Names of the mesh levels to output
std::set< string > m_levelNames;

/// The previousCycle
integer m_previousCycle;

Expand Down

0 comments on commit 176e5db

Please sign in to comment.