Skip to content

Commit

Permalink
wip: VTK DataRepo and VTKMeshGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Untereiner committed Sep 9, 2024
1 parent 3de3a70 commit 8d73ee0
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#include "mesh/generators/VTKHierarchicalDataRepository.hpp"

#include "mesh/generators/VTKUtilities.hpp"
#include <vtkXMLPartitionedDataSetCollectionReader.h>

namespace geos
Expand All @@ -38,6 +38,9 @@ VTKHierarchicalDataRepository::VTKHierarchicalDataRepository( string const & nam

void VTKHierarchicalDataRepository::open()

Check warning on line 39 in src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp#L39

Added line #L39 was not covered by tests
{
string const extension = m_filePath.extension();
GEOS_ERROR_IF( extension != "vtpc", "Unsupported vtk extension. File must be a vtpc file" );

Check warning on line 42 in src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp#L41-L42

Added lines #L41 - L42 were not covered by tests

vtkNew< vtkXMLPartitionedDataSetCollectionReader > reader;
reader->SetFileName( m_filePath.c_str());
reader->Update();

Check warning on line 46 in src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp#L44-L46

Added lines #L44 - L46 were not covered by tests
Expand All @@ -46,15 +49,22 @@ void VTKHierarchicalDataRepository::open()
m_dataAssembly = vtkSmartPointer< vtkDataAssembly >( m_collection->GetDataAssembly() );

Check warning on line 49 in src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp#L48-L49

Added lines #L48 - L49 were not covered by tests
}

vtkSmartPointer< vtkDataSet >
vtkSmartPointer< vtkPartitionedDataSet >
VTKHierarchicalDataRepository::search( string const & path )

Check warning on line 53 in src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp#L53

Added line #L53 was not covered by tests
{
int node = m_dataAssembly->GetFirstNodeByPath( path.c_str());
GEOS_ERROR_IF( node == -1, "" );
GEOS_ERROR_IF( node == -1, "Node doesn't exist" );
GEOS_ERROR_IF( m_dataAssembly->GetNumberOfChildren( node ) > 0, "only leaf nodes can be queried." );

Check warning on line 57 in src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp#L55-L57

Added lines #L55 - L57 were not covered by tests

// for sub_node : m_dataAssembly->GetChildNodes(node, False)
return m_collection->GetPartitionedDataSet( node );

Check warning on line 59 in src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKHierarchicalDataRepository.cpp#L59

Added line #L59 was not covered by tests

// for(auto & sub_node : m_dataAssembly->GetChildNodes(node, false))
// {
// std::vector<unsigned int> datasets = m_dataAssembly->GetDataSetIndices(sub_node, false);
// dataset = pdsc.GetPartitionedDataSet(node)
// }
// {
// datasets = m_dataAssembly->GetDataSetIndices(sub_node, False)
// d
// for d in datasets
// {
// dataset = pdsc.GetPartitionedDataSet(d)
Expand All @@ -64,8 +74,9 @@ VTKHierarchicalDataRepository::search( string const & path )
// }
// }
//TODO
}

REGISTER_CATALOG_ENTRY( ExternalDataRepositoryBase, VTKHierarchicalDataRepository, string const &, Group * const )

return {};

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <vtkSmartPointer.h>
#include <vtkDataSet.h>
#include <vtkDataAssembly.h>
#include <vtkPartitionedDataSet.h>
#include <vtkPartitionedDataSetCollection.h>

namespace geos
Expand Down Expand Up @@ -56,7 +57,7 @@ class VTKHierarchicalDataRepository : public ExternalDataRepositoryBase

void open() override;

vtkSmartPointer< vtkDataSet > search( string const & path );
vtkSmartPointer< vtkPartitionedDataSet > search( string const & path );

private:

Expand Down
53 changes: 47 additions & 6 deletions src/coreComponents/mesh/generators/VTKMeshGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "VTKMeshGenerator.hpp"

#include "mesh/ExternalDataRepositoryManager.hpp"
#include "mesh/generators/VTKFaceBlockUtilities.hpp"
#include "mesh/generators/VTKMeshGeneratorTools.hpp"
#include "mesh/generators/CellBlockManager.hpp"
Expand All @@ -33,10 +34,11 @@ using namespace dataRepository;

VTKMeshGenerator::VTKMeshGenerator( string const & name,
Group * const parent )
: ExternalMeshGeneratorBase( name, parent )
: ExternalMeshGeneratorBase( name, parent ),
m_repository( nullptr )
{
// getWrapperBase(ExternalMeshGeneratorBase::viewKeyStruct::filePathString()).
// setInputFlag( InputFlags::OPTIONAL );
getWrapperBase( ExternalMeshGeneratorBase::viewKeyStruct::filePathString()).
setInputFlag( InputFlags::OPTIONAL );

registerWrapper( viewKeyStruct::regionAttributeString(), &m_attributeName ).
setRTTypeName( rtTypes::CustomTypes::groupNameRef ).
Expand Down Expand Up @@ -78,12 +80,38 @@ VTKMeshGenerator::VTKMeshGenerator( string const & name,
" If set to 0 (default value), the GlobalId arrays in the input mesh are used if available, and generated otherwise."
" If set to a negative value, the GlobalId arrays in the input mesh are not used, and generated global Ids are automatically generated."
" If set to a positive value, the GlobalId arrays in the input mesh are used and required, and the simulation aborts if they are not available" );

registerWrapper( viewKeyStruct::repositoryString(), &m_repositoryName ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Name of the VTK Repository" );

registerWrapper( viewKeyStruct::meshPathString(), &m_meshPath ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "path of the VTK mesh in the repository" );
}

void VTKMeshGenerator::postInputInitialization()
{
// if(this->m_filePath && m_meshPath)
// GEOS_ERROR( "Could not import field \"" << meshFieldName << "\" from cell block \"" << cellBlockName << "\"." );
GEOS_ERROR_IF( !this->m_filePath.empty() && (!m_repositoryName.empty() || !m_meshPath.empty()),
getName() << ": Access to the mesh via file or repository are mutually exclusive. "
"You can't set " << viewKeyStruct::repositoryString() << " or " << viewKeyStruct::meshPathString() << " and " <<
ExternalMeshGeneratorBase::viewKeyStruct::filePathString() );

GEOS_ERROR_IF ( !m_repositoryName.empty() && m_meshPath.empty(),
getName() << ": using the repository mode, you must supply a path in the repository for the mesh." );

GEOS_ERROR_IF ( m_repositoryName.empty() && !m_meshPath.empty(),
getName() << ": using a path in the repository for the mesh, you must supply a repository mode." );

ExternalDataRepositoryManager & externalDataManager = this->getGroupByPath< ExternalDataRepositoryManager >( "/Problem/ExternalDataRepository" );
// objectRepository.
m_repository = externalDataManager.getGroupPointer< VTKHierarchicalDataRepository >( m_repositoryName );

Check warning on line 108 in src/coreComponents/mesh/generators/VTKMeshGenerator.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKMeshGenerator.cpp#L108

Added line #L108 was not covered by tests

GEOS_THROW_IF( m_repository == nullptr,

Check warning on line 110 in src/coreComponents/mesh/generators/VTKMeshGenerator.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKMeshGenerator.cpp#L110

Added line #L110 was not covered by tests
getName() << ": VTK Data Object Repository not found: " << m_repositoryName,
InputError );


}

void VTKMeshGenerator::fillCellBlockManager( CellBlockManager & cellBlockManager, SpatialPartition & partition )
Expand All @@ -98,7 +126,20 @@ void VTKMeshGenerator::fillCellBlockManager( CellBlockManager & cellBlockManager
GEOS_LOG_RANK_0( GEOS_FMT( "{} '{}': reading mesh from {}", catalogName(), getName(), m_filePath ) );
{
GEOS_LOG_LEVEL_RANK_0( 2, " reading the dataset..." );
vtk::AllMeshes allMeshes = vtk::loadAllMeshes( m_filePath, m_mainBlockName, m_faceBlockNames );

vtk::AllMeshes allMeshes;

Check warning on line 130 in src/coreComponents/mesh/generators/VTKMeshGenerator.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKMeshGenerator.cpp#L130

Added line #L130 was not covered by tests

if( !m_filePath.empty())

Check warning on line 132 in src/coreComponents/mesh/generators/VTKMeshGenerator.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKMeshGenerator.cpp#L132

Added line #L132 was not covered by tests
{
allMeshes = vtk::loadAllMeshes( m_filePath, m_mainBlockName, m_faceBlockNames );

Check warning on line 134 in src/coreComponents/mesh/generators/VTKMeshGenerator.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKMeshGenerator.cpp#L134

Added line #L134 was not covered by tests
}
else if( !m_repositoryName.empty())

Check warning on line 136 in src/coreComponents/mesh/generators/VTKMeshGenerator.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKMeshGenerator.cpp#L136

Added line #L136 was not covered by tests
{
vtkSmartPointer< vtkPartitionedDataSet > partitions = m_repository->search( m_meshPath );

Check warning on line 138 in src/coreComponents/mesh/generators/VTKMeshGenerator.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/mesh/generators/VTKMeshGenerator.cpp#L138

Added line #L138 was not covered by tests
// allMeshes = vtk::loadPartitions(partitions);
}


GEOS_LOG_LEVEL_RANK_0( 2, " redistributing mesh..." );
vtk::AllMeshes redistributedMeshes =
vtk::redistributeMeshes( getLogLevel(), allMeshes.getMainMesh(), allMeshes.getFaceBlocks(), comm, m_partitionMethod, m_partitionRefinement, m_useGlobalIds );
Expand Down
16 changes: 14 additions & 2 deletions src/coreComponents/mesh/generators/VTKMeshGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "mesh/generators/ExternalMeshGeneratorBase.hpp"
#include "mesh/generators/VTKUtilities.hpp"
#include "mesh/generators/VTKHierarchicalDataRepository.hpp"
#include "mesh/mpiCommunications/SpatialPartition.hpp"

#include <vtkDataSet.h>
Expand Down Expand Up @@ -88,15 +89,15 @@ class VTKMeshGenerator : public ExternalMeshGeneratorBase
* surfaces of interest, with triangles and/or quads holding an attribute value
* of 1, 2 or 3, three node sets named "1", "2" and "3" will be instantiated by this method
*/
virtual void fillCellBlockManager( CellBlockManager & cellBlockManager, SpatialPartition & partition ) override;
void fillCellBlockManager( CellBlockManager & cellBlockManager, SpatialPartition & partition ) override;

void importFieldOnArray( Block block,
string const & blockName,
string const & meshFieldName,
bool isMaterialField,
dataRepository::WrapperBase & wrapper ) const override;

virtual void freeResources() override;
void freeResources() override;

protected:
void postInputInitialization() override;
Expand All @@ -113,6 +114,8 @@ class VTKMeshGenerator : public ExternalMeshGeneratorBase
constexpr static char const * partitionRefinementString() { return "partitionRefinement"; }
constexpr static char const * partitionMethodString() { return "partitionMethod"; }
constexpr static char const * useGlobalIdsString() { return "useGlobalIds"; }
constexpr static char const * repositoryString() { return "repositoryName"; }
constexpr static char const * meshPathString() { return "meshPath"; }
};
/// @endcond

Expand Down Expand Up @@ -158,6 +161,15 @@ class VTKMeshGenerator : public ExternalMeshGeneratorBase

/// Lists of VTK cell ids, organized by element type, then by region
vtk::CellMapType m_cellMap;

/// Repository name
string m_repositoryName;

/// path to the mesh in the repository
string m_meshPath;

/// Repository of VTK objects
VTKHierarchicalDataRepository * m_repository;
};

} // namespace geos
Expand Down
10 changes: 5 additions & 5 deletions src/coreComponents/schema/docs/ExternalDataRepository.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


==== ==== ============================
Name Type Description
==== ==== ============================
(no documentation available)
==== ==== ============================
============================= ==== ======= ========================================
Name Type Default Description
============================= ==== ======= ========================================
VTKHierarchicalDataRepository node :ref:`XML_VTKHierarchicalDataRepository`
============================= ==== ======= ========================================


10 changes: 5 additions & 5 deletions src/coreComponents/schema/docs/ExternalDataRepository_other.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


==== ==== ============================
Name Type Description
==== ==== ============================
(no documentation available)
==== ==== ============================
============================= ==== ==================================================
Name Type Description
============================= ==== ==================================================
VTKHierarchicalDataRepository node :ref:`DATASTRUCTURE_VTKHierarchicalDataRepository`
============================= ==== ==================================================


11 changes: 11 additions & 0 deletions src/coreComponents/schema/docs/VTKHierarchicalDataRepository.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


============================= ============ ======== ===========================================
Name Type Default Description
============================= ============ ======== ===========================================
file groupNameRef required Path to the mesh file
name groupName required A name is required for any non-unique nodes
VTKHierarchicalDataRepository node :ref:`XML_VTKHierarchicalDataRepository`
============================= ============ ======== ===========================================


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


============================= ==== ==================================================
Name Type Description
============================= ==== ==================================================
VTKHierarchicalDataRepository node :ref:`DATASTRUCTURE_VTKHierarchicalDataRepository`
============================= ==== ==================================================


Loading

0 comments on commit 8d73ee0

Please sign in to comment.