Skip to content

Commit

Permalink
refactor: some more details for mesh import, unify createChild log me…
Browse files Browse the repository at this point in the history
…ssages (#3476)

Co-authored-by: Nicola Castelletto <[email protected]>
  • Loading branch information
paveltomin and castelletto1 authored Dec 13, 2024
1 parent da4cd7f commit b5ea7ce
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 72 deletions.
1 change: 1 addition & 0 deletions src/coreComponents/constitutive/ConstitutiveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ConstitutiveManager::~ConstitutiveManager()

Group * ConstitutiveManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< ConstitutiveBase > material = ConstitutiveBase::CatalogInterface::factory( childKey, childName, this );
return &registerGroup< ConstitutiveBase >( childName, std::move( material ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/dataRepository/xmlWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void xmlDocument::addIncludedXML( xmlNode & targetNode, int const level )
return isAbsolutePath( fileName ) ? fileName : joinPath( splitPath( currentFilePath ).first, fileName );
}();

GEOS_LOG_RANK_0( "Included additionnal XML file: " << getAbsolutePath( includedFilePath ) );
GEOS_LOG_RANK_0( "Included additional XML file: " << getAbsolutePath( includedFilePath ) );

xmlDocument includedXmlDocument;
xmlResult const result = includedXmlDocument.loadFile( includedFilePath, hasNodeFileInfo() );
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/events/EventBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ EventBase::CatalogInterface::CatalogType & EventBase::getCatalog()

Group * EventBase::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( "Adding Event: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< EventBase > event = EventBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< EventBase >( childName, std::move( event ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/events/EventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ EventManager::~EventManager()

Group * EventManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( "Adding Event: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< EventBase > event = EventBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< EventBase >( childName, std::move( event ) );
}
Expand Down
1 change: 1 addition & 0 deletions src/coreComponents/events/tasks/TasksManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TasksManager::~TasksManager()

Group * TasksManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< TaskBase > task = TaskBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< TaskBase >( childName, std::move( task ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FieldSpecificationManager & FieldSpecificationManager::getInstance()

Group * FieldSpecificationManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< FieldSpecificationBase > bc = FieldSpecificationBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup( childName, std::move( bc ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/fileIO/Outputs/OutputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ OutputManager::~OutputManager()

Group * OutputManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( "Adding Output: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< OutputBase > output = OutputBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< OutputBase >( childName, std::move( output ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ FiniteElementDiscretizationManager::~FiniteElementDiscretizationManager()
Group * FiniteElementDiscretizationManager::createChild( string const & childKey, string const & childName )
{
// These objects should probably not be registered on managed group...
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< Group > fem = Group::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup( childName, std::move( fem ) );
}
Expand Down
1 change: 1 addition & 0 deletions src/coreComponents/finiteVolume/FiniteVolumeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ FiniteVolumeManager::~FiniteVolumeManager()

Group * FiniteVolumeManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
if( childKey == HybridMimeticDiscretization::catalogName() )
{
std::unique_ptr< HybridMimeticDiscretization > hm = std::make_unique< HybridMimeticDiscretization >( childName, this );
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/functions/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ FunctionManager & FunctionManager::getInstance()
Group * FunctionManager::createChild( string const & functionCatalogKey,
string const & functionName )
{
GEOS_LOG_RANK_0( " " << functionCatalogKey << ": " << functionName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), functionCatalogKey, functionName ) );
std::unique_ptr< FunctionBase > function = FunctionBase::CatalogInterface::factory( functionCatalogKey, functionName, this );
return &this->registerGroup< FunctionBase >( functionName, std::move( function ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/ElementRegionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Group * ElementRegionManager::createChild( string const & childKey, string const
{
GEOS_ERROR_IF( !(CatalogInterface::hasKeyName( childKey )),
"KeyName ("<<childKey<<") not found in ObjectManager::Catalog" );
GEOS_LOG_RANK_0( "Adding Object " << childKey<<" named "<< childName<<" from ObjectManager::Catalog." );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );

Group & elementRegions = this->getGroup( ElementRegionManager::groupKeyStruct::elementRegionsGroup() );
return &elementRegions.registerGroup( childName,
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/ExternalDataSourceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ExternalDataSourceBase::ExternalDataSourceBase( string const & name, Group * con

Group * ExternalDataSourceBase::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( "Adding External Data Source: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< ExternalDataSourceBase > event = ExternalDataSourceBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< ExternalDataSourceBase >( childName, std::move( event ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/ExternalDataSourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ExternalDataSourceManager::~ExternalDataSourceManager()

Group * ExternalDataSourceManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( "Adding External Data Source: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< ExternalDataSourceBase > externalDataSource = ExternalDataSourceBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< ExternalDataSourceBase >( childName, std::move( externalDataSource ) );
}
Expand Down
96 changes: 48 additions & 48 deletions src/coreComponents/mesh/MeshManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "mesh/mpiCommunications/SpatialPartition.hpp"
#include "generators/CellBlockManagerABC.hpp"
#include "generators/MeshGeneratorBase.hpp"
#include "mesh/mpiCommunications/CommunicationTools.hpp"
#include "common/TimingMacros.hpp"

Expand All @@ -43,7 +42,7 @@ MeshManager::~MeshManager()

Group * MeshManager::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( "Adding Mesh: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< MeshGeneratorBase > mesh = MeshGeneratorBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< MeshGeneratorBase >( childName, std::move( mesh ) );
}
Expand Down Expand Up @@ -81,7 +80,7 @@ void MeshManager::generateMeshes( DomainPartition & domain )

void MeshManager::generateMeshLevels( DomainPartition & domain )
{
this->forSubGroups< MeshGeneratorBase >( [&]( MeshGeneratorBase & meshGen )
forSubGroups< MeshGeneratorBase >( [&]( MeshGeneratorBase & meshGen )
{
string const & meshName = meshGen.getName();
domain.getMeshBodies().registerGroup< MeshBody >( meshName ).createMeshLevel( MeshBody::groupStructKeys::baseDiscretizationString() );
Expand Down Expand Up @@ -126,66 +125,28 @@ void MeshManager::importFields( DomainPartition & domain )
}

GEOS_LOG_RANK_0( GEOS_FMT( "{}: importing field data from mesh dataset", generator.getName() ) );

auto const importFields = [&generator]( ElementRegionBase const & region,
ElementSubRegionBase & subRegion,
MeshGeneratorBase::Block block,
std::map< string, string > const & fieldsMapping,
FieldIdentifiers & fieldsToBeSync )
{
std::unordered_set< string > const materialWrapperNames = getMaterialWrapperNames( subRegion );
// Writing properties
for( auto const & pair : fieldsMapping )
{
string const & meshFieldName = pair.first;
string const & geosFieldName = pair.second;
// Find destination
if( !subRegion.hasWrapper( geosFieldName ) )
{
// Skip - the user may have not enabled a particular physics model/solver on this destination region.
if( generator.getLogLevel() >= 1 )
{
GEOS_LOG_RANK_0( "Skipping import of " << meshFieldName << " -> " << geosFieldName <<
" on " << region.getName() << "/" << subRegion.getName() << " (field not found)" );
}

continue;
}

// Now that we know that the subRegion has this wrapper,
// we can add the geosFieldName to the list of fields to synchronize
fieldsToBeSync.addElementFields( { geosFieldName }, { region.getName() } );
WrapperBase & wrapper = subRegion.getWrapperBase( geosFieldName );
if( generator.getLogLevel() >= 1 )
{
GEOS_LOG_RANK_0( "Importing field " << meshFieldName << " into " << geosFieldName <<
" on " << region.getName() << "/" << subRegion.getName() );
}

bool const isMaterialField = materialWrapperNames.count( geosFieldName ) > 0 && wrapper.numArrayDims() > 1;
generator.importFieldOnArray( block, subRegion.getName(), meshFieldName, isMaterialField, wrapper );
}
};

dataRepository::Group & meshLevels = domain.getMeshBody( generator.getName() ).getMeshLevels();
meshLevels.forSubGroups< MeshLevel >( [&]( MeshLevel & meshLevel )
MeshBody & meshBody = domain.getMeshBody( generator.getName() );
meshBody.forMeshLevels( [&]( MeshLevel & meshLevel )
{
GEOS_LOG_RANK_0( GEOS_FMT( " mesh level = {}", meshLevel.getName() ) );
FieldIdentifiers fieldsToBeSync;
meshLevel.getElemManager().forElementSubRegionsComplete< CellElementSubRegion >(
[&]( localIndex,
localIndex,
ElementRegionBase const & region,
CellElementSubRegion & subRegion )
{
importFields( region, subRegion, MeshGeneratorBase::Block::VOLUMIC, generator.getVolumicFieldsMapping(), fieldsToBeSync );
GEOS_LOG_RANK_0( GEOS_FMT( " volumic fields on {}/{}", region.getName(), subRegion.getName() ) );
importFields( generator, region.getName(), subRegion, MeshGeneratorBase::Block::VOLUMIC, generator.getVolumicFieldsMapping(), fieldsToBeSync );
} );
meshLevel.getElemManager().forElementSubRegionsComplete< FaceElementSubRegion >(
[&]( localIndex,
localIndex,
ElementRegionBase const & region,
FaceElementSubRegion & subRegion )
{
importFields( region, subRegion, MeshGeneratorBase::Block::SURFACIC, generator.getSurfacicFieldsMapping(), fieldsToBeSync );
GEOS_LOG_RANK_0( GEOS_FMT( " surfaic fields on {}/{}", region.getName(), subRegion.getName() ) );
importFields( generator, region.getName(), subRegion, MeshGeneratorBase::Block::SURFACIC, generator.getSurfacicFieldsMapping(), fieldsToBeSync );
} );
CommunicationTools::getInstance().synchronizeFields( fieldsToBeSync, meshLevel, domain.getNeighbors(), false ); // TODO Validate this.
} );
Expand All @@ -197,4 +158,43 @@ void MeshManager::importFields( DomainPartition & domain )
} );
}

void MeshManager::importFields( MeshGeneratorBase const & generator,
string const & regionName,
ElementSubRegionBase & subRegion,
MeshGeneratorBase::Block const block,
std::map< string, string > const & fieldsMapping,
FieldIdentifiers & fieldsToBeSync )
{
std::unordered_set< string > const materialWrapperNames = getMaterialWrapperNames( subRegion );
// Writing properties
for( auto const & pair : fieldsMapping )
{
string const & meshFieldName = pair.first;
string const & geosFieldName = pair.second;
// Find destination
if( !subRegion.hasWrapper( geosFieldName ) )
{
// Skip - the user may have not enabled a particular physics model/solver on this destination region.
if( generator.getLogLevel() >= 1 )
{
GEOS_LOG_RANK_0( GEOS_FMT( " Skipping import of {} -> {} (field not found)", meshFieldName, geosFieldName ) );
}

continue;
}

// Now that we know that the subRegion has this wrapper,
// we can add the geosFieldName to the list of fields to synchronize
fieldsToBeSync.addElementFields( { geosFieldName }, { regionName } );
WrapperBase & wrapper = subRegion.getWrapperBase( geosFieldName );
if( generator.getLogLevel() >= 1 )
{
GEOS_LOG_RANK_0( GEOS_FMT( " {} -> {}", meshFieldName, geosFieldName ) );
}

bool const isMaterialField = materialWrapperNames.count( geosFieldName ) > 0 && wrapper.numArrayDims() > 1;
generator.importFieldOnArray( block, subRegion.getName(), meshFieldName, isMaterialField, wrapper );
}
}

} /* namespace geos */
17 changes: 17 additions & 0 deletions src/coreComponents/mesh/MeshManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "dataRepository/Group.hpp"
#include "mesh/DomainPartition.hpp"
#include "generators/MeshGeneratorBase.hpp"

namespace geos
{
Expand Down Expand Up @@ -74,6 +75,22 @@ class MeshManager : public dataRepository::Group
*/
void importFields( DomainPartition & domain );

/**
* @brief Import fields data
* @param[in] generator reference to mesh generator
* @param[in] regionName name of the region
* @param[in] subRegion reference to the subregion
* @param[in] block block type
* @param[in] fieldsMapping mapping for fields
* @param[out] fieldsToBeSync list of fields to synchronize
*/
static void importFields( MeshGeneratorBase const & generator,
string const & regionName,
ElementSubRegionBase & subRegion,
MeshGeneratorBase::Block block,
std::map< string, string > const & fieldsMapping,
FieldIdentifiers & fieldsToBeSync );

private:

/**
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/ParticleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Group * ParticleManager::createChild( string const & childKey, string const & ch
{
GEOS_ERROR_IF( !(CatalogInterface::hasKeyName( childKey )),
"KeyName ("<<childKey<<") not found in ObjectManager::Catalog" );
GEOS_LOG_RANK_0( "Adding Object " << childKey << " named " << childName << " from ObjectManager::Catalog." );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );

Group & particleRegions = this->getGroup( ParticleManager::groupKeyStruct::particleRegionsGroup() );
return &particleRegions.registerGroup( childName,
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/generators/MeshGeneratorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MeshGeneratorBase::MeshGeneratorBase( string const & name, Group * const parent

Group * MeshGeneratorBase::createChild( string const & childKey, string const & childName )
{
GEOS_LOG_RANK_0( "Adding Mesh attribute: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
std::unique_ptr< MeshComponentBase > comp = MeshComponentBase::CatalogInterface::factory( childKey, childName, this );
return &this->registerGroup< MeshComponentBase >( childName, std::move( comp ) );
}
Expand Down
22 changes: 11 additions & 11 deletions src/coreComponents/mesh/generators/VTKMeshGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void VTKMeshGenerator::fillCellBlockManager( CellBlockManager & cellBlockManager
{
vtk::AllMeshes allMeshes;

GEOS_LOG_LEVEL_RANK_0( 2, " reading the dataset..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': reading the dataset...", catalogName(), getName() ) );

if( !m_filePath.empty())
{
Expand Down Expand Up @@ -183,41 +183,41 @@ void VTKMeshGenerator::fillCellBlockManager( CellBlockManager & cellBlockManager
}
}

GEOS_LOG_LEVEL_RANK_0( 2, " redistributing mesh..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': redistributing mesh...", catalogName(), getName() ) );
vtk::AllMeshes redistributedMeshes =
vtk::redistributeMeshes( getLogLevel(), allMeshes.getMainMesh(), allMeshes.getFaceBlocks(), comm, m_partitionMethod, m_partitionRefinement, m_useGlobalIds );
m_vtkMesh = redistributedMeshes.getMainMesh();
m_faceBlockMeshes = redistributedMeshes.getFaceBlocks();
GEOS_LOG_LEVEL_RANK_0( 2, " finding neighbor ranks..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': finding neighbor ranks...", catalogName(), getName() ) );
std::vector< vtkBoundingBox > boxes = vtk::exchangeBoundingBoxes( *m_vtkMesh, comm );
std::vector< int > const neighbors = vtk::findNeighborRanks( std::move( boxes ) );
partition.setMetisNeighborList( std::move( neighbors ) );
GEOS_LOG_LEVEL_RANK_0( 2, " done!" );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': done!", catalogName(), getName() ) );
}
GEOS_LOG_RANK_0( GEOS_FMT( "{} '{}': generating GEOSX mesh data structure", catalogName(), getName() ) );
GEOS_LOG_RANK_0( GEOS_FMT( "{} '{}': generating GEOS mesh data structure", catalogName(), getName() ) );


GEOS_LOG_LEVEL_RANK_0( 2, " preprocessing..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': preprocessing...", catalogName(), getName() ) );
m_cellMap = vtk::buildCellMap( *m_vtkMesh, m_attributeName );

GEOS_LOG_LEVEL_RANK_0( 2, " writing nodes..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': writing nodes...", catalogName(), getName() ) );
cellBlockManager.setGlobalLength( writeNodes( getLogLevel(), *m_vtkMesh, m_nodesetNames, cellBlockManager, this->m_translate, this->m_scale ) );

GEOS_LOG_LEVEL_RANK_0( 2, " writing cells..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': writing cells...", catalogName(), getName() ) );
writeCells( getLogLevel(), *m_vtkMesh, m_cellMap, cellBlockManager );

GEOS_LOG_LEVEL_RANK_0( 2, " writing surfaces..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': writing surfaces...", catalogName(), getName() ) );
writeSurfaces( getLogLevel(), *m_vtkMesh, m_cellMap, cellBlockManager );

GEOS_LOG_LEVEL_RANK_0( 2, " building connectivity maps..." );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': building connectivity maps...", catalogName(), getName() ) );
cellBlockManager.buildMaps();

for( auto const & [name, mesh]: m_faceBlockMeshes )
{
vtk::importFractureNetwork( name, mesh, m_vtkMesh, cellBlockManager );
}

GEOS_LOG_LEVEL_RANK_0( 2, " done!" );
GEOS_LOG_LEVEL_RANK_0( 2, GEOS_FMT( "{} '{}': done!", catalogName(), getName() ) );
vtk::printMeshStatistics( *m_vtkMesh, m_cellMap, comm );
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/mesh/generators/WellGeneratorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Group * WellGeneratorBase::createChild( string const & childKey, string const &

// keep track of the perforations that have been added
m_perforationList.emplace_back( childName );
GEOS_LOG_RANK_0( "Adding Well attribute: " << childKey << ", " << childName );
GEOS_LOG_RANK_0( GEOS_FMT( "{}: adding {} {}", getName(), childKey, childName ) );
return &registerGroup< Perforation >( childName );
}
else
Expand Down
Loading

0 comments on commit b5ea7ce

Please sign in to comment.