From 76f4644c9011231612342e0d3e38575bec9891e8 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 7 May 2025 18:24:23 +0200 Subject: [PATCH 01/67] =?UTF-8?q?=F0=9F=92=A9=20first=20attempt=20at=20out?= =?UTF-8?q?puting=20wrong=20cells=20in=20multiphase=20cases...=20work=20on?= =?UTF-8?q?=20CPU=20but=20doesn't=20on=20GPU=20build=20+=20suboptimal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 1 + .../fluidFlow/CompositionalMultiphaseFVM.cpp | 135 +++++++++++----- .../kernels/SolutionCheckHelperKernels.hpp | 88 +++++++++++ .../compositional/SolutionCheckKernel.hpp | 62 ++++++-- .../singlePhase/SolutionCheckKernel.hpp | 1 + src/coreComponents/schema/schema.xsd | 4 +- src/coreComponents/schema/schema.xsd.other | 146 +++++++++--------- 7 files changed, 311 insertions(+), 126 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index ce0829dd415..82bda960652 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -41,6 +41,7 @@ set( fluidFlowSolvers_headers LogLevelsInfo.hpp kernels/MinPoreVolumeMaxPorosityKernel.hpp kernels/StencilWeightsUpdateKernel.hpp + kernels/SolutionCheckHelperKernels.hpp kernels/HybridFVMHelperKernels.hpp kernels/singlePhase/AccumulationKernels.hpp kernels/singlePhase/AquiferBCKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index b5387d3e040..4bb9f553fc8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -846,6 +846,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegPres = 0, numNegDens = 0, numNegTotalDens = 0; + std::vector< globalIndex > rankNegPressureElementIds; + std::vector< globalIndex > rankNegDensityElementIds; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -867,50 +869,73 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K const integer temperatureOffset = m_numComponents+1; - auto const subRegionData = - m_isThermal - ? thermalCompositionalMultiphaseBaseKernels:: - SolutionCheckKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - temperature, - compDens, - pressureScalingFactor, - temperatureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution, - temperatureOffset ) - : isothermalCompositionalMultiphaseBaseKernels:: - SolutionCheckKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution ); + auto const subRegionData = m_isThermal ? + thermalCompositionalMultiphaseBaseKernels:: + SolutionCheckKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + temperature, + compDens, + pressureScalingFactor, + temperatureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution, + temperatureOffset ) : + isothermalCompositionalMultiphaseBaseKernels:: + SolutionCheckKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution ); localCheck = std::min( localCheck, subRegionData.localMinVal ); minPres = std::min( minPres, subRegionData.localMinPres ); minDens = std::min( minDens, subRegionData.localMinDens ); minTotalDens = std::min( minTotalDens, subRegionData.localMinTotalDens ); - numNegPres += subRegionData.localNumNegPressures; - numNegDens += subRegionData.localNumNegDens; + // numNegPres += subRegionData.localNumNegPressures; + // numNegDens += subRegionData.localNumNegDens; numNegTotalDens += subRegionData.localNumNegTotalDens; + + // integer const numIdsToAdd = std::min( subRegionData.localNumNegPressures, + // integer( subRegionData.localNegPresElementIds.capacity() ) ); + // for( int i = 0; i < numIdsToAdd; ++i ) + // { + // rankNegPressureElementIds.emplace_back( subRegionData.localNegPresElementIds[i] ); // todo local -> global + // } + + flowSolverBaseKernels::aggregateKernelsIds( rankNegPressureElementIds, + numNegPres, + subRegionData.localNegPresElementIds, + subRegionData.localNumNegPressures ); + + flowSolverBaseKernels::aggregateKernelsIds( rankNegDensityElementIds, + numNegDens, + subRegionData.localNegDensElementIds, + subRegionData.localNumNegDens ); + + // integer const numIdsToAdd = std::min( subRegionData.localNumNegDens, + // integer( subRegionData.localNegDensElementIds.capacity() ) ); + // for( int i = 0; i < numIdsToAdd; ++i ) + // { + // rankNegDensityElementIds.emplace_back( subRegionData.localNegDensElementIds[i] ); // todo local -> global + // } } ); } ); @@ -922,18 +947,48 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); if( numNegPres > 0 ) + { GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative pressure values: {}, minimum value: {} Pa", getName(), numNegPres, fmt::format( "{:.{}f}", minPres, 3 ) ) ); + GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, + GEOS_FMT( " {}: negative pressure element ids (may not be complete):", + getName() ) ); + MpiWrapper::barrier(); + if( !rankNegPressureElementIds.empty() ) + { + GEOS_LOG_LEVEL( logInfo::Solution, + GEOS_FMT( " Rank {}: {}", + MpiWrapper::commRank(), + stringutilities::join( rankNegPressureElementIds, ", " ) ) ); + } + } + string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; + if( minTotalDens > 0 ) + { + GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, + GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}}", + getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + } + if( numNegDens > 0 ) + { GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative component density values: {}, minimum value: {} {}}", getName(), numNegDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); - if( minTotalDens > 0 ) GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, - GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}}", - getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + GEOS_FMT( " {}: negative component density element ids (may not be complete):", + getName() ) ); + MpiWrapper::barrier(); + if( !rankNegDensityElementIds.empty() ) + { + GEOS_LOG_LEVEL( logInfo::Solution, + GEOS_FMT( " Rank {}: {}", + MpiWrapper::commRank(), + stringutilities::join( rankNegDensityElementIds, ", " ) ) ); + } + } return MpiWrapper::min( localCheck ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp new file mode 100644 index 00000000000..8757759964a --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp @@ -0,0 +1,88 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 TotalEnergies + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file SolutionCheckKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPERKERNELS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPERKERNELS_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" + +namespace geos +{ + +namespace flowSolverBaseKernels +{ + +//fonction inutile +template< typename KernelStackArray, typename IdType, typename IdCountType > +GEOS_HOST_DEVICE +void collectKernelId( KernelStackArray & idList, + IdCountType & idsCounter, + IdType id ) +{ + if( idsCounter < idList.capacity() ) + { + idList[idsCounter] = id; // ne peut avoir qu'une occurence + } + + idsCounter += 1; +} + +/** + * @brief + * @param stackBuffer + * @param kernelIds + * @param kernelIdsCount Strictly positive. + */ +template< typename OutputStackArray, typename KernelStackArray, typename IdCountType, typename ReducePolicy > +GEOS_HOST_DEVICE +void aggregateKernelsIds( OutputStackArray & outputBuffer, + T & outputIdsCounter, + KernelStackArray const & kernelIds, + IdCountType const kernelIdsCount ) +{ + IdCountType const outputBufferStart = RAJA::atomicAdd< RAJA::auto_atomic >( &outputIdsCounter, + kernelIdsCount ); + IdCountType const maxNbIdToAdd = IdCountType( outputBuffer.capacity() - outputBufferStart ); + IdCountType const nbIdToAdd = LvArray::math::min( kernelIdsCount, maxNbIdToAdd ); + for( IdCountType i = 0; i < nbIdToAdd; ++i ) + { + outputBuffer[outputBufferStart + i] = kernelIds[i]; + } +} + +template< typename OutputDynamicArray, typename InputArray, typename IdCountType > +void aggregateKernelsIds( OutputDynamicArray & outputBuffer, + IdCountType & outputIdsCounter, + InputArray const & ids, + IdCountType const idsCount ) +{ + outputIdsCounter += idsCount; + IdCountType const numIdsToAdd = std::min( idsCount, IdCountType( ids.capacity() ) ); + for( int i = 0; i < numIdsToAdd; ++i ) + { + outputBuffer.emplace_back( ids[i] ); // todo local -> global + } +} + +} // namespace flowSolverBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 89d681bb02c..b0d725ca2e1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -21,6 +21,7 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" +#include "physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp" namespace geos { @@ -47,6 +48,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer using Base::m_pressure; using Base::m_compDens; + static constexpr int maxNegValueElementIds = 16; + /** * @brief Create a new kernel instance * @param[in] allowCompDensChopping flag to allow the component density chopping @@ -94,7 +97,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer struct StackVariables : public Base::StackVariables { GEOS_HOST_DEVICE - StackVariables() + StackVariables(): + localNegPresElementIds( maxNegValueElementIds ), + localNegDensElementIds( maxNegValueElementIds ) { } StackVariables( real64 _localMinVal, @@ -103,7 +108,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer real64 _localMinTotalDens, integer _localNumNegPressures, integer _localNumNegDens, - integer _localNumNegTotalDens ) + integer _localNumNegTotalDens, + stackArray1d< globalIndex, maxNegValueElementIds > _localNegPresElementIds, + stackArray1d< globalIndex, maxNegValueElementIds > _localNegDensElementIds ) : Base::StackVariables( _localMinVal ), localMinPres( _localMinPres ), @@ -111,17 +118,24 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer localMinTotalDens( _localMinTotalDens ), localNumNegPressures( _localNumNegPressures ), localNumNegDens( _localNumNegDens ), - localNumNegTotalDens( _localNumNegTotalDens ) + localNumNegTotalDens( _localNumNegTotalDens ), + localNegPresElementIds( _localNegPresElementIds ), + localNegDensElementIds( _localNegDensElementIds ) { } real64 localMinPres; real64 localMinDens; real64 localMinTotalDens; - integer localNumNegPressures; - integer localNumNegDens; - integer localNumNegTotalDens; + integer localNumNegPressures; // ne peuvent être que 0 ou 1 dans chaque kernel + integer localNumNegDens; // ne peuvent être que 0 ou 1 dans chaque kernel + integer localNumNegTotalDens; // ne peuvent être que 0 ou 1 dans chaque kernel + + /// limited quantity of local ids of detected solved elements with negative pressures + stackArray1d< globalIndex, maxNegValueElementIds > localNegPresElementIds; + /// limited quantity of local ids of detected solved elements with negative density + stackArray1d< globalIndex, maxNegValueElementIds > localNegDensElementIds; }; /** @@ -146,6 +160,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegDens( 0 ); RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegTotalDens( 0 ); + stackArray1d< globalIndex, maxNegValueElementIds > localNegPresElementIds; + stackArray1d< globalIndex, maxNegValueElementIds > localNegDensElementIds; + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) { if( kernelComponent.ghostRank( ei ) >= 0 ) @@ -163,8 +180,21 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer minDens.min( stack.localMinDens ); minTotalDens.min( stack.localMinTotalDens ); - numNegPressures += stack.localNumNegPressures; - numNegDens += stack.localNumNegDens; + if( stack.localNumNegPressures > 0 ) + { + flowSolverBaseKernels::aggregateKernelsIds( localNegPresElementIds, + numNegPressures, + stack.localNegPresElementIds, + integer( stack.localNumNegPressures ) ); + } + + if( stack.localNumNegDens > 0 ) + { + flowSolverBaseKernels::aggregateKernelsIds( localNegDensElementIds, + numNegDens, + stack.localNegDensElementIds, + stack.localNumNegDens ); + } numNegTotalDens += stack.localNumNegTotalDens; } ); @@ -174,7 +204,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer minTotalDens.get(), numNegPressures.get(), numNegDens.get(), - numNegTotalDens.get() ); + numNegTotalDens.get(), + localNegPresElementIds, + localNegDensElementIds ); } GEOS_HOST_DEVICE @@ -226,7 +258,11 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer { stack.localMinVal = 0; } - stack.localNumNegPressures += 1; + + flowSolverBaseKernels::collectKernelId( stack.localNegPresElementIds, + stack.localNumNegPressures, + globalIndex( ei ) ); + if( newPres < stack.localMinPres ) stack.localMinPres = newPres; } @@ -242,7 +278,11 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer if( newDens < 0 ) { stack.localMinVal = 0; - stack.localNumNegDens += 1; + + flowSolverBaseKernels::collectKernelId( stack.localNegDensElementIds, + stack.localNumNegDens, + ei ); + if( newDens < stack.localMinDens ) stack.localMinDens = newDens; } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp index 24529dda836..b4bf8022774 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp @@ -22,6 +22,7 @@ #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" +#include "common/GEOS_RAJA_Interface.hpp" namespace geos { diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index ee95e352d66..c8137e5ce7c 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -3459,7 +3459,7 @@ Information output from lower logLevels is added with the desired log level - + @@ -3482,7 +3482,7 @@ Local- Add jump stabilization on interior of macro elements--> - + diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index 728b907fe74..7cbfd61e863 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -486,7 +486,7 @@ - + @@ -576,7 +576,7 @@ - + @@ -613,7 +613,7 @@ - + @@ -666,7 +666,7 @@ - + @@ -709,7 +709,7 @@ - + @@ -744,7 +744,7 @@ - + @@ -755,7 +755,7 @@ - + @@ -768,7 +768,7 @@ - + @@ -781,7 +781,7 @@ - + @@ -795,7 +795,7 @@ - + @@ -829,7 +829,7 @@ - + @@ -894,7 +894,7 @@ - + @@ -927,7 +927,7 @@ - + @@ -938,7 +938,7 @@ - + @@ -949,7 +949,7 @@ - + @@ -962,7 +962,7 @@ - + @@ -975,7 +975,7 @@ - + @@ -986,7 +986,7 @@ - + @@ -997,7 +997,7 @@ - + @@ -1008,7 +1008,7 @@ - + @@ -1021,7 +1021,7 @@ - + @@ -1034,7 +1034,7 @@ - + @@ -1047,7 +1047,7 @@ - + @@ -1060,7 +1060,7 @@ - + @@ -1071,7 +1071,7 @@ - + @@ -1084,7 +1084,7 @@ - + @@ -1097,7 +1097,7 @@ - + @@ -1108,7 +1108,7 @@ - + @@ -1119,7 +1119,7 @@ - + @@ -1132,7 +1132,7 @@ - + @@ -1143,7 +1143,7 @@ - + @@ -1154,7 +1154,7 @@ - + @@ -1167,7 +1167,7 @@ - + @@ -1180,7 +1180,7 @@ - + @@ -1193,7 +1193,7 @@ - + @@ -1206,7 +1206,7 @@ - + @@ -1219,7 +1219,7 @@ - + @@ -1230,7 +1230,7 @@ - + @@ -1243,7 +1243,7 @@ - + @@ -1256,7 +1256,7 @@ - + @@ -1269,7 +1269,7 @@ - + @@ -1283,7 +1283,7 @@ - + @@ -1298,7 +1298,7 @@ - + @@ -1315,7 +1315,7 @@ - + @@ -1332,7 +1332,7 @@ - + @@ -1349,7 +1349,7 @@ - + @@ -1364,7 +1364,7 @@ - + @@ -1403,7 +1403,7 @@ - + @@ -1432,7 +1432,7 @@ - + @@ -1527,7 +1527,7 @@ - + @@ -3191,7 +3191,7 @@ - + @@ -3219,7 +3219,7 @@ - + @@ -3238,11 +3238,11 @@ - + - + @@ -3252,7 +3252,7 @@ - + @@ -3262,11 +3262,11 @@ - + - + @@ -3276,7 +3276,7 @@ - + @@ -3286,7 +3286,7 @@ - + @@ -3296,7 +3296,7 @@ - + @@ -3320,7 +3320,7 @@ - + @@ -3338,7 +3338,7 @@ - + @@ -3350,7 +3350,7 @@ - + @@ -3362,7 +3362,7 @@ - + @@ -3370,11 +3370,11 @@ - + - + @@ -3397,7 +3397,7 @@ - + @@ -3423,7 +3423,7 @@ - + @@ -3444,7 +3444,7 @@ - + @@ -3474,7 +3474,7 @@ - + @@ -3488,7 +3488,7 @@ - + @@ -3515,7 +3515,7 @@ - + @@ -3554,7 +3554,7 @@ - + From 8d158fc0ded2c0dbf182e1317321a6aeeace65e5 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 16 May 2025 11:56:59 +0200 Subject: [PATCH 02/67] =?UTF-8?q?=E2=9C=A8=20added=20the=20IdReporter=20cl?= =?UTF-8?q?asses=20to=20facilitate=20outputing=20ids=20&=20their=20count?= =?UTF-8?q?=20from=20kernels=20(optionally)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 60 ++--- .../CompositionalMultiphaseHybridFVM.cpp | 4 +- .../kernels/SolutionCheckHelperKernels.hpp | 88 ------- .../kernels/SolutionCheckKernelsHelper.hpp | 224 ++++++++++++++++++ .../compositional/SolutionCheckKernel.hpp | 147 ++++++------ .../ThermalSolutionCheckKernel.hpp | 12 +- .../wells/CompositionalMultiphaseWell.cpp | 80 ++++--- .../CompositionalMultiphaseWellKernels.hpp | 8 +- 8 files changed, 370 insertions(+), 253 deletions(-) delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 4bb9f553fc8..941d4112e8b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -845,9 +845,9 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; - integer numNegPres = 0, numNegDens = 0, numNegTotalDens = 0; - std::vector< globalIndex > rankNegPressureElementIds; - std::vector< globalIndex > rankNegDensityElementIds; + integer numNegTotalDens = 0; + IdReporterBuffer< integer, globalIndex > rankNegPressureIds{ 16 }; // TODO disable if not enabled. + IdReporterBuffer< integer, globalIndex > rankNegDensityIds{ 16 }; // TODO disable if not enabled. forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -866,6 +866,10 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); + auto const & cellLocalToGlobalIds = subRegion.localToGlobalMap(); + auto const presCollector = rankNegPressureIds.createCollector(cellLocalToGlobalIds); + auto const densCollector = rankNegDensityIds.createCollector(cellLocalToGlobalIds); + // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K const integer temperatureOffset = m_numComponents+1; @@ -887,6 +891,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, dofKey, subRegion, localSolution, + presCollector, + densCollector, temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: @@ -902,48 +908,24 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, m_numComponents, dofKey, subRegion, - localSolution ); + localSolution, + presCollector, + densCollector ); localCheck = std::min( localCheck, subRegionData.localMinVal ); minPres = std::min( minPres, subRegionData.localMinPres ); minDens = std::min( minDens, subRegionData.localMinDens ); minTotalDens = std::min( minTotalDens, subRegionData.localMinTotalDens ); - // numNegPres += subRegionData.localNumNegPressures; - // numNegDens += subRegionData.localNumNegDens; numNegTotalDens += subRegionData.localNumNegTotalDens; - - // integer const numIdsToAdd = std::min( subRegionData.localNumNegPressures, - // integer( subRegionData.localNegPresElementIds.capacity() ) ); - // for( int i = 0; i < numIdsToAdd; ++i ) - // { - // rankNegPressureElementIds.emplace_back( subRegionData.localNegPresElementIds[i] ); // todo local -> global - // } - - flowSolverBaseKernels::aggregateKernelsIds( rankNegPressureElementIds, - numNegPres, - subRegionData.localNegPresElementIds, - subRegionData.localNumNegPressures ); - - flowSolverBaseKernels::aggregateKernelsIds( rankNegDensityElementIds, - numNegDens, - subRegionData.localNegDensElementIds, - subRegionData.localNumNegDens ); - - // integer const numIdsToAdd = std::min( subRegionData.localNumNegDens, - // integer( subRegionData.localNegDensElementIds.capacity() ) ); - // for( int i = 0; i < numIdsToAdd; ++i ) - // { - // rankNegDensityElementIds.emplace_back( subRegionData.localNegDensElementIds[i] ); // todo local -> global - // } } ); } ); minPres = MpiWrapper::min( minPres ); minDens = MpiWrapper::min( minDens ); minTotalDens = MpiWrapper::min( minTotalDens ); - numNegPres = MpiWrapper::sum( numNegPres ); - numNegDens = MpiWrapper::sum( numNegDens ); + integer numNegPres = MpiWrapper::sum( rankNegPressureIds.getSignaledIdsCount() ); + integer numNegDens = MpiWrapper::sum( rankNegDensityIds.getSignaledIdsCount() ); numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); if( numNegPres > 0 ) @@ -955,21 +937,20 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, GEOS_FMT( " {}: negative pressure element ids (may not be complete):", getName() ) ); MpiWrapper::barrier(); - if( !rankNegPressureElementIds.empty() ) + if( !rankNegPressureIds.empty() ) { GEOS_LOG_LEVEL( logInfo::Solution, GEOS_FMT( " Rank {}: {}", - MpiWrapper::commRank(), - stringutilities::join( rankNegPressureElementIds, ", " ) ) ); + MpiWrapper::commRank(), stringutilities::join( rankNegPressureIds, ", " ) ) ); } } string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; - if( minTotalDens > 0 ) + if( numNegTotalDens > 0 ) { GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}}", - getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + getName(), numNegTotalDens, fmt::format( "{:.{}f}", minTotalDens, 3 ), massUnit ) ); } if( numNegDens > 0 ) @@ -981,12 +962,11 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, GEOS_FMT( " {}: negative component density element ids (may not be complete):", getName() ) ); MpiWrapper::barrier(); - if( !rankNegDensityElementIds.empty() ) + if( !rankNegDensityIds.empty() ) { GEOS_LOG_LEVEL( logInfo::Solution, GEOS_FMT( " Rank {}: {}", - MpiWrapper::commRank(), - stringutilities::join( rankNegDensityElementIds, ", " ) ) ); + MpiWrapper::commRank(), stringutilities::join( rankNegDensityIds, ", " ) ) ); } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index 477215a14a7..3e0582546c1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -553,7 +553,9 @@ bool CompositionalMultiphaseHybridFVM::checkSystemSolution( DomainPartition & do m_numComponents, elemDofKey, subRegion, - localSolution ); + localSolution, + IdReporterCollector<>::disabled(), + IdReporterCollector<>::disabled() ); localCheck = std::min( localCheck, subRegionData.localMinVal ); } ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp deleted file mode 100644 index 8757759964a..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 TotalEnergies - * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2023-2024 Chevron - * Copyright (c) 2019- GEOS/GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file SolutionCheckKernel.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPERKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPERKERNELS_HPP - -#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" - -namespace geos -{ - -namespace flowSolverBaseKernels -{ - -//fonction inutile -template< typename KernelStackArray, typename IdType, typename IdCountType > -GEOS_HOST_DEVICE -void collectKernelId( KernelStackArray & idList, - IdCountType & idsCounter, - IdType id ) -{ - if( idsCounter < idList.capacity() ) - { - idList[idsCounter] = id; // ne peut avoir qu'une occurence - } - - idsCounter += 1; -} - -/** - * @brief - * @param stackBuffer - * @param kernelIds - * @param kernelIdsCount Strictly positive. - */ -template< typename OutputStackArray, typename KernelStackArray, typename IdCountType, typename ReducePolicy > -GEOS_HOST_DEVICE -void aggregateKernelsIds( OutputStackArray & outputBuffer, - T & outputIdsCounter, - KernelStackArray const & kernelIds, - IdCountType const kernelIdsCount ) -{ - IdCountType const outputBufferStart = RAJA::atomicAdd< RAJA::auto_atomic >( &outputIdsCounter, - kernelIdsCount ); - IdCountType const maxNbIdToAdd = IdCountType( outputBuffer.capacity() - outputBufferStart ); - IdCountType const nbIdToAdd = LvArray::math::min( kernelIdsCount, maxNbIdToAdd ); - for( IdCountType i = 0; i < nbIdToAdd; ++i ) - { - outputBuffer[outputBufferStart + i] = kernelIds[i]; - } -} - -template< typename OutputDynamicArray, typename InputArray, typename IdCountType > -void aggregateKernelsIds( OutputDynamicArray & outputBuffer, - IdCountType & outputIdsCounter, - InputArray const & ids, - IdCountType const idsCount ) -{ - outputIdsCounter += idsCount; - IdCountType const numIdsToAdd = std::min( idsCount, IdCountType( ids.capacity() ) ); - for( int i = 0; i < numIdsToAdd; ++i ) - { - outputBuffer.emplace_back( ids[i] ); // todo local -> global - } -} - -} // namespace flowSolverBaseKernels - -} // namespace geos - - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp new file mode 100644 index 00000000000..a5093c4d4da --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp @@ -0,0 +1,224 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 TotalEnergies + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file SolutionCheckKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPER_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPER_HPP + +#include "common/DataTypes.hpp" + +namespace geos +{ + +template< typename IdCountType, + typename IdType > +class IdReporterBuffer; + +/** + * @brief TODO + * @tparam IdCountType TODO + * @tparam IdType TODO + */ +template< typename IdCountType = integer, + typename IdType = globalIndex > +class IdReporterCollector +{ + friend class IdReporterBuffer< IdCountType, IdType >; +public: + + IdReporterCollector( IdReporterCollector const & other ) = default; + IdReporterCollector( IdReporterCollector && other ) = default; + IdReporterCollector & operator=( IdReporterCollector const & other ) = default; + IdReporterCollector & operator=( IdReporterCollector && other ) = default; + + static IdReporterCollector disabled() // -> cpp + { + return IdReporterCollector( arrayView1d< IdCountType >(), + arrayView1d< IdType >(), + arrayView1d< globalIndex >() ); + } + + /** + * @brief TODO + * @tparam CollectorAtomicPolicy The policy of the atomic increment on the ids counter. + * @param m_idsCounter The ids counter to increment with an atomic operation. + * @param m_idsBuffer The output id buffer, in the same memory space as m_idsCounter. + * If its size is 0 (= disabled output) or not not large enought, the buffer is not filled. + * @param id The Id to add to the buffer. + */ + template< typename CollectorAtomicPolicy > + GEOS_HOST_DEVICE + void collectId( CollectorAtomicPolicy, IdType id ) const + { + if( !m_idsCounter.empty() ) + { + IdCountType const outputStart = RAJA::atomicInc< CollectorAtomicPolicy >( &m_idsCounter[0] ); + + if( outputStart < m_idsBuffer.size() ) + { + m_idsBuffer[outputStart] = m_localToGlobalId[id]; + } + } + } + + // // currently unused version for adding multiple ids from a given kernel + // template< typename AddedArray, typename IdCountType > + // GEOS_HOST_DEVICE + // void collectIds( AddedArray const & newIds, IdCountType newIdsCount ) + // { + // IdCountType const outputStart = RAJA::atomicAdd< CollectorAtomicPolicy >( &m_idsCounter[0], newIdsCount ); + // IdCountType const maxNbIdToAdd = IdCountType( m_idsBuffer.size() - outputStart ); + // newIdsCount = LvArray::math::min( newIdsCount, maxNbIdToAdd ); + // for( IdCountType i = 0; i < newIdsCount; ++i ) + // { + // m_idsBuffer[outputStart + i] = newIds[i]; + // } + // } + +private: + + // array of one element to get benefit of chai managed memory. + arrayView1d< IdCountType > m_idsCounter; + + // ids of detected elements, quantity limited to 'maxIdsCount' + arrayView1d< IdType > m_idsBuffer; + + arrayView1d< globalIndex > m_localToGlobalId; + + IdReporterCollector( arrayView1d< IdCountType > const & idsCounter, + arrayView1d< IdType > const & idsArray, + arrayView1d< globalIndex > const & localToGlobalId ): // -> cpp + m_idsCounter( idsCounter ), + m_idsBuffer( idsArray ), + m_localToGlobalId( localToGlobalId ) + {} + +}; + +template< typename IdCountType = integer, + typename IdType = globalIndex > +class IdReporterBuffer +{ +public: + + /** + * @brief Construct a preallocated buffer to collect a limited quantity of ids in kernels. + * @param maxCollectionSize Limit of the buffer. + * If 0, the buffering functionnality is disabled and only the counting is enabled. + */ + IdReporterBuffer( IdCountType maxCollectionSize ): + m_idsCounter( 1 ), + m_idsBuffer( maxCollectionSize ) + { m_idsCounter.zero(); } + + IdReporterBuffer( IdReporterBuffer const & other ) = delete; + IdReporterBuffer( IdReporterBuffer && other ) = default; + IdReporterBuffer & operator=( IdReporterBuffer const & other ) = delete; + IdReporterBuffer & operator=( IdReporterBuffer && other ) = default; + + IdCountType getSignaledIdsCount() const + { return m_idsCounter[0]; } + + IdCountType getCollectedIdsCount() const + { return LvArray::math::min( m_idsCounter[0], m_idsCounter.size() ); } + + auto begin() const + { return m_idsBuffer.begin(); } + + auto end() const + { return m_idsBuffer.begin() + getCollectedIdsCount(); } + + bool empty() const + { return getCollectedIdsCount() == 0; } + + /** + * @return A view on the ids array owned by the instance. + */ + IdReporterCollector< IdCountType, IdType > + createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const // -> cpp + { return IdReporterCollector< IdCountType, IdType >( m_idsCounter, m_idsBuffer, localToGlobalId ); } + +private: + + // array of one element to get benefit of managed host-device memory. + array1d< IdCountType > m_idsCounter; + + // ids of detected elements + array1d< IdType > m_idsBuffer; + +}; + +// /** +// * @brief TODO +// * @tparam AtomicPolicy The policy of the atomic increment on idsCounter. +// * @tparam KernelStackArray TODO +// * @tparam IdType TODO +// * @tparam IdCountType TODO +// * @param idsCounter The ids counter to increment with an atomic operation. +// * @param idsBuffer The output id buffer, in the same memory space as idsCounter. +// * If its size is 0 (= disabled output) or not not large enought, the buffer is not filled. +// * @param id The Id to add to the buffer. +// * @return TODO +// */ +// template< typename AtomicPolicy, typename OutputStackArray, typename IdType, typename IdCountType > +// GEOS_HOST_DEVICE +// void collectKernelId( IdCountType & idsCounter, OutputStackArray & idsBuffer, IdType id ) +// { +// static constexpr IdCountType addingRequest = 1; +// IdCountType const idsBufferStart = RAJA::atomicAdd< AtomicPolicy >( &idsCounter, addingRequest ); +// if( idsBufferStart < idsBuffer.size() ) +// { +// idsBuffer[idsBufferStart] = kernelIds[i]; +// } +// } + +// // // currently unused version for adding multiple ids from a given kernel +// // template< typename ReducePolicy, typename OutputStackArray, typename KernelStackArray, typename IdCountType > +// // GEOS_HOST_DEVICE +// // void collectKernelIds( OutputStackArray & outputBuffer, +// // IdCountType & outputIdsCounter, +// // KernelStackArray const & kernelIds, +// // IdCountType const kernelIdsCount ) +// // { +// // IdCountType const outputBufferStart = RAJA::atomicAdd< ReducePolicy >( &outputIdsCounter, kernelIdsCount ); +// // IdCountType const maxNbIdToAdd = IdCountType( outputBuffer.capacity() - outputBufferStart ); +// // IdCountType const nbIdToAdd = LvArray::math::min( kernelIdsCount, maxNbIdToAdd ); +// // for( IdCountType i = 0; i < nbIdToAdd; ++i ) +// // { +// // outputBuffer[outputBufferStart + i] = kernelIds[i]; +// // } +// // } + +// template< typename OutputDynamicArray, typename InputArray, typename IdCountType > +// void aggregateIdsBuffers( OutputDynamicArray & outputBuffer, +// IdCountType & outputIdsCounter, +// InputArray const & ids, +// IdCountType const idsCount ) +// { +// outputIdsCounter += idsCount; +// IdCountType const numIdsToAdd = std::min( idsCount, IdCountType( ids.capacity() ) ); +// for( int i = 0; i < numIdsToAdd; ++i ) +// { +// outputBuffer.emplace_back( ids[i] ); // todo local -> global +// } +// } + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPER_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index b0d725ca2e1..8b85d2fc34c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" -#include "physicsSolvers/fluidFlow/kernels/SolutionCheckHelperKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp" namespace geos { @@ -48,7 +48,7 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer using Base::m_pressure; using Base::m_compDens; - static constexpr int maxNegValueElementIds = 16; + static constexpr int maxWrongValueIds = 16; /** * @brief Create a new kernel instance @@ -74,7 +74,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer integer const numComp, string const dofKey, ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution ) + arrayView1d< real64 const > const localSolution, + IdReporterCollector<> const & negPressureIds, + IdReporterCollector<> const & negDensityIds ) : Base( rankOffset, numComp, dofKey, @@ -87,55 +89,55 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer m_allowCompDensChopping( allowCompDensChopping ), m_allowNegativePressure( allowNegativePressure ), m_scalingFactor( scalingFactor ), - m_scalingType( scalingType ) + m_scalingType( scalingType ), + m_negPressureIds( negPressureIds ), + m_negDensityIds( negDensityIds ) {} /** - * @struct StackVariables + * @struct KernelStats * @brief Kernel variables located on the stack */ - struct StackVariables : public Base::StackVariables + struct KernelStats : public Base::StackVariables { GEOS_HOST_DEVICE - StackVariables(): - localNegPresElementIds( maxNegValueElementIds ), - localNegDensElementIds( maxNegValueElementIds ) - { } - - StackVariables( real64 _localMinVal, - real64 _localMinPres, - real64 _localMinDens, - real64 _localMinTotalDens, - integer _localNumNegPressures, - integer _localNumNegDens, - integer _localNumNegTotalDens, - stackArray1d< globalIndex, maxNegValueElementIds > _localNegPresElementIds, - stackArray1d< globalIndex, maxNegValueElementIds > _localNegDensElementIds ) + KernelStats(): + Base::StackVariables() + {} + + KernelStats( real64 _localMinVal, + real64 _localMinPres, + real64 _localMinDens, + real64 _localMinTotalDens, + integer _localNumNegTotalDens ) : Base::StackVariables( _localMinVal ), localMinPres( _localMinPres ), localMinDens( _localMinDens ), localMinTotalDens( _localMinTotalDens ), - localNumNegPressures( _localNumNegPressures ), - localNumNegDens( _localNumNegDens ), - localNumNegTotalDens( _localNumNegTotalDens ), - localNegPresElementIds( _localNegPresElementIds ), - localNegDensElementIds( _localNegDensElementIds ) + localNumNegTotalDens( _localNumNegTotalDens ) { } real64 localMinPres; real64 localMinDens; real64 localMinTotalDens; - integer localNumNegPressures; // ne peuvent être que 0 ou 1 dans chaque kernel - integer localNumNegDens; // ne peuvent être que 0 ou 1 dans chaque kernel - integer localNumNegTotalDens; // ne peuvent être que 0 ou 1 dans chaque kernel + localIndex localNumNegTotalDens; // ne peuvent être que 0 ou 1 dans chaque kernel + }; - /// limited quantity of local ids of detected solved elements with negative pressures - stackArray1d< globalIndex, maxNegValueElementIds > localNegPresElementIds; + /** + * @struct StackVariables + * @brief Kernel variables located on the stack + */ + struct StackVariables : public KernelStats + { + GEOS_HOST_DEVICE + StackVariables(): + KernelStats() + { } - /// limited quantity of local ids of detected solved elements with negative density - stackArray1d< globalIndex, maxNegValueElementIds > localNegDensElementIds; + localIndex localNumNegPres; + localIndex localNumNegDens; }; /** @@ -146,22 +148,20 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer * @param[inout] kernelComponent the kernel component providing access to the compute function */ template< typename POLICY, typename KERNEL_TYPE > - static StackVariables + static KernelStats launch( localIndex const numElems, KERNEL_TYPE const & kernelComponent ) { - RAJA::ReduceMin< ReducePolicy< POLICY >, integer > globalMinVal( 1 ); + using reducePolicy = ReducePolicy< POLICY >; + using atomicPolicy = AtomicPolicy< POLICY >; - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPres( 0.0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minDens( 0.0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minTotalDens( 0.0 ); + RAJA::ReduceMin< reducePolicy, integer > globalMinVal( 1 ); - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegPressures( 0 ); - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegDens( 0 ); - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegTotalDens( 0 ); + RAJA::ReduceMin< reducePolicy, real64 > minPres( 0.0 ); + RAJA::ReduceMin< reducePolicy, real64 > minDens( 0.0 ); + RAJA::ReduceMin< reducePolicy, real64 > minTotalDens( 0.0 ); - stackArray1d< globalIndex, maxNegValueElementIds > localNegPresElementIds; - stackArray1d< globalIndex, maxNegValueElementIds > localNegDensElementIds; + RAJA::ReduceSum< reducePolicy, localIndex > numNegTotalDens( 0 ); forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) { @@ -170,7 +170,7 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer return; } - StackVariables stack; + StackVariables stack{}; kernelComponent.setup( ei, stack ); kernelComponent.compute( ei, stack ); @@ -180,33 +180,20 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer minDens.min( stack.localMinDens ); minTotalDens.min( stack.localMinTotalDens ); - if( stack.localNumNegPressures > 0 ) - { - flowSolverBaseKernels::aggregateKernelsIds( localNegPresElementIds, - numNegPressures, - stack.localNegPresElementIds, - integer( stack.localNumNegPressures ) ); - } + if( stack.localNumNegPres > 0 ) + kernelComponent.m_negPressureIds.collectId( atomicPolicy{}, ei ); if( stack.localNumNegDens > 0 ) - { - flowSolverBaseKernels::aggregateKernelsIds( localNegDensElementIds, - numNegDens, - stack.localNegDensElementIds, - stack.localNumNegDens ); - } + kernelComponent.m_negDensityIds.collectId( atomicPolicy{}, ei ); + numNegTotalDens += stack.localNumNegTotalDens; } ); - return StackVariables( globalMinVal.get(), - minPres.get(), - minDens.get(), - minTotalDens.get(), - numNegPressures.get(), - numNegDens.get(), - numNegTotalDens.get(), - localNegPresElementIds, - localNegDensElementIds ); + return KernelStats( globalMinVal.get(), + minPres.get(), + minDens.get(), + minTotalDens.get(), + numNegTotalDens.get() ); } GEOS_HOST_DEVICE @@ -219,7 +206,7 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer stack.localMinDens = 0.0; stack.localMinTotalDens = 0.0; - stack.localNumNegPressures = 0; + stack.localNumNegPres = 0; stack.localNumNegDens = 0; stack.localNumNegTotalDens = 0; } @@ -254,14 +241,10 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer real64 const newPres = m_pressure[ei] + (localScaling ? m_pressureScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow]; if( newPres < 0 ) { + stack.localNumNegPres = 1; + if( !m_allowNegativePressure ) - { stack.localMinVal = 0; - } - - flowSolverBaseKernels::collectKernelId( stack.localNegPresElementIds, - stack.localNumNegPressures, - globalIndex( ei ) ); if( newPres < stack.localMinPres ) stack.localMinPres = newPres; @@ -277,12 +260,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer real64 const newDens = m_compDens[ei][ic] + (localScaling ? m_compDensScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow + ic + 1]; if( newDens < 0 ) { + stack.localNumNegDens = 1; stack.localMinVal = 0; - flowSolverBaseKernels::collectKernelId( stack.localNegDensElementIds, - stack.localNumNegDens, - ei ); - if( newDens < stack.localMinDens ) stack.localMinDens = newDens; } @@ -298,8 +278,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer } if( totalDens < 0 ) { + stack.localNumNegTotalDens = 1; stack.localMinVal = 0; - stack.localNumNegTotalDens += 1; + if( totalDens < stack.localMinTotalDens ) stack.localMinTotalDens = totalDens; } @@ -322,6 +303,10 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer /// scaling type (global or local) compositionalMultiphaseUtilities::ScalingType const m_scalingType; + IdReporterCollector<> m_negPressureIds; + + IdReporterCollector<> m_negDensityIds; + }; /** @@ -343,7 +328,7 @@ class SolutionCheckKernelFactory * @param[in] localSolution the Newton update */ template< typename POLICY > - static SolutionCheckKernel::StackVariables + static SolutionCheckKernel::KernelStats createAndLaunch( integer const allowCompDensChopping, integer const allowNegativePressure, compositionalMultiphaseUtilities::ScalingType const scalingType, @@ -356,11 +341,13 @@ class SolutionCheckKernelFactory integer const numComp, string const dofKey, ElementSubRegionBase & subRegion, - arrayView1d< real64 const > const localSolution ) + arrayView1d< real64 const > const localSolution, + IdReporterCollector<> const & negPressureIds, + IdReporterCollector<> const & negDensityIds ) // TODO : ajouter bool reportWrongValues { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset, - numComp, dofKey, subRegion, localSolution ); + numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds ); return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp index b0447b33782..f9bb9851dfa 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp @@ -73,6 +73,8 @@ class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels: string const dofKey, ElementSubRegionBase const & subRegion, arrayView1d< real64 const > const localSolution, + IdReporterCollector<> const & negPressureIds, + IdReporterCollector<> const & negDensityIds, integer const temperatureOffset ) : Base( allowCompDensChopping, allowNegativePressure, @@ -86,7 +88,9 @@ class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels: numComp, dofKey, subRegion, - localSolution ), + localSolution, + negPressureIds, + negDensityIds ), m_temperature( temperature ), m_temperatureScalingFactor( temperatureScalingFactor ), m_temperatureOffset( temperatureOffset ) @@ -146,7 +150,7 @@ class SolutionCheckKernelFactory * @param[in] localSolution the Newton update */ template< typename POLICY > - static SolutionCheckKernel::StackVariables + static SolutionCheckKernel::KernelStats createAndLaunch( integer const allowCompDensChopping, integer const allowNegativePressure, compositionalMultiphaseUtilities::ScalingType const scalingType, @@ -162,11 +166,13 @@ class SolutionCheckKernelFactory string const dofKey, ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, + IdReporterCollector<> const & negPressureIds, + IdReporterCollector<> const & negDensityIds, integer temperatureOffset ) { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, pressure, temperature, compDens, pressureScalingFactor, compDensScalingFactor, temperatureScalingFactor, - rankOffset, numComp, dofKey, subRegion, localSolution, + rankOffset, numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds, temperatureOffset ); return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 77ee9ca0f29..072fcf0077b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1536,7 +1536,9 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, m_numComponents, wellDofKey, subRegion, - localSolution ); + localSolution, + IdReporterCollector<>::disabled(), + IdReporterCollector<>::disabled() ); if( !subRegionData.localMinVal ) { @@ -1578,49 +1580,50 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K const integer temperatureOffset = m_numComponents+2; - auto const subRegionData = - m_isThermal - ? thermalCompositionalMultiphaseBaseKernels:: - SolutionCheckKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - temperature, - compDens, - pressureScalingFactor, - temperatureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - wellDofKey, - subRegion, - localSolution, - temperatureOffset ) - : isothermalCompositionalMultiphaseBaseKernels:: - SolutionCheckKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - wellDofKey, - subRegion, - localSolution ); + auto const subRegionData = m_isThermal ? + thermalCompositionalMultiphaseBaseKernels:: + SolutionCheckKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + temperature, + compDens, + pressureScalingFactor, + temperatureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + wellDofKey, + subRegion, + localSolution, + IdReporterCollector<>::disabled(), + IdReporterCollector<>::disabled(), + temperatureOffset ) : + isothermalCompositionalMultiphaseBaseKernels:: + SolutionCheckKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + wellDofKey, + subRegion, + localSolution, + IdReporterCollector<>::disabled(), + IdReporterCollector<>::disabled() ); localCheck = std::min( localCheck, subRegionData.localMinVal ); minPres = std::min( minPres, subRegionData.localMinPres ); minDens = std::min( minDens, subRegionData.localMinDens ); minTotalDens = std::min( minTotalDens, subRegionData.localMinTotalDens ); - numNegPres += subRegionData.localNumNegPressures; - numNegDens += subRegionData.localNumNegDens; numNegTotalDens += subRegionData.localNumNegTotalDens; } ); } ); @@ -1632,6 +1635,7 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, numNegDens = MpiWrapper::sum( numNegDens ); numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); + // TODO stats comme les autres if( numNegPres > 0 ) GEOS_LOG_LEVEL_RANK_0( logInfo::WellValidity, GEOS_FMT( " {}: Number of negative well pressure values: {}, minimum value: {} Pa", diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index 7aa4cb2c49b..a5b96d6c77b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -808,7 +808,7 @@ class SolutionCheckKernelFactory * @param[in] localSolution the Newton update */ template< typename POLICY > - static isothermalCompositionalMultiphaseBaseKernels::SolutionCheckKernel::StackVariables + static isothermalCompositionalMultiphaseBaseKernels::SolutionCheckKernel::KernelStats createAndLaunch( integer const allowCompDensChopping, compositionalMultiphaseUtilities::ScalingType const scalingType, real64 const scalingFactor, @@ -820,13 +820,15 @@ class SolutionCheckKernelFactory integer const numComp, string const dofKey, ElementSubRegionBase & subRegion, - arrayView1d< real64 const > const localSolution ) + arrayView1d< real64 const > const localSolution, + IdReporterCollector<> const & negPressureIds, + IdReporterCollector<> const & negDensityIds ) { isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernel kernel( allowCompDensChopping, 0, scalingType, scalingFactor, pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset, - numComp, dofKey, subRegion, localSolution ); + numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds ); return isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernel:: launch< POLICY >( subRegion.size(), kernel ); From 1434bd389f2db1f2cc9b060e798baae5a0cd9cfb Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 16 May 2025 12:09:57 +0200 Subject: [PATCH 03/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20removing=20unnecessa?= =?UTF-8?q?ry=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 4 ++-- .../CompositionalMultiphaseHybridFVM.cpp | 4 ++-- .../kernels/SolutionCheckKernelsHelper.hpp | 21 +++++++++---------- .../compositional/SolutionCheckKernel.hpp | 12 +++++------ .../ThermalSolutionCheckKernel.hpp | 8 +++---- .../wells/CompositionalMultiphaseWell.cpp | 12 +++++------ .../CompositionalMultiphaseWellKernels.hpp | 4 ++-- 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 941d4112e8b..6371cbeb15d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -846,8 +846,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; - IdReporterBuffer< integer, globalIndex > rankNegPressureIds{ 16 }; // TODO disable if not enabled. - IdReporterBuffer< integer, globalIndex > rankNegDensityIds{ 16 }; // TODO disable if not enabled. + IdReporterBuffer rankNegPressureIds{ 16 }; // TODO disable if not enabled. + IdReporterBuffer rankNegDensityIds{ 16 }; // TODO disable if not enabled. forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index 3e0582546c1..eec6b106efe 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -554,8 +554,8 @@ bool CompositionalMultiphaseHybridFVM::checkSystemSolution( DomainPartition & do elemDofKey, subRegion, localSolution, - IdReporterCollector<>::disabled(), - IdReporterCollector<>::disabled() ); + IdReporterCollector::disabled(), + IdReporterCollector::disabled() ); localCheck = std::min( localCheck, subRegionData.localMinVal ); } ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp index a5093c4d4da..49009735196 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp @@ -25,8 +25,6 @@ namespace geos { -template< typename IdCountType, - typename IdType > class IdReporterBuffer; /** @@ -34,13 +32,14 @@ class IdReporterBuffer; * @tparam IdCountType TODO * @tparam IdType TODO */ -template< typename IdCountType = integer, - typename IdType = globalIndex > class IdReporterCollector { - friend class IdReporterBuffer< IdCountType, IdType >; + friend class IdReporterBuffer; public: + using IdCountType = int32_t; + using IdType = globalIndex; + IdReporterCollector( IdReporterCollector const & other ) = default; IdReporterCollector( IdReporterCollector && other ) = default; IdReporterCollector & operator=( IdReporterCollector const & other ) = default; @@ -110,12 +109,13 @@ class IdReporterCollector }; -template< typename IdCountType = integer, - typename IdType = globalIndex > class IdReporterBuffer { public: + using IdCountType = int32_t; + using IdType = globalIndex; + /** * @brief Construct a preallocated buffer to collect a limited quantity of ids in kernels. * @param maxCollectionSize Limit of the buffer. @@ -147,11 +147,10 @@ class IdReporterBuffer { return getCollectedIdsCount() == 0; } /** - * @return A view on the ids array owned by the instance. + * @return A view on the ids array owned by the instance. -> change comment to explain the interest for kernels */ - IdReporterCollector< IdCountType, IdType > - createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const // -> cpp - { return IdReporterCollector< IdCountType, IdType >( m_idsCounter, m_idsBuffer, localToGlobalId ); } + IdReporterCollector createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const // -> cpp + { return IdReporterCollector( m_idsCounter, m_idsBuffer, localToGlobalId ); } private: diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 8b85d2fc34c..1453ab87976 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -75,8 +75,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer string const dofKey, ElementSubRegionBase const & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector<> const & negPressureIds, - IdReporterCollector<> const & negDensityIds ) + IdReporterCollector const & negPressureIds, + IdReporterCollector const & negDensityIds ) : Base( rankOffset, numComp, dofKey, @@ -303,9 +303,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer /// scaling type (global or local) compositionalMultiphaseUtilities::ScalingType const m_scalingType; - IdReporterCollector<> m_negPressureIds; + IdReporterCollector m_negPressureIds; - IdReporterCollector<> m_negDensityIds; + IdReporterCollector m_negDensityIds; }; @@ -342,8 +342,8 @@ class SolutionCheckKernelFactory string const dofKey, ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector<> const & negPressureIds, - IdReporterCollector<> const & negDensityIds ) // TODO : ajouter bool reportWrongValues + IdReporterCollector const & negPressureIds, + IdReporterCollector const & negDensityIds ) // TODO : ajouter bool reportWrongValues { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp index f9bb9851dfa..283702a665d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp @@ -73,8 +73,8 @@ class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels: string const dofKey, ElementSubRegionBase const & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector<> const & negPressureIds, - IdReporterCollector<> const & negDensityIds, + IdReporterCollector const & negPressureIds, + IdReporterCollector const & negDensityIds, integer const temperatureOffset ) : Base( allowCompDensChopping, allowNegativePressure, @@ -166,8 +166,8 @@ class SolutionCheckKernelFactory string const dofKey, ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector<> const & negPressureIds, - IdReporterCollector<> const & negDensityIds, + IdReporterCollector const & negPressureIds, + IdReporterCollector const & negDensityIds, integer temperatureOffset ) { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 072fcf0077b..e1182be2377 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1537,8 +1537,8 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, wellDofKey, subRegion, localSolution, - IdReporterCollector<>::disabled(), - IdReporterCollector<>::disabled() ); + IdReporterCollector::disabled(), + IdReporterCollector::disabled() ); if( !subRegionData.localMinVal ) { @@ -1598,8 +1598,8 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, wellDofKey, subRegion, localSolution, - IdReporterCollector<>::disabled(), - IdReporterCollector<>::disabled(), + IdReporterCollector::disabled(), + IdReporterCollector::disabled(), temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: @@ -1616,8 +1616,8 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, wellDofKey, subRegion, localSolution, - IdReporterCollector<>::disabled(), - IdReporterCollector<>::disabled() ); + IdReporterCollector::disabled(), + IdReporterCollector::disabled() ); localCheck = std::min( localCheck, subRegionData.localMinVal ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index a5b96d6c77b..5c985e67efc 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -821,8 +821,8 @@ class SolutionCheckKernelFactory string const dofKey, ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector<> const & negPressureIds, - IdReporterCollector<> const & negDensityIds ) + IdReporterCollector const & negPressureIds, + IdReporterCollector const & negDensityIds ) { isothermalCompositionalMultiphaseBaseKernels:: From cb0ae03efeef7fff41d2378e11e97d1c254174ca Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 16 May 2025 12:34:53 +0200 Subject: [PATCH 04/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20proper=20cpp/hpp=20f?= =?UTF-8?q?ile=20repartition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 4 +- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 1 + .../fluidFlow/SolutionCheckHelpers.cpp | 34 ++++++++ .../fluidFlow/SolutionCheckHelpers.hpp | 85 +++++++++++++++++++ ...er.hpp => SolutionCheckKernelsHelpers.hpp} | 58 +------------ .../compositional/SolutionCheckKernel.hpp | 2 +- 6 files changed, 127 insertions(+), 57 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{SolutionCheckKernelsHelper.hpp => SolutionCheckKernelsHelpers.hpp} (78%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 82bda960652..3bcf8745946 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -37,11 +37,12 @@ set( fluidFlowSolvers_headers SinglePhaseHybridFVM.hpp SinglePhaseProppantBase.hpp StencilAccessors.hpp + SolutionCheckHelpers.hpp StencilDataCollection.hpp LogLevelsInfo.hpp kernels/MinPoreVolumeMaxPorosityKernel.hpp + kernels/SolutionCheckKernelsHelpers.hpp kernels/StencilWeightsUpdateKernel.hpp - kernels/SolutionCheckHelperKernels.hpp kernels/HybridFVMHelperKernels.hpp kernels/singlePhase/AccumulationKernels.hpp kernels/singlePhase/AquiferBCKernel.hpp @@ -136,6 +137,7 @@ set( fluidFlowSolvers_sources SinglePhaseHybridFVM.cpp SinglePhaseProppantBase.cpp SourceFluxStatistics.cpp + SolutionCheckHelpers.cpp StencilDataCollection.cpp kernels/singlePhase/proppant/ProppantFluxKernels.cpp kernels/compositional/AquiferBCKernel.cpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 6371cbeb15d..0d5d39323c1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -38,6 +38,7 @@ #include "physicsSolvers/LogLevelsInfo.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp new file mode 100644 index 00000000000..e2ef21f8ea7 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -0,0 +1,34 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 TotalEnergies + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file SolutionCheckKernel.hpp + */ + +#include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" + +namespace geos +{ + +IdReporterBuffer::IdReporterBuffer( IdCountType maxCollectionSize ): + m_idsCounter( 1 ), + m_idsBuffer( maxCollectionSize ) +{ + m_idsCounter.zero(); + m_idsBuffer.zero(); +} + + +} // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp new file mode 100644 index 00000000000..f94e171f2d6 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -0,0 +1,85 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 TotalEnergies + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file SolutionCheckHelpers.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPER_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPER_HPP + +#include "physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp" + +namespace geos +{ + +class IdReporterBuffer +{ +public: + + using IdCountType = int32_t; + using IdType = globalIndex; + + /** + * @brief Construct a preallocated buffer to collect a limited quantity of ids in kernels. + * @param maxCollectionSize Limit of the buffer. + * If 0, the buffering functionnality is disabled and only the counting is enabled. + */ + IdReporterBuffer( IdCountType maxCollectionSize ); + + // TODO: Proper docs. can be moved without any issue. + IdReporterBuffer( IdReporterBuffer && other ) = default; + IdReporterBuffer & operator=( IdReporterBuffer && other ) = default; + + // TODO: Proper docs. copying prevented has it doesn't seem useful / relevant. + IdReporterBuffer( IdReporterBuffer const & other ) = delete; + IdReporterBuffer & operator=( IdReporterBuffer const & other ) = delete; + + IdCountType getSignaledIdsCount() const + { return m_idsCounter[0]; } + + IdCountType getCollectedIdsCount() const + { return LvArray::math::min( m_idsCounter[0], m_idsCounter.size() ); } + + auto begin() const + { return m_idsBuffer.begin(); } + + auto end() const + { return m_idsBuffer.begin() + getCollectedIdsCount(); } + + bool empty() const + { return getCollectedIdsCount() == 0; } + + /** + * @return A view on the ids array owned by the instance. -> change comment to explain the interest for kernels + */ + IdReporterCollector createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const // -> cpp + { return IdReporterCollector( m_idsCounter, m_idsBuffer, localToGlobalId ); } + +private: + + // array of one element to get benefit of managed host-device memory. + array1d< IdCountType > m_idsCounter; + + // ids of detected elements + array1d< IdType > m_idsBuffer; + +}; + + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPER_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp similarity index 78% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 49009735196..01075187f7d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -14,7 +14,7 @@ */ /** - * @file SolutionCheckKernel.hpp + * @file SolutionCheckKernelsHelpers.hpp */ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPER_HPP @@ -40,6 +40,7 @@ class IdReporterCollector using IdCountType = int32_t; using IdType = globalIndex; + // TODO : proper docs. can be copied & moved as this class only has views to the internal chai memory buffers IdReporterCollector( IdReporterCollector const & other ) = default; IdReporterCollector( IdReporterCollector && other ) = default; IdReporterCollector & operator=( IdReporterCollector const & other ) = default; @@ -101,7 +102,7 @@ class IdReporterCollector IdReporterCollector( arrayView1d< IdCountType > const & idsCounter, arrayView1d< IdType > const & idsArray, - arrayView1d< globalIndex > const & localToGlobalId ): // -> cpp + arrayView1d< globalIndex > const & localToGlobalId ): m_idsCounter( idsCounter ), m_idsBuffer( idsArray ), m_localToGlobalId( localToGlobalId ) @@ -109,59 +110,6 @@ class IdReporterCollector }; -class IdReporterBuffer -{ -public: - - using IdCountType = int32_t; - using IdType = globalIndex; - - /** - * @brief Construct a preallocated buffer to collect a limited quantity of ids in kernels. - * @param maxCollectionSize Limit of the buffer. - * If 0, the buffering functionnality is disabled and only the counting is enabled. - */ - IdReporterBuffer( IdCountType maxCollectionSize ): - m_idsCounter( 1 ), - m_idsBuffer( maxCollectionSize ) - { m_idsCounter.zero(); } - - IdReporterBuffer( IdReporterBuffer const & other ) = delete; - IdReporterBuffer( IdReporterBuffer && other ) = default; - IdReporterBuffer & operator=( IdReporterBuffer const & other ) = delete; - IdReporterBuffer & operator=( IdReporterBuffer && other ) = default; - - IdCountType getSignaledIdsCount() const - { return m_idsCounter[0]; } - - IdCountType getCollectedIdsCount() const - { return LvArray::math::min( m_idsCounter[0], m_idsCounter.size() ); } - - auto begin() const - { return m_idsBuffer.begin(); } - - auto end() const - { return m_idsBuffer.begin() + getCollectedIdsCount(); } - - bool empty() const - { return getCollectedIdsCount() == 0; } - - /** - * @return A view on the ids array owned by the instance. -> change comment to explain the interest for kernels - */ - IdReporterCollector createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const // -> cpp - { return IdReporterCollector( m_idsCounter, m_idsBuffer, localToGlobalId ); } - -private: - - // array of one element to get benefit of managed host-device memory. - array1d< IdCountType > m_idsCounter; - - // ids of detected elements - array1d< IdType > m_idsBuffer; - -}; - // /** // * @brief TODO // * @tparam AtomicPolicy The policy of the atomic increment on idsCounter. diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 1453ab87976..958b71cacb4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" -#include "physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp" namespace geos { From 96cd0a844cabf0e7465fc9d046edee117890e9ae Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 16 May 2025 18:10:08 +0200 Subject: [PATCH 05/67] =?UTF-8?q?=E2=9C=A8=20activation=20de=20l'output=20?= =?UTF-8?q?des=20valeurs=20probl=C3=A9matique=20en=20f=C2=B0=20d'un=20nouv?= =?UTF-8?q?eau=20logLevel=20"SolutionDetails"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/LogLevelsInfo.hpp | 6 ++ .../fluidFlow/CompositionalMultiphaseFVM.cpp | 57 +++++------------- .../fluidFlow/SolutionCheckHelpers.cpp | 59 +++++++++++++++++-- .../fluidFlow/SolutionCheckHelpers.hpp | 40 ++++++++++--- .../kernels/SolutionCheckKernelsHelpers.hpp | 4 +- 5 files changed, 109 insertions(+), 57 deletions(-) diff --git a/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp b/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp index e506139cfe7..017f69babf3 100644 --- a/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp +++ b/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp @@ -96,6 +96,12 @@ struct Solution static constexpr std::string_view getDescription() { return "Solution information (scaling, maximum changes, quality check)"; } }; +struct SolutionDetails +{ + static constexpr int getMinLogLevel() { return 2; } + static constexpr std::string_view getDescription() { return "Solution details (negative values ids)"; } +}; + struct SolverInitialization { static constexpr int getMinLogLevel() { return 1; } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 0d5d39323c1..706179eaab5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -847,8 +847,10 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; - IdReporterBuffer rankNegPressureIds{ 16 }; // TODO disable if not enabled. - IdReporterBuffer rankNegDensityIds{ 16 }; // TODO disable if not enabled. + IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; + IdReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -868,8 +870,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); auto const & cellLocalToGlobalIds = subRegion.localToGlobalMap(); - auto const presCollector = rankNegPressureIds.createCollector(cellLocalToGlobalIds); - auto const densCollector = rankNegDensityIds.createCollector(cellLocalToGlobalIds); + auto const presCollector = rankNegPressureIds.createCollector( cellLocalToGlobalIds ); + auto const densCollector = rankNegDensityIds.createCollector( cellLocalToGlobalIds ); // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K @@ -925,50 +927,21 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, minPres = MpiWrapper::min( minPres ); minDens = MpiWrapper::min( minDens ); minTotalDens = MpiWrapper::min( minTotalDens ); - integer numNegPres = MpiWrapper::sum( rankNegPressureIds.getSignaledIdsCount() ); - integer numNegDens = MpiWrapper::sum( rankNegDensityIds.getSignaledIdsCount() ); numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); - if( numNegPres > 0 ) - { - GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, - GEOS_FMT( " {}: Number of negative pressure values: {}, minimum value: {} Pa", - getName(), numNegPres, fmt::format( "{:.{}f}", minPres, 3 ) ) ); - GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, - GEOS_FMT( " {}: negative pressure element ids (may not be complete):", - getName() ) ); - MpiWrapper::barrier(); - if( !rankNegPressureIds.empty() ) - { - GEOS_LOG_LEVEL( logInfo::Solution, - GEOS_FMT( " Rank {}: {}", - MpiWrapper::commRank(), stringutilities::join( rankNegPressureIds, ", " ) ) ); - } - } + units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; - string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; - if( numNegTotalDens > 0 ) - { - GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, - GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}}", - getName(), numNegTotalDens, fmt::format( "{:.{}f}", minTotalDens, 3 ), massUnit ) ); - } + rankNegPressureIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + "negative pressure", minPres, units::Unit::Pressure ); + + rankNegDensityIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + "negative component density", minDens, massUnit ); - if( numNegDens > 0 ) + if( numNegTotalDens > 0 ) { GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, - GEOS_FMT( " {}: Number of negative component density values: {}, minimum value: {} {}}", - getName(), numNegDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); - GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, - GEOS_FMT( " {}: negative component density element ids (may not be complete):", - getName() ) ); - MpiWrapper::barrier(); - if( !rankNegDensityIds.empty() ) - { - GEOS_LOG_LEVEL( logInfo::Solution, - GEOS_FMT( " Rank {}: {}", - MpiWrapper::commRank(), stringutilities::join( rankNegDensityIds, ", " ) ) ); - } + GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}", + getName(), numNegTotalDens, fmt::format( "{:.{}f}", minTotalDens, 3 ), units::getSymbol( massUnit ) ) ); } return MpiWrapper::min( localCheck ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index e2ef21f8ea7..25c2a77825d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -18,17 +18,66 @@ */ #include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" +#include "common/MpiWrapper.hpp" +#include "common/format/StringUtilities.hpp" namespace geos { -IdReporterBuffer::IdReporterBuffer( IdCountType maxCollectionSize ): - m_idsCounter( 1 ), - m_idsBuffer( maxCollectionSize ) +IdReporterBuffer::IdReporterBuffer( bool enabled, IdCountType maxCollectionSize ): + m_idsCounter( enabled ? 1 : 0 ), + m_idsBuffer( enabled ? maxCollectionSize : 0 ) { - m_idsCounter.zero(); - m_idsBuffer.zero(); + if( enabled ) + { + m_idsCounter.zero(); + m_idsBuffer.zero(); + } } +IdReporterCollector IdReporterBuffer::createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const +{ + return IdReporterCollector( m_idsCounter, m_idsBuffer, localToGlobalId ); +} + +IdReporterOutput IdReporterBuffer::createOutput() const +{ + return IdReporterOutput( *this ); +} + + +IdReporterOutput::IdReporterOutput( IdReporterBuffer const & buffer ): + m_buffer( buffer ) +{} + +void IdReporterOutput::outputWrongValues( string_view linesPrefix, + string_view valueNaming, + real64 minValue, + units::Unit unit ) const +{ + if( m_buffer.enabled() ) + { + integer numNegativeValues = MpiWrapper::sum( m_buffer.getSignaledIdsCount() ); + if( numNegativeValues > 0 ) + { + string const minValueStr = GEOS_FMT( "{:.{}f} [{}]", minValue, 3, units::getSymbol( unit ) ); + GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", + linesPrefix, numNegativeValues, valueNaming, minValueStr ) ); + GEOS_LOG_RANK_0( GEOS_FMT( "{}{} element ids:", + linesPrefix, valueNaming ) ); + + MpiWrapper::barrier(); + if( m_buffer.getCollectedIdsCount() > 0 ) + { + GEOS_LOG( GEOS_FMT( "{}- rank {} ({} values): {} {}", + string( ' ', linesPrefix.size() ), + MpiWrapper::commRank(), + m_buffer.getSignaledIdsCount(), + stringutilities::join( m_buffer, ", " ), + ( m_buffer.isComplete() ? "..." : "." ) ) ); + } + } + } +} } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index f94e171f2d6..95f1ee2f5d2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -17,14 +17,32 @@ * @file SolutionCheckHelpers.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPER_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPER_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPERS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPERS_HPP #include "physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp" +#include "common/Units.hpp" namespace geos { +class IdReporterOutput +{ +public: + + IdReporterOutput( IdReporterBuffer const & buffer ); + + void outputWrongValues( string_view linesPrefix, + string_view valueNaming, + real64 minValue, + units::Unit valueUnit ) const; + +private: + + IdReporterBuffer const & m_buffer; + +}; + class IdReporterBuffer { public: @@ -37,7 +55,7 @@ class IdReporterBuffer * @param maxCollectionSize Limit of the buffer. * If 0, the buffering functionnality is disabled and only the counting is enabled. */ - IdReporterBuffer( IdCountType maxCollectionSize ); + IdReporterBuffer( bool enabled, IdCountType maxCollectionSize ); // TODO: Proper docs. can be moved without any issue. IdReporterBuffer( IdReporterBuffer && other ) = default; @@ -48,10 +66,10 @@ class IdReporterBuffer IdReporterBuffer & operator=( IdReporterBuffer const & other ) = delete; IdCountType getSignaledIdsCount() const - { return m_idsCounter[0]; } + { return m_idsCounter.empty() ? 0 : m_idsCounter[0]; } IdCountType getCollectedIdsCount() const - { return LvArray::math::min( m_idsCounter[0], m_idsCounter.size() ); } + { return LvArray::math::min( getSignaledIdsCount(), m_idsBuffer.size() ); } auto begin() const { return m_idsBuffer.begin(); } @@ -59,14 +77,21 @@ class IdReporterBuffer auto end() const { return m_idsBuffer.begin() + getCollectedIdsCount(); } + bool enabled() const + { return !m_idsCounter.empty(); } + bool empty() const { return getCollectedIdsCount() == 0; } + bool isComplete() const + { return getCollectedIdsCount() < getSignaledIdsCount(); } + /** * @return A view on the ids array owned by the instance. -> change comment to explain the interest for kernels */ - IdReporterCollector createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const // -> cpp - { return IdReporterCollector( m_idsCounter, m_idsBuffer, localToGlobalId ); } + IdReporterCollector createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const; + + IdReporterOutput createOutput() const; private: @@ -78,7 +103,6 @@ class IdReporterBuffer }; - } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 01075187f7d..05a45f90bf5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -17,8 +17,8 @@ * @file SolutionCheckKernelsHelpers.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPER_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPER_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPERS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPERS_HPP #include "common/DataTypes.hpp" From 5cf681482329ec2fd28aad90acc2a5d5b1160d0a Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 19 May 2025 15:40:18 +0200 Subject: [PATCH 06/67] =?UTF-8?q?=F0=9F=92=84=20slight=20msg=20change=20/?= =?UTF-8?q?=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 25c2a77825d..5c50d9aad64 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -57,20 +57,20 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, { if( m_buffer.enabled() ) { - integer numNegativeValues = MpiWrapper::sum( m_buffer.getSignaledIdsCount() ); - if( numNegativeValues > 0 ) + integer numWrongValues = MpiWrapper::sum( m_buffer.getSignaledIdsCount() ); + if( numWrongValues > 0 ) { string const minValueStr = GEOS_FMT( "{:.{}f} [{}]", minValue, 3, units::getSymbol( unit ) ); GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", - linesPrefix, numNegativeValues, valueNaming, minValueStr ) ); + linesPrefix, numWrongValues, valueNaming, minValueStr ) ); GEOS_LOG_RANK_0( GEOS_FMT( "{}{} element ids:", linesPrefix, valueNaming ) ); MpiWrapper::barrier(); if( m_buffer.getCollectedIdsCount() > 0 ) { - GEOS_LOG( GEOS_FMT( "{}- rank {} ({} values): {} {}", - string( ' ', linesPrefix.size() ), + GEOS_LOG( GEOS_FMT( "{}- rank {}, {} values: {} {}", + string( linesPrefix.size(), ' ' ), MpiWrapper::commRank(), m_buffer.getSignaledIdsCount(), stringutilities::join( m_buffer, ", " ), From 4ebe3308a3e1486c85411c2ecfaf7ae981fb24e0 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 19 May 2025 15:48:26 +0200 Subject: [PATCH 07/67] =?UTF-8?q?=F0=9F=92=84=20slight=20msg=20change=20/?= =?UTF-8?q?=20fix=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 5c50d9aad64..71197efb776 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -69,7 +69,7 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, MpiWrapper::barrier(); if( m_buffer.getCollectedIdsCount() > 0 ) { - GEOS_LOG( GEOS_FMT( "{}- rank {}, {} values: {} {}", + GEOS_LOG( GEOS_FMT( "{}- rank {}, {} values: {}{}", string( linesPrefix.size(), ' ' ), MpiWrapper::commRank(), m_buffer.getSignaledIdsCount(), From 14a546fbb1eb3ef5254207058be2c63fbb2a8fb6 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 19 May 2025 16:10:47 +0200 Subject: [PATCH 08/67] =?UTF-8?q?=F0=9F=92=84=20adding=20msg=20precisions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SolutionCheckHelpers.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 71197efb776..d9ea0fb0574 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -57,18 +57,18 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, { if( m_buffer.enabled() ) { - integer numWrongValues = MpiWrapper::sum( m_buffer.getSignaledIdsCount() ); - if( numWrongValues > 0 ) + integer numSignaledWrongValues = MpiWrapper::sum( m_buffer.getSignaledIdsCount() ); + if( numSignaledWrongValues > 0 ) { string const minValueStr = GEOS_FMT( "{:.{}f} [{}]", minValue, 3, units::getSymbol( unit ) ); GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", - linesPrefix, numWrongValues, valueNaming, minValueStr ) ); - GEOS_LOG_RANK_0( GEOS_FMT( "{}{} element ids:", - linesPrefix, valueNaming ) ); + linesPrefix, numSignaledWrongValues, valueNaming, minValueStr ) ); - MpiWrapper::barrier(); - if( m_buffer.getCollectedIdsCount() > 0 ) + if( MpiWrapper::sum( m_buffer.getCollectedIdsCount() ) > 0 ) { + GEOS_LOG_RANK_0( GEOS_FMT( "{}{} element ids:", + linesPrefix, valueNaming ) ); + MpiWrapper::barrier(); GEOS_LOG( GEOS_FMT( "{}- rank {}, {} values: {}{}", string( linesPrefix.size(), ' ' ), MpiWrapper::commRank(), @@ -76,6 +76,10 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, stringutilities::join( m_buffer, ", " ), ( m_buffer.isComplete() ? "..." : "." ) ) ); } + else { + GEOS_LOG_RANK_0( GEOS_FMT( "{}Id listing of {} elements not shown, increase the log-level if needed.", + linesPrefix, valueNaming ) ); + } } } } From 18703e3ef100a37c09ea9b8a057c9949a3e4b25a Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 20 May 2025 11:28:20 +0200 Subject: [PATCH 09/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactors=20to=20pre?= =?UTF-8?q?vent=20computing=20mpi=20reduction=20twice=20+=20constness=20+?= =?UTF-8?q?=20naming?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 22 ++++----- .../fluidFlow/SolutionCheckHelpers.cpp | 16 ++++--- .../fluidFlow/SolutionCheckHelpers.hpp | 19 ++++++-- .../kernels/SolutionCheckKernelsHelpers.hpp | 8 ++-- .../compositional/SolutionCheckKernel.hpp | 46 +++++++++---------- 5 files changed, 62 insertions(+), 49 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 706179eaab5..766e41ca146 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -870,8 +870,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); auto const & cellLocalToGlobalIds = subRegion.localToGlobalMap(); - auto const presCollector = rankNegPressureIds.createCollector( cellLocalToGlobalIds ); - auto const densCollector = rankNegDensityIds.createCollector( cellLocalToGlobalIds ); + auto const negPresCollector = rankNegPressureIds.createCollector( cellLocalToGlobalIds ); + auto const negDensCollector = rankNegDensityIds.createCollector( cellLocalToGlobalIds ); // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K @@ -894,8 +894,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, dofKey, subRegion, localSolution, - presCollector, - densCollector, + negPresCollector, + negDensCollector, temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: @@ -912,14 +912,14 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, dofKey, subRegion, localSolution, - presCollector, - densCollector ); + negPresCollector, + negDensCollector ); localCheck = std::min( localCheck, subRegionData.localMinVal ); - minPres = std::min( minPres, subRegionData.localMinPres ); - minDens = std::min( minDens, subRegionData.localMinDens ); - minTotalDens = std::min( minTotalDens, subRegionData.localMinTotalDens ); + minPres = std::min( minPres, subRegionData.localMinNegPres ); + minDens = std::min( minDens, subRegionData.localMinNegDens ); + minTotalDens = std::min( minTotalDens, subRegionData.localMinNegTotalDens ); numNegTotalDens += subRegionData.localNumNegTotalDens; } ); } ); @@ -929,14 +929,12 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, minTotalDens = MpiWrapper::min( minTotalDens ); numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); - units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; - rankNegPressureIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), "negative pressure", minPres, units::Unit::Pressure ); + units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; rankNegDensityIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), "negative component density", minDens, massUnit ); - if( numNegTotalDens > 0 ) { GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index d9ea0fb0574..9fe4331d724 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -35,7 +35,7 @@ IdReporterBuffer::IdReporterBuffer( bool enabled, IdCountType maxCollectionSize } } -IdReporterCollector IdReporterBuffer::createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const +IdReporterCollector IdReporterBuffer::createCollector( arrayView1d< globalIndex const > const & localToGlobalId ) const { return IdReporterCollector( m_idsCounter, m_idsBuffer, localToGlobalId ); } @@ -47,7 +47,9 @@ IdReporterOutput IdReporterBuffer::createOutput() const IdReporterOutput::IdReporterOutput( IdReporterBuffer const & buffer ): - m_buffer( buffer ) + m_buffer( buffer ), + m_ranksSignaledIdsCount( MpiWrapper::sum( buffer.getSignaledIdsCount() ) ), + m_ranksCollectedIdsCount( MpiWrapper::sum( buffer.getCollectedIdsCount() ) ) {} void IdReporterOutput::outputWrongValues( string_view linesPrefix, @@ -57,14 +59,13 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, { if( m_buffer.enabled() ) { - integer numSignaledWrongValues = MpiWrapper::sum( m_buffer.getSignaledIdsCount() ); - if( numSignaledWrongValues > 0 ) + if( m_ranksSignaledIdsCount > 0 ) { string const minValueStr = GEOS_FMT( "{:.{}f} [{}]", minValue, 3, units::getSymbol( unit ) ); GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", - linesPrefix, numSignaledWrongValues, valueNaming, minValueStr ) ); + linesPrefix, m_ranksSignaledIdsCount, valueNaming, minValueStr ) ); - if( MpiWrapper::sum( m_buffer.getCollectedIdsCount() ) > 0 ) + if( m_ranksCollectedIdsCount > 0 ) { GEOS_LOG_RANK_0( GEOS_FMT( "{}{} element ids:", linesPrefix, valueNaming ) ); @@ -76,7 +77,8 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, stringutilities::join( m_buffer, ", " ), ( m_buffer.isComplete() ? "..." : "." ) ) ); } - else { + else + { GEOS_LOG_RANK_0( GEOS_FMT( "{}Id listing of {} elements not shown, increase the log-level if needed.", linesPrefix, valueNaming ) ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index 95f1ee2f5d2..cdeb054eb90 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -30,8 +30,17 @@ class IdReporterOutput { public: + using IdCountType = IdReporterCollector::IdCountType; + using IdType = IdReporterCollector::IdType; + IdReporterOutput( IdReporterBuffer const & buffer ); + IdCountType getRanksSignaledIdsCount() const + { return m_ranksSignaledIdsCount; } + + IdCountType getRanksCollectedIdsCount() const + { return m_ranksCollectedIdsCount; } + void outputWrongValues( string_view linesPrefix, string_view valueNaming, real64 minValue, @@ -41,14 +50,18 @@ class IdReporterOutput IdReporterBuffer const & m_buffer; + IdCountType m_ranksSignaledIdsCount; + + IdCountType m_ranksCollectedIdsCount; + }; class IdReporterBuffer { public: - using IdCountType = int32_t; - using IdType = globalIndex; + using IdCountType = IdReporterCollector::IdCountType; + using IdType = IdReporterCollector::IdType; /** * @brief Construct a preallocated buffer to collect a limited quantity of ids in kernels. @@ -89,7 +102,7 @@ class IdReporterBuffer /** * @return A view on the ids array owned by the instance. -> change comment to explain the interest for kernels */ - IdReporterCollector createCollector( arrayView1d< globalIndex > const & localToGlobalId ) const; + IdReporterCollector createCollector( arrayView1d< globalIndex const > const & localToGlobalId ) const; IdReporterOutput createOutput() const; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 05a45f90bf5..c73c1002d67 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -46,11 +46,11 @@ class IdReporterCollector IdReporterCollector & operator=( IdReporterCollector const & other ) = default; IdReporterCollector & operator=( IdReporterCollector && other ) = default; - static IdReporterCollector disabled() // -> cpp + static IdReporterCollector disabled() { return IdReporterCollector( arrayView1d< IdCountType >(), arrayView1d< IdType >(), - arrayView1d< globalIndex >() ); + arrayView1d< globalIndex const >() ); } /** @@ -98,11 +98,11 @@ class IdReporterCollector // ids of detected elements, quantity limited to 'maxIdsCount' arrayView1d< IdType > m_idsBuffer; - arrayView1d< globalIndex > m_localToGlobalId; + arrayView1d< globalIndex const > m_localToGlobalId; IdReporterCollector( arrayView1d< IdCountType > const & idsCounter, arrayView1d< IdType > const & idsArray, - arrayView1d< globalIndex > const & localToGlobalId ): + arrayView1d< globalIndex const > const & localToGlobalId ): m_idsCounter( idsCounter ), m_idsBuffer( idsArray ), m_localToGlobalId( localToGlobalId ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 958b71cacb4..c311efefc2b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -106,21 +106,21 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer {} KernelStats( real64 _localMinVal, - real64 _localMinPres, - real64 _localMinDens, - real64 _localMinTotalDens, + real64 _localNegMinPres, + real64 _localMinNegDens, + real64 _localMinNegTotalDens, integer _localNumNegTotalDens ) : Base::StackVariables( _localMinVal ), - localMinPres( _localMinPres ), - localMinDens( _localMinDens ), - localMinTotalDens( _localMinTotalDens ), + localMinNegPres( _localNegMinPres ), + localMinNegDens( _localMinNegDens ), + localMinNegTotalDens( _localMinNegTotalDens ), localNumNegTotalDens( _localNumNegTotalDens ) { } - real64 localMinPres; - real64 localMinDens; - real64 localMinTotalDens; + real64 localMinNegPres; + real64 localMinNegDens; + real64 localMinNegTotalDens; localIndex localNumNegTotalDens; // ne peuvent être que 0 ou 1 dans chaque kernel }; @@ -176,9 +176,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer globalMinVal.min( stack.localMinVal ); - minPres.min( stack.localMinPres ); - minDens.min( stack.localMinDens ); - minTotalDens.min( stack.localMinTotalDens ); + minPres.min( stack.localMinNegPres ); + minDens.min( stack.localMinNegDens ); + minTotalDens.min( stack.localMinNegTotalDens ); if( stack.localNumNegPres > 0 ) kernelComponent.m_negPressureIds.collectId( atomicPolicy{}, ei ); @@ -202,9 +202,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer { Base::setup( ei, stack ); - stack.localMinPres = 0.0; - stack.localMinDens = 0.0; - stack.localMinTotalDens = 0.0; + stack.localMinNegPres = 0.0; + stack.localMinNegDens = 0.0; + stack.localMinNegTotalDens = 0.0; stack.localNumNegPres = 0; stack.localNumNegDens = 0; @@ -246,8 +246,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer if( !m_allowNegativePressure ) stack.localMinVal = 0; - if( newPres < stack.localMinPres ) - stack.localMinPres = newPres; + if( newPres < stack.localMinNegPres ) + stack.localMinNegPres = newPres; } // if component density chopping is not allowed, the time step fails if a component density is negative @@ -263,8 +263,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer stack.localNumNegDens = 1; stack.localMinVal = 0; - if( newDens < stack.localMinDens ) - stack.localMinDens = newDens; + if( newDens < stack.localMinNegDens ) + stack.localMinNegDens = newDens; } } } @@ -281,8 +281,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer stack.localNumNegTotalDens = 1; stack.localMinVal = 0; - if( totalDens < stack.localMinTotalDens ) - stack.localMinTotalDens = totalDens; + if( totalDens < stack.localMinNegTotalDens ) + stack.localMinNegTotalDens = totalDens; } } @@ -303,9 +303,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer /// scaling type (global or local) compositionalMultiphaseUtilities::ScalingType const m_scalingType; - IdReporterCollector m_negPressureIds; + IdReporterCollector const & m_negPressureIds; - IdReporterCollector m_negDensityIds; + IdReporterCollector const & m_negDensityIds; }; From 056ac9cf89e5d9d918a870c7525d734e896e9288 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 20 May 2025 11:29:21 +0200 Subject: [PATCH 10/67] =?UTF-8?q?=E2=9C=A8=20implementation=20of=20neg=20p?= =?UTF-8?q?ressure=20ids=20output=20on=20other=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SinglePhaseBase.cpp | 32 ++++++------ .../singlePhase/SolutionCheckKernel.hpp | 32 +++++++----- .../wells/CompositionalMultiphaseWell.cpp | 50 ++++++++++--------- .../fluidFlow/wells/LogLevelsInfo.hpp | 6 +++ .../fluidFlow/wells/SinglePhaseWell.cpp | 35 +++++++------ 5 files changed, 90 insertions(+), 65 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index 6a17a1ef7d4..c803c66880a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -43,6 +43,7 @@ #include "physicsSolvers/KernelLaunchSelectors.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp" @@ -1328,7 +1329,8 @@ bool SinglePhaseBase::checkSystemSolution( DomainPartition & domain, GEOS_MARK_FUNCTION; string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); - integer numNegativePressures = 0; + IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; real64 minPressure = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, @@ -1343,23 +1345,25 @@ bool SinglePhaseBase::checkSystemSolution( DomainPartition & domain, arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); - - auto const statistics = - singlePhaseBaseKernels::SolutionCheckKernel:: - launch< parallelDevicePolicy<> >( localSolution, rankOffset, dofNumber, ghostRank, pres, scalingFactor ); - - numNegativePressures += statistics.first; - minPressure = std::min( minPressure, statistics.second ); + auto const negPresCollector = rankNegPressureIds.createCollector( subRegion.localToGlobalMap().toViewConst() ); + + auto const statistics = singlePhaseBaseKernels::SolutionCheckKernel:: + launch< parallelDevicePolicy<> >( localSolution, + rankOffset, + dofNumber, + ghostRank, + pres, + scalingFactor, + negPresCollector ); + + minPressure = std::min( minPressure, statistics.minNegPres ); } ); } ); - numNegativePressures = MpiWrapper::sum( numNegativePressures ); - - if( numNegativePressures > 0 ) - GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative pressure values: {}, minimum value: {} Pa", - getName(), numNegativePressures, fmt::format( "{:.{}f}", minPressure, 3 ) ) ); + rankNegPressureIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + "negative pressure", minPressure, units::Unit::Pressure ); - return (m_allowNegativePressure || numNegativePressures == 0) ? 1 : 0; + return (m_allowNegativePressure || rankNegPressureIds.getSignaledIdsCount() == 0) ? 1 : 0; } void SinglePhaseBase::saveConvergedState( ElementSubRegionBase & subRegion ) const diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp index b4bf8022774..97560785906 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp @@ -22,7 +22,7 @@ #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "common/GEOS_RAJA_Interface.hpp" +#include "physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp" namespace geos { @@ -34,16 +34,24 @@ namespace singlePhaseBaseKernels struct SolutionCheckKernel { + + struct KernelStats + { + real64 minNegPres; + }; + template< typename POLICY > - static std::pair< integer, real64 > launch( arrayView1d< real64 const > const & localSolution, - globalIndex const rankOffset, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< integer const > const & ghostRank, - arrayView1d< real64 const > const & pres, - real64 const scalingFactor ) + static KernelStats launch( arrayView1d< real64 const > const & localSolution, + globalIndex const rankOffset, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< integer const > const & ghostRank, + arrayView1d< real64 const > const & pres, + real64 const scalingFactor, + IdReporterCollector const & negPressureIds ) { - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegativePressures( 0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPres( 0.0 ); + using reducePolicy = ReducePolicy< POLICY >; + using atomicPolicy = AtomicPolicy< POLICY >; + RAJA::ReduceMin< reducePolicy, real64 > minNegPres( 0.0 ); forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) { @@ -54,14 +62,14 @@ struct SolutionCheckKernel if( newPres < 0.0 ) { - numNegativePressures += 1; - minPres.min( newPres ); + minNegPres.min( newPres ); + negPressureIds.collectId( atomicPolicy{}, ei ); } } } ); - return { numNegativePressures.get(), minPres.get() }; + return { minNegPres.get() }; } }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index e1182be2377..313c19eb54f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -33,6 +33,7 @@ #include "mesh/WellElementSubRegion.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/LogLevelsInfo.hpp" +#include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" #include "physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellFields.hpp" @@ -1554,7 +1555,11 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, { real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; - integer numNegPres = 0, numNegDens = 0, numNegTotalDens = 0; + integer numNegTotalDens = 0; + IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), + isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; + IdReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), + isLogLevelActive< logInfo::WellValidityDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -1576,6 +1581,9 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::well::pressureScalingFactor >(); arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::well::temperatureScalingFactor >(); arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::well::globalCompDensityScalingFactor >(); + auto const & cellLocalToGlobalIds = subRegion.localToGlobalMap(); + auto const negPresCollector = rankNegPressureIds.createCollector( cellLocalToGlobalIds ); + auto const negDensCollector = rankNegDensityIds.createCollector( cellLocalToGlobalIds ); // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K @@ -1598,8 +1606,8 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, wellDofKey, subRegion, localSolution, - IdReporterCollector::disabled(), - IdReporterCollector::disabled(), + negPresCollector, + negDensCollector, temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: @@ -1616,14 +1624,14 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, wellDofKey, subRegion, localSolution, - IdReporterCollector::disabled(), - IdReporterCollector::disabled() ); + negPresCollector, + negDensCollector ); localCheck = std::min( localCheck, subRegionData.localMinVal ); - minPres = std::min( minPres, subRegionData.localMinPres ); - minDens = std::min( minDens, subRegionData.localMinDens ); - minTotalDens = std::min( minTotalDens, subRegionData.localMinTotalDens ); + minPres = std::min( minPres, subRegionData.localMinNegPres ); + minDens = std::min( minDens, subRegionData.localMinNegDens ); + minTotalDens = std::min( minTotalDens, subRegionData.localMinNegTotalDens ); numNegTotalDens += subRegionData.localNumNegTotalDens; } ); } ); @@ -1631,24 +1639,20 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, minPres = MpiWrapper::min( minPres ); minDens = MpiWrapper::min( minDens ); minTotalDens = MpiWrapper::min( minTotalDens ); - numNegPres = MpiWrapper::sum( numNegPres ); - numNegDens = MpiWrapper::sum( numNegDens ); numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); - // TODO stats comme les autres - if( numNegPres > 0 ) - GEOS_LOG_LEVEL_RANK_0( logInfo::WellValidity, - GEOS_FMT( " {}: Number of negative well pressure values: {}, minimum value: {} Pa", - getName(), numNegPres, fmt::format( "{:.{}f}", minPres, 3 ) ) ); - string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; - if( numNegDens > 0 ) - GEOS_LOG_LEVEL_RANK_0( logInfo::WellValidity, - GEOS_FMT( " {}: Number of negative well component density values: {}, minimum value: {} {} ", - getName(), numNegDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); - if( minTotalDens > 0 ) + rankNegPressureIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + "negative pressure", minPres, units::Unit::Pressure ); + + units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; + rankNegDensityIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + "negative component density", minDens, massUnit ); + if( numNegTotalDens > 0 ) + { GEOS_LOG_LEVEL_RANK_0( logInfo::WellValidity, - GEOS_FMT( " {}: Number of negative total well density values: {}, minimum value: {} {} ", - getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}", + getName(), numNegTotalDens, fmt::format( "{:.{}f}", minTotalDens, 3 ), units::getSymbol( massUnit ) ) ); + } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp index 1d577ad591b..792d8f18243 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp @@ -66,6 +66,12 @@ struct WellValidity static constexpr std::string_view getDescription() { return "Well validity information"; } }; +struct WellValidityDetails +{ + static constexpr int getMinLogLevel() { return 2; } + static constexpr std::string_view getDescription() { return "Well validity details (negative pressure element ids)"; } +}; + /// @endcond ///@} diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index b2255836bcc..de44a4d6539 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -33,6 +33,7 @@ #include "physicsSolvers/LogLevelsInfo.hpp" #include "physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" +#include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/wells/SinglePhaseWellFields.hpp" @@ -883,8 +884,9 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, GEOS_MARK_FUNCTION; string const wellDofKey = dofManager.getKey( wellElementDofName() ); - integer numNegativePressures = 0; - real64 minPressure = 0.0; + IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), + isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; + real64 minNegPres = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel const & mesh, @@ -908,25 +910,26 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, arrayView1d< real64 const > const & pres = subRegion.getField< fields::well::pressure >(); - auto const statistics = - singlePhaseBaseKernels::SolutionCheckKernel:: - launch< parallelDevicePolicy<> >( localSolution, rankOffset, dofNumber, ghostRank, pres, scalingFactor ); + auto const negPresCollector = rankNegPressureIds.createCollector( subRegion.localToGlobalMap().toViewConst() ); - numNegativePressures += statistics.first; - minPressure = std::min( minPressure, statistics.second ); + auto const results = singlePhaseBaseKernels::SolutionCheckKernel:: + launch< parallelDevicePolicy<> >( localSolution, + rankOffset, + dofNumber, + ghostRank, + pres, + scalingFactor, + negPresCollector ); + + minNegPres = std::min( minNegPres, results.minNegPres ); } ); } ); - numNegativePressures = MpiWrapper::sum( numNegativePressures ); - - if( numNegativePressures > 0 ) - { - GEOS_LOG_LEVEL_RANK_0( logInfo::SystemSolution, - GEOS_FMT( " {}: Number of negative pressure values: {}, minimum value: {} Pa", - getName(), numNegativePressures, fmt::format( "{:.{}f}", minPressure, 3 ) ) ); - } + IdReporterOutput const rankNegPressureIdsOutput = rankNegPressureIds.createOutput(); + rankNegPressureIdsOutput.outputWrongValues( GEOS_FMT( " {}: ", getName() ), + "negative pressure", minNegPres, units::Unit::Pressure ); - return (m_allowNegativePressure || numNegativePressures == 0) ? 1 : 0; + return (m_allowNegativePressure || rankNegPressureIdsOutput.getRanksSignaledIdsCount() == 0) ? 1 : 0; } void From 3f97e2bd5527ba9269893344374492be5982871b Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 20 May 2025 14:33:40 +0200 Subject: [PATCH 11/67] =?UTF-8?q?=F0=9F=90=9B=20fix=20for=20a=20CUDA=20tar?= =?UTF-8?q?get:=20explicit=20constructor=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp index 97560785906..bfbe3021863 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp @@ -69,7 +69,7 @@ struct SolutionCheckKernel } ); - return { minNegPres.get() }; + return KernelStats{ minNegPres.get() }; } }; From e0b104d7c12ac6230138e9d04b070684c87f5ad2 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 20 May 2025 17:22:31 +0200 Subject: [PATCH 12/67] =?UTF-8?q?=F0=9F=92=84=20msg=20slight=20rewriting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SolutionCheckHelpers.cpp | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 9fe4331d724..cf387355217 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -65,22 +65,19 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", linesPrefix, m_ranksSignaledIdsCount, valueNaming, minValueStr ) ); + string const indentation = string( linesPrefix.size(), ' ' ); if( m_ranksCollectedIdsCount > 0 ) { - GEOS_LOG_RANK_0( GEOS_FMT( "{}{} element ids:", - linesPrefix, valueNaming ) ); + GEOS_LOG_RANK_0( GEOS_FMT( "{}Summary of {} element:", + indentation, valueNaming ) ); MpiWrapper::barrier(); - GEOS_LOG( GEOS_FMT( "{}- rank {}, {} values: {}{}", - string( linesPrefix.size(), ' ' ), - MpiWrapper::commRank(), - m_buffer.getSignaledIdsCount(), - stringutilities::join( m_buffer, ", " ), - ( m_buffer.isComplete() ? "..." : "." ) ) ); - } - else - { - GEOS_LOG_RANK_0( GEOS_FMT( "{}Id listing of {} elements not shown, increase the log-level if needed.", - linesPrefix, valueNaming ) ); + if( m_buffer.getSignaledIdsCount() > 0 ) + GEOS_LOG( GEOS_FMT( "{}- rank {}, {} values: {}{}", + indentation, + MpiWrapper::commRank(), + m_buffer.getSignaledIdsCount(), + stringutilities::join( m_buffer, ", " ), + ( m_buffer.isComplete() ? "..." : "." ) ) ); } } } From d29db451bc30b9c76a90873b3b0910de135d859e Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 20 May 2025 17:42:52 +0200 Subject: [PATCH 13/67] =?UTF-8?q?=F0=9F=90=9B=20adding=20one=20more=20barr?= =?UTF-8?q?ier=20to=20not=20get=20the=20msg=20cut=20by=20other=20msgs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index cf387355217..f10c4ad674f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -78,6 +78,7 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, m_buffer.getSignaledIdsCount(), stringutilities::join( m_buffer, ", " ), ( m_buffer.isComplete() ? "..." : "." ) ) ); + MpiWrapper::barrier(); } } } From 0803a92e910f5274258ad742fd227cec4e5b9151 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Thu, 22 May 2025 16:53:04 +0200 Subject: [PATCH 14/67] =?UTF-8?q?=F0=9F=90=9B=20CUDA=20crash=20fix=20+=20b?= =?UTF-8?q?ug=20fix=20(data=20not=20moved=20from=20device)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 2 ++ .../fluidFlow/kernels/compositional/SolutionCheckKernel.hpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index f10c4ad674f..3216da55d4d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -42,6 +42,8 @@ IdReporterCollector IdReporterBuffer::createCollector( arrayView1d< globalIndex IdReporterOutput IdReporterBuffer::createOutput() const { + m_idsCounter.move( LvArray::MemorySpace::host, false ); + m_idsBuffer.move( LvArray::MemorySpace::host, false ); return IdReporterOutput( *this ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index c311efefc2b..4ea7c458bb7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -303,9 +303,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer /// scaling type (global or local) compositionalMultiphaseUtilities::ScalingType const m_scalingType; - IdReporterCollector const & m_negPressureIds; + IdReporterCollector const m_negPressureIds; - IdReporterCollector const & m_negDensityIds; + IdReporterCollector const m_negDensityIds; }; From de506c60bb0ee7b09eaac5518f72efe2a730dbb8 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 23 May 2025 10:09:42 +0200 Subject: [PATCH 15/67] =?UTF-8?q?=E2=9C=A8=20adding=20table=20formatting?= =?UTF-8?q?=20to=20allow=20for=20showing=20more=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SolutionCheckHelpers.cpp | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 3216da55d4d..2998090f25b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -20,6 +20,7 @@ #include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" #include "common/MpiWrapper.hpp" #include "common/format/StringUtilities.hpp" +#include "common/format/table/TableFormatter.hpp" namespace geos { @@ -70,20 +71,29 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, string const indentation = string( linesPrefix.size(), ' ' ); if( m_ranksCollectedIdsCount > 0 ) { - GEOS_LOG_RANK_0( GEOS_FMT( "{}Summary of {} element:", - indentation, valueNaming ) ); - MpiWrapper::barrier(); + TableLayout const layout = TableLayout( GEOS_FMT( "Summary of {} element:", valueNaming ), + { "Rank", "Global id", "Value" } )/*. + setIndentation( linesPrefix.size() )*/; + TableData data; if( m_buffer.getSignaledIdsCount() > 0 ) - GEOS_LOG( GEOS_FMT( "{}- rank {}, {} values: {}{}", - indentation, - MpiWrapper::commRank(), - m_buffer.getSignaledIdsCount(), - stringutilities::join( m_buffer, ", " ), - ( m_buffer.isComplete() ? "..." : "." ) ) ); - MpiWrapper::barrier(); + { + integer rank = MpiWrapper::commRank(); + integer omitted = m_buffer.getSignaledIdsCount() - m_buffer.getCollectedIdsCount(); + + for( auto const & wrongOccurence : m_buffer ) + { + data.addRow( rank, m_buffer.getSignaledIdsCount(), wrongOccurence ); + } + + if( omitted > 0 ) + data.addRow( rank, CellType::MergeNext, GEOS_FMT( "Omitted {} values ...", omitted ) ); + } + + TableTextFormatter const formatter( layout ); + GEOS_LOG( formatter.toString( data ) ); } } } } -} // namespace geos +} // namespace geos From 47f5c5ce91bd396d355e4034b10caa26428ab74d Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 23 May 2025 11:09:44 +0200 Subject: [PATCH 16/67] =?UTF-8?q?=E2=9C=A8=20adding=20table=20indentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableFormatter.cpp | 5 ++-- .../common/format/table/TableFormatter.hpp | 5 ++-- .../common/format/table/TableLayout.cpp | 12 ++++++++-- .../common/format/table/TableLayout.hpp | 23 +++++++++++++++++++ .../format/table/unitTests/testTable.cpp | 15 ++++++------ .../fluidFlow/SolutionCheckHelpers.cpp | 7 +++--- 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index a56c7baa22d..8e5f28dcd90 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -564,12 +564,12 @@ void TableTextFormatter::outputTable( PreparedTableLayout const & tableLayout, { tableOutput << '\n'; } - tableOutput << sepLine << '\n'; + tableOutput << tableLayout.getIndentationStr() << sepLine << '\n'; outputLines( tableLayout, headerCellsLayout, tableOutput ); if( !dataCellsLayout.empty()) { outputLines( tableLayout, dataCellsLayout, tableOutput ); - tableOutput << sepLine; + tableOutput << tableLayout.getIndentationStr() << sepLine; } if( tableLayout.isLineBreakEnabled()) { @@ -640,6 +640,7 @@ void TableTextFormatter::outputLines( PreparedTableLayout const & tableLayout, if( isLeftBorderCell ) { // left table border isLeftBorderCell=false; + tableOutput << tableLayout.getIndentationStr(); tableOutput << m_verticalLine << string( nbBorderSpaces, cellSpaceChar ); } else diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 5902af27e58..4bce6432bb9 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -70,7 +70,7 @@ class TableFormatter }; /** - * @brief class for CSV formatting + * @brief Class to format data in a formatted CSV format */ class TableCSVFormatter : public TableFormatter { @@ -123,7 +123,8 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c /** - * @brief class for log formatting + * @brief Class to format data in a formatted text format + * (for log output typically, expecting fixed character size). */ class TableTextFormatter : public TableFormatter { diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 59c49bc2404..30ebe4059ef 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -78,6 +78,12 @@ TableLayout & TableLayout::setMaxColumnWidth( size_t width ) return *this; } +TableLayout & TableLayout::setIndentation( size_t spacesCount ) +{ + m_indentation = spacesCount; + return *this; +} + bool TableLayout::isLineBreakEnabled() const { return m_lineBreakAtBegin; } @@ -293,13 +299,15 @@ TableLayout::DeepFirstIterator TableLayout::beginDeepFirst() const PreparedTableLayout::PreparedTableLayout( ): TableLayout(), m_columnLayersCount( 0 ), - m_lowermostColumnCount( 0 ) + m_lowermostColumnCount( 0 ), + m_indentationStr( m_indentation, ' ' ) {} PreparedTableLayout::PreparedTableLayout( TableLayout const & other ): TableLayout( other ), m_columnLayersCount( 0 ), - m_lowermostColumnCount( 0 ) + m_lowermostColumnCount( 0 ), + m_indentationStr( m_indentation, ' ' ) { prepareLayoutRecusive( m_tableColumns, 0 ); diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index b92cfe91624..31f7c498852 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -634,6 +634,12 @@ class TableLayout */ TableLayout & setMaxColumnWidth( size_t width ); + /** + * @brief Set the indentation of the whole table. + * @param spacesCount The number of indentation spaces. + */ + TableLayout & setIndentation( size_t spacesCount ); + /** * @brief check if a column max width has been set * @return Truef a column max width has been set, otherwise false @@ -670,6 +676,12 @@ class TableLayout size_t const & getMaxColumnWidth() const { return m_maxColumnWidth; } + /** + * @return The number of spaces at the left of the table. + */ + size_t const & getIndentation() const + { return m_indentation; } + /** * @brief Create and add columns to the columns vector given a string vector * @param columnNames The columns name @@ -744,6 +756,9 @@ class TableLayout /// The number of margin spaces around contents. integer m_marginValue; + + /// The number of spaces at the left of the table. + size_t m_indentation = 0; }; @@ -796,11 +811,19 @@ class PreparedTableLayout : public TableLayout size_t getLowermostColumnsCount() const { return m_lowermostColumnCount; } + /** + * @return A string with the correct indentation space count to precede each lines of the formatted table. + */ + string_view getIndentationStr() const + { return m_indentationStr; } + private: size_t m_columnLayersCount; size_t m_lowermostColumnCount; + string m_indentationStr; + /** * @brief Recursive part of column layout preparation, see constructor documentation. * @param columns The list of columns to prepare. diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 67e36df5c94..9794daa15f4 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -88,18 +88,19 @@ TEST( testTable, tableEmptyRow ) TEST( testTable, tableOneTrickyLine ) { - TableLayout const tableLayout( "", { "Well", "CordX", "CoordZ", "Prev", "Next" } ); + TableLayout const tableLayout = TableLayout( "", { "Well", "CordX", "CoordZ", "Prev", "Next" } ). + setIndentation( 4 ); TableData tableData; tableData.addRow( "value1", CellType::MergeNext, CellType::MergeNext, CellType::MergeNext, CellType::MergeNext ); TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n" - "---------------------------------------------------\n" - "| Well | CordX | CoordZ | Prev | Next |\n" - "|----------|---------|----------|--------|--------|\n" - "| value1 | |\n" - "---------------------------------------------------\n" ); + " ---------------------------------------------------\n" + " | Well | CordX | CoordZ | Prev | Next |\n" + " |----------|---------|----------|--------|--------|\n" + " | value1 | |\n" + " ---------------------------------------------------\n" ); } TEST( testTable, tableClassic ) @@ -216,7 +217,7 @@ TEST( testTable, tableHiddenColumn ) TEST( testTable, tableMergeOverflowParadox ) { string const title = "Lorem Ipsum"; - TableLayout tableLayout( title, + TableLayout const tableLayout( title, { TableLayout::Column() .setName( "A" ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 2998090f25b..748013e725d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -71,9 +71,10 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, string const indentation = string( linesPrefix.size(), ' ' ); if( m_ranksCollectedIdsCount > 0 ) { - TableLayout const layout = TableLayout( GEOS_FMT( "Summary of {} element:", valueNaming ), - { "Rank", "Global id", "Value" } )/*. - setIndentation( linesPrefix.size() )*/; + TableLayout const layout = TableLayout( GEOS_FMT( "Summary of {} element", valueNaming ), + { "Rank", "Global id", "Value" } ). + enableLineBreak( false ). + setIndentation( linesPrefix.size() ); TableData data; if( m_buffer.getSignaledIdsCount() > 0 ) { From 5fc7ea63c7da07b4f7364e9d2a5035c052a858ef Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 23 May 2025 12:28:09 +0200 Subject: [PATCH 17/67] =?UTF-8?q?=E2=9C=A8=20adding=20support=20for=20no?= =?UTF-8?q?=20column=20titled=20table=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableFormatter.cpp | 16 ++++++--- .../common/format/table/TableFormatter.hpp | 4 ++- .../format/table/unitTests/testTable.cpp | 36 +++++++++++++++---- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 8e5f28dcd90..2850910e0ce 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -166,7 +166,7 @@ void TableTextFormatter::initalizeTableGrids( PreparedTableLayout const & tableL // this array will store the displayed width of all columns (it will be scaled by data & headers width) stdVector< size_t > columnsWidth; - populateTitleCellsLayout( tableLayout, headerCellsLayout ); + populateTitleCellsLayout( tableLayout, headerCellsLayout, inputDataRowsCount ); if( hasColumnLayout ) { populateHeaderCellsLayout( tableLayout, headerCellsLayout, inputDataRowsCount ); @@ -201,23 +201,29 @@ void TableTextFormatter::initalizeTableGrids( PreparedTableLayout const & tableL } void TableTextFormatter::populateTitleCellsLayout( PreparedTableLayout const & tableLayout, - CellLayoutRows & headerCellsLayout ) const + CellLayoutRows & headerCellsLayout, + size_t const inputDataColumnsCount ) const { TableLayout::CellLayout const & titleInput = tableLayout.getTitleLayout(); if( !titleInput.isEmpty() ) { // if it exists, we add the title, as a first row with all cells merged in one containing the title text - headerCellsLayout.reserve( headerCellsLayout.size() + 2 ); + // (we fit the number of data columns if no column layout has been specified) + size_t const lowermostColumnsCount = tableLayout.getColumnLayersCount() > 0 ? + tableLayout.getLowermostColumnsCount() : + inputDataColumnsCount; + + headerCellsLayout.reserve( 2 ); // the title row consists in a row of cells merging with the last cell containing the title text headerCellsLayout.emplace_back() = { - stdVector< TableLayout::CellLayout >( tableLayout.getLowermostColumnsCount(), + stdVector< TableLayout::CellLayout >( lowermostColumnsCount, TableLayout::CellLayout( CellType::MergeNext ) ), // cells titleInput.getHeight(), // sublinesCount }; headerCellsLayout.back().cells.back() = titleInput; headerCellsLayout.emplace_back() = { - stdVector< TableLayout::CellLayout >( tableLayout.getLowermostColumnsCount(), + stdVector< TableLayout::CellLayout >( lowermostColumnsCount, TableLayout::CellLayout( CellType::Separator ) ), // cells 1, // sublinesCount }; diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 4bce6432bb9..344381d965b 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -199,9 +199,11 @@ class TableTextFormatter : public TableFormatter * @param tableLayout The layout of the table, containing information about columns, headers, and their layers. * @param headerCellsLayout A reference to the collection of header cells that will be updated with the * gridified layout. + * @param inputDataColumnsCount The number of input data columns count, helps verifying the number of column. */ void populateTitleCellsLayout( PreparedTableLayout const & tableLayout, - CellLayoutRows & headerCellsLayout ) const; + CellLayoutRows & headerCellsLayout, + size_t inputDataColumnsCount ) const; /** * @brief Populate a grid of CellLayout with all visible columns of the given table layout. diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 9794daa15f4..7f7011d0649 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -88,19 +88,18 @@ TEST( testTable, tableEmptyRow ) TEST( testTable, tableOneTrickyLine ) { - TableLayout const tableLayout = TableLayout( "", { "Well", "CordX", "CoordZ", "Prev", "Next" } ). - setIndentation( 4 ); + TableLayout const tableLayout( "", { "Well", "CordX", "CoordZ", "Prev", "Next" } ); TableData tableData; tableData.addRow( "value1", CellType::MergeNext, CellType::MergeNext, CellType::MergeNext, CellType::MergeNext ); TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n" - " ---------------------------------------------------\n" - " | Well | CordX | CoordZ | Prev | Next |\n" - " |----------|---------|----------|--------|--------|\n" - " | value1 | |\n" - " ---------------------------------------------------\n" ); + "---------------------------------------------------\n" + "| Well | CordX | CoordZ | Prev | Next |\n" + "|----------|---------|----------|--------|--------|\n" + "| value1 | |\n" + "---------------------------------------------------\n" ); } TEST( testTable, tableClassic ) @@ -671,6 +670,29 @@ TEST( testTable, testFreeLayout ) ); } +TEST( testTable, testTitleWithNoColumnIndented ) +{ + TableLayout const tableLayout = TableLayout(). + setTitle( "Title" ). + setIndentation( 4 ). + setMargin( TableLayout::MarginValue::small ); + + TableData tableData; + tableData.addRow( "Global Id", 1234, 40, 5678, 60 ); + tableData.addRow( "pressure", 0.1234, 0.40, 0.5678, 0.60 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n" + " -------------------------------------------\n" + " | Title |\n" + " |-----------------------------------------|\n" + " | Global Id | 1234 | 40 | 5678 | 60 |\n" + " | pressure | 0.1234 | 0.4 | 0.5678 | 0.6 |\n" + " -------------------------------------------\n" + ); +} + int main( int argc, char * * argv ) { testing::InitGoogleTest( &argc, argv ); From 3eb2293a826a844df7c0a7f8b678f165fd0f6c79 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 26 May 2025 11:48:38 +0200 Subject: [PATCH 18/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20removing=20double=20?= =?UTF-8?q?assessor=20+=20exposing=20non-const=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableData.cpp | 5 ----- .../common/format/table/TableData.hpp | 16 +++++++--------- .../common/format/table/TableFormatter.cpp | 4 ++-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/coreComponents/common/format/table/TableData.cpp b/src/coreComponents/common/format/table/TableData.cpp index 2e4b3a85b60..1bf2a33697f 100644 --- a/src/coreComponents/common/format/table/TableData.cpp +++ b/src/coreComponents/common/format/table/TableData.cpp @@ -45,11 +45,6 @@ void TableData::clear() m_rows.clear(); } -stdVector< stdVector< TableData::CellData > > const & TableData::getTableDataRows() const -{ - return m_rows; -} - void TableData2D::collectTableValues( arraySlice1d< real64 const > dim0AxisCoordinates, arraySlice1d< real64 const > dim1AxisCoordinates, arrayView1d< real64 const > values, diff --git a/src/coreComponents/common/format/table/TableData.hpp b/src/coreComponents/common/format/table/TableData.hpp index d7f2392828a..ee23af38c6f 100644 --- a/src/coreComponents/common/format/table/TableData.hpp +++ b/src/coreComponents/common/format/table/TableData.hpp @@ -84,11 +84,6 @@ class TableData */ void clear(); - /** - * @return The rows of the table - */ - stdVector< stdVector< CellData > > const & getTableDataRows() const; - /** * @brief Get all error messages * @return The vector of error messages @@ -101,16 +96,19 @@ class TableData DataRows const & getCellsData() const { return m_rows; } + /** + * @return The const table data rows + */ + DataRows & getCellsData() + { return m_rows; } + /** * @brief Comparison operator for data rows * @param comparingTable The tableData values to compare * @return The comparison result */ inline bool operator==( TableData const & comparingTable ) const - { - - return getCellsData() == comparingTable.getCellsData(); - } + { return getCellsData() == comparingTable.getCellsData(); } private: /// vector containing all rows with cell values diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 2850910e0ce..fe727d38572 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -79,7 +79,7 @@ string TableCSVFormatter::headerToString() const string TableCSVFormatter::dataToString( TableData const & tableData ) const { - RowsCellInput const rowsValues( tableData.getTableDataRows() ); + RowsCellInput const rowsValues( tableData.getCellsData() ); string result; size_t total_size = 0; for( auto const & row : rowsValues ) @@ -160,8 +160,8 @@ void TableTextFormatter::initalizeTableGrids( PreparedTableLayout const & tableL CellLayoutRows & dataCellsLayout, size_t & tableTotalWidth ) const { + RowsCellInput const & inputDataValues( tableInputData.getCellsData() ); bool const hasColumnLayout = tableLayout.getColumnLayersCount() > 0; - RowsCellInput const & inputDataValues( tableInputData.getTableDataRows() ); size_t const inputDataRowsCount = !inputDataValues.empty() ? inputDataValues.front().size() : 0; // this array will store the displayed width of all columns (it will be scaled by data & headers width) stdVector< size_t > columnsWidth; From 58d1dce87471a359eb18a982f548e4c0dfb0812a Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 26 May 2025 11:52:38 +0200 Subject: [PATCH 19/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactoring=20TableF?= =?UTF-8?q?ormatter:=20give=20control=20to=20inheriting=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableFormatter.cpp | 50 ++++++++++++----- .../common/format/table/TableFormatter.hpp | 53 ++++++++++++++----- 2 files changed, 75 insertions(+), 28 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index fe727d38572..eecfd3119f8 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -148,9 +148,12 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) initalizeTableGrids( m_tableLayout, tableData, headerCellsLayout, dataCellsLayout, tableTotalWidth ); - outputTable( m_tableLayout, tableOutput, - headerCellsLayout, dataCellsLayout, - tableTotalWidth ); + + string const sepLine = string( tableTotalWidth, m_horizontalLine ); + outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, sepLine ); + outputTableData( tableOutput, m_tableLayout, dataCellsLayout, false ); + outputTableBottom( tableOutput, m_tableLayout, sepLine, !dataCellsLayout.empty() ); + return tableOutput.str(); } @@ -559,24 +562,40 @@ void TableTextFormatter::applyColumnsWidth( stdVector< size_t > const & columnsW } } -void TableTextFormatter::outputTable( PreparedTableLayout const & tableLayout, - std::ostringstream & tableOutput, - CellLayoutRows const & headerCellsLayout, - CellLayoutRows const & dataCellsLayout, - size_t const tableTotalWidth ) const +void TableTextFormatter::outputTableHeader( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + CellLayoutRows const & headerCellsLayout, + string_view sepLine ) const { - string const sepLine = string( tableTotalWidth, m_horizontalLine ); if( tableLayout.isLineBreakEnabled()) { tableOutput << '\n'; } tableOutput << tableLayout.getIndentationStr() << sepLine << '\n'; - outputLines( tableLayout, headerCellsLayout, tableOutput ); - if( !dataCellsLayout.empty()) + outputLines( tableLayout, headerCellsLayout, tableOutput, false ); +} + +void TableTextFormatter::outputTableData( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + CellLayoutRows const & dataCellsLayout, + bool flushAfterEachLines ) const +{ + if( !dataCellsLayout.empty() ) + { + outputLines( tableLayout, dataCellsLayout, tableOutput, flushAfterEachLines ); + } +} + +void TableTextFormatter::outputTableBottom( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + string_view sepLine, + bool hasData ) const +{ + if( hasData ) { - outputLines( tableLayout, dataCellsLayout, tableOutput ); tableOutput << tableLayout.getIndentationStr() << sepLine; } + if( tableLayout.isLineBreakEnabled()) { tableOutput << '\n'; @@ -601,7 +620,7 @@ string buildCell( TableLayout::Alignment const m_alignment, string_view value, s } } -void TableTextFormatter::formatCell( std::ostringstream & tableOutput, +void TableTextFormatter::formatCell( std::ostream & tableOutput, TableLayout::CellLayout const & cell, size_t const idxLine ) const { @@ -620,7 +639,8 @@ void TableTextFormatter::formatCell( std::ostringstream & tableOutput, void TableTextFormatter::outputLines( PreparedTableLayout const & tableLayout, CellLayoutRows const & rows, - std::ostringstream & tableOutput ) const + std::ostream & tableOutput, + bool flushOnEachLines ) const { size_t const nbRows = rows.size(); size_t const nbColumns = !rows.empty() ? rows[0].cells.size() : 0; @@ -669,6 +689,8 @@ void TableTextFormatter::outputLines( PreparedTableLayout const & tableLayout, else { // right table border tableOutput << string( nbBorderSpaces, cellSpaceChar ) << m_verticalLine << "\n"; + if( flushOnEachLines ) + tableOutput << std::flush; } } } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 344381d965b..355d48a7794 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -158,21 +158,20 @@ class TableTextFormatter : public TableFormatter template< typename DATASOURCE > string toString( DATASOURCE const & tableData ) const; -private: +protected: /// symbol for separator construction static constexpr char m_verticalLine = '|'; /// for the extremity of a row static constexpr char m_horizontalLine = '-'; - /** * @brief Initializes the table layout with the given table data and prepares necessary layouts for headers and data cells. * @param tableLayout A reference to the `TableLayout` object. * @param tableData A constant reference to the `TableData` object, which contains the actual data for the table. * @param headerCellsLayout A reference to a `CellLayoutRows` where the header cells will be populated. * @param dataCellsLayout A reference to a `CellLayoutRows` where the data cells will be populated. - * @param separatorLine A string that will be used as the table separator line + * @param tableTotalWidth A string that will be used as the table separator line */ void initalizeTableGrids( PreparedTableLayout const & tableLayout, TableData const & tableData, @@ -183,16 +182,43 @@ class TableTextFormatter : public TableFormatter /** * @brief Outputs the formatted table to the provided output stream. * @param tableLayout The layout of the table - * @param tableOutput A reference to an `std::ostringstream` where the formatted table will be written. + * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. * @param headerCellsLayout The layout of the header rows * @param dataCellsLayout The layout of the data rows - * @param separatorLine The string to be used as the table separator line + * @param separatorLine A string that will be used as the table separator line */ - void outputTable( PreparedTableLayout const & tableLayout, - std::ostringstream & tableOutput, - CellLayoutRows const & headerCellsLayout, - CellLayoutRows const & dataCellsLayout, - size_t tableTotalWidth ) const; + void outputTableHeader( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + CellLayoutRows const & headerCellsLayout, + string_view separatorLine ) const; + + /** + * @brief Outputs the formatted table to the provided output stream. + * @param tableLayout The layout of the table + * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. + * @param headerCellsLayout The layout of the header rows + * @param dataCellsLayout The layout of the data rows + * @param separatorLine A string that will be used as the table separator line + */ + void outputTableData( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + CellLayoutRows const & dataCellsLayout, + bool flushAfterEachLines ) const; + + /** + * @brief Outputs the formatted table to the provided output stream. + * @param tableLayout The layout of the table + * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. + * @param headerCellsLayout The layout of the header rows + * @param dataCellsLayout The layout of the data rows + * @param separatorLine A string that will be used as the table separator line + */ + void outputTableBottom( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + string_view separatorLine, + bool hasData ) const; + +private: /** * @brief Populate a grid of CellLayout with the title rows. @@ -290,13 +316,12 @@ class TableTextFormatter : public TableFormatter * @param tableLayout The layout of the table * @param cellsLayout A collection of rows, each containing a layout of cells to be processed and formatted. * @param tableOutput The output stream - * @param nbLinesRow A vector containing the number of sub-lines for each row. - * @param sectionType The type of the section being processed (Header, Value, etc.). - * @param separatorLine The table separator line string + * @param flushOnEachLines flush the output stream each time a line is finished */ void outputLines( PreparedTableLayout const & tableLayout, CellLayoutRows const & cellsLayout, - std::ostringstream & tableOutput ) const; + std::ostream & tableOutput, + bool flushOnEachLines ) const; }; /** From 8f68eb515f0534be35d467dfc40a3a42b52c3e06 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 26 May 2025 17:47:25 +0200 Subject: [PATCH 20/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactoring=20TableF?= =?UTF-8?q?ormatter:=20give=20control=20to=20inheriting=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableFormatter.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 355d48a7794..46392267e2b 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -307,7 +307,7 @@ class TableTextFormatter : public TableFormatter * @param cell The cell to format * @param idxLine The current line index used to access the specific content for the cell. */ - void formatCell( std::ostringstream & tableOutput, + void formatCell( std::ostream & tableOutput, TableLayout::CellLayout const & cell, size_t idxLine ) const; From 3fd0c12e336f924a27a00b7d273b81fdab774c67 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 26 May 2025 17:48:52 +0200 Subject: [PATCH 21/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=F0=9F=90=9B=20simpl?= =?UTF-8?q?ifying=20&=20fixing=20visible=20columns=20counting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableFormatter.cpp | 29 ++++++++----------- .../common/format/table/TableFormatter.hpp | 8 ++--- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index eecfd3119f8..895e16c8ec1 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -166,21 +166,21 @@ void TableTextFormatter::initalizeTableGrids( PreparedTableLayout const & tableL RowsCellInput const & inputDataValues( tableInputData.getCellsData() ); bool const hasColumnLayout = tableLayout.getColumnLayersCount() > 0; size_t const inputDataRowsCount = !inputDataValues.empty() ? inputDataValues.front().size() : 0; + size_t nbVisibleColumns = std::max( size_t( 1 ), ( hasColumnLayout ? + tableLayout.getLowermostColumnsCount() : + inputDataRowsCount ) ); // this array will store the displayed width of all columns (it will be scaled by data & headers width) - stdVector< size_t > columnsWidth; + stdVector< size_t > columnsWidth = stdVector< size_t >( nbVisibleColumns, 0 ); - populateTitleCellsLayout( tableLayout, headerCellsLayout, inputDataRowsCount ); + populateTitleCellsLayout( tableLayout, headerCellsLayout, nbVisibleColumns ); if( hasColumnLayout ) { - populateHeaderCellsLayout( tableLayout, headerCellsLayout, inputDataRowsCount ); - size_t nbVisibleColumns = headerCellsLayout.back().cells.size(); + populateHeaderCellsLayout( tableLayout, headerCellsLayout, nbVisibleColumns ); populateDataCellsLayout( tableLayout, dataCellsLayout, inputDataValues, nbVisibleColumns ); - columnsWidth = stdVector< size_t >( nbVisibleColumns, 0 ); } else { populateDataCellsLayout( tableLayout, dataCellsLayout, inputDataValues ); - columnsWidth = stdVector< size_t >( inputDataRowsCount, 0 ); } stretchColumnsByCellsWidth( columnsWidth, headerCellsLayout ); @@ -205,28 +205,23 @@ void TableTextFormatter::initalizeTableGrids( PreparedTableLayout const & tableL void TableTextFormatter::populateTitleCellsLayout( PreparedTableLayout const & tableLayout, CellLayoutRows & headerCellsLayout, - size_t const inputDataColumnsCount ) const + size_t const nbVisibleColumns ) const { TableLayout::CellLayout const & titleInput = tableLayout.getTitleLayout(); if( !titleInput.isEmpty() ) { // if it exists, we add the title, as a first row with all cells merged in one containing the title text - // (we fit the number of data columns if no column layout has been specified) - size_t const lowermostColumnsCount = tableLayout.getColumnLayersCount() > 0 ? - tableLayout.getLowermostColumnsCount() : - inputDataColumnsCount; - headerCellsLayout.reserve( 2 ); // the title row consists in a row of cells merging with the last cell containing the title text headerCellsLayout.emplace_back() = { - stdVector< TableLayout::CellLayout >( lowermostColumnsCount, + stdVector< TableLayout::CellLayout >( nbVisibleColumns, TableLayout::CellLayout( CellType::MergeNext ) ), // cells titleInput.getHeight(), // sublinesCount }; headerCellsLayout.back().cells.back() = titleInput; headerCellsLayout.emplace_back() = { - stdVector< TableLayout::CellLayout >( lowermostColumnsCount, + stdVector< TableLayout::CellLayout >( nbVisibleColumns, TableLayout::CellLayout( CellType::Separator ) ), // cells 1, // sublinesCount }; @@ -235,7 +230,7 @@ void TableTextFormatter::populateTitleCellsLayout( PreparedTableLayout const & t void TableTextFormatter::populateHeaderCellsLayout( PreparedTableLayout const & tableLayout, CellLayoutRows & headerCellsLayout, - size_t const inputDataColumnsCount ) const + size_t const nbVisibleColumns ) const { using CellLayout = TableLayout::CellLayout; @@ -252,8 +247,8 @@ void TableTextFormatter::populateHeaderCellsLayout( PreparedTableLayout const & // TODO: integrate this error in the table, and use an equality with the visible+non-visible lowermost column count // (PreparedTableLayout should have a visible & nonvisible getLowermostColumnsCount() verion) - if( inputDataColumnsCount > 0 ) - GEOS_ERROR_IF_GT( lowermostColumnsCount, inputDataColumnsCount ); + if( nbVisibleColumns > 0 ) + GEOS_ERROR_IF_GT( lowermostColumnsCount, nbVisibleColumns ); headerCellsLayout.resize( previousRowsCount + headerRowsCount ); for( size_t rowId = previousRowsCount; rowId < headerCellsLayout.size(); rowId++ ) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 46392267e2b..10f2aa550c5 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -225,11 +225,11 @@ class TableTextFormatter : public TableFormatter * @param tableLayout The layout of the table, containing information about columns, headers, and their layers. * @param headerCellsLayout A reference to the collection of header cells that will be updated with the * gridified layout. - * @param inputDataColumnsCount The number of input data columns count, helps verifying the number of column. + * @param nbVisibleColumn The number of columns that are not hidden */ void populateTitleCellsLayout( PreparedTableLayout const & tableLayout, CellLayoutRows & headerCellsLayout, - size_t inputDataColumnsCount ) const; + size_t nbVisibleColumn ) const; /** * @brief Populate a grid of CellLayout with all visible columns of the given table layout. @@ -240,11 +240,11 @@ class TableTextFormatter : public TableFormatter * @param tableLayout The layout of the table, containing information about columns, headers, and their layers. * @param headerCellsLayout A reference to the collection of header cells that will be updated with the * gridified layout. - * @param inputDataColumnsCount The number of input data columns count, helps verifying the number of column. + * @param nbVisibleColumn The number of columns that are not hidden */ void populateHeaderCellsLayout( PreparedTableLayout const & tableLayout, CellLayoutRows & headerCellsLayout, - size_t inputDataColumnsCount ) const; + size_t nbVisibleColumn ) const; /** * @brief Populates the data cells layout based on input data values, as a free layout (no columns layout). * @param tableLayout The layout of the table, From e7f73cf188698b44b110f98ef235314c50d5e4c0 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 26 May 2025 17:49:19 +0200 Subject: [PATCH 22/67] =?UTF-8?q?=E2=9C=A8=20offering=20control=20on=20ali?= =?UTF-8?q?gnement=20when=20using=20columns-free=20table=20layouts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableFormatter.cpp | 5 ++- .../common/format/table/TableLayout.cpp | 13 +++++- .../common/format/table/TableLayout.hpp | 42 ++++++++++++++----- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 895e16c8ec1..68fcd3f1a54 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -383,9 +383,12 @@ void TableTextFormatter::populateDataCellsLayout( PreparedTableLayout const & ta string_view value = inputCell.type == CellType::Separator ? string_view( &m_horizontalLine, 1 ) : string_view( inputCell.value ); + TableLayout::Alignment const alignment = inputCell.type == CellType::Header ? + tableLayout.getDefaultHeaderAlignment() : + tableLayout.getDefaultValueAlignment(); TableLayout::CellLayout & outputCell = outputRow.cells[idxColumn]; - outputCell = TableLayout::CellLayout( inputCell.type, TableLayout::defaultValueAlignment ); + outputCell = TableLayout::CellLayout( inputCell.type, alignment ); outputCell.prepareLayout( value, tableLayout.getMaxColumnWidth() ); maxLinesInRow = std::max( maxLinesInRow, outputCell.getHeight() ); diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 30ebe4059ef..674bca02c5a 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -84,6 +84,17 @@ TableLayout & TableLayout::setIndentation( size_t spacesCount ) return *this; } +TableLayout & TableLayout::setDefaultHeaderAlignment( TableLayout::Alignment alignment ) +{ + m_defaultHeaderAlignment = alignment; + return *this; +} +TableLayout & TableLayout::setDefaultValueAlignment( TableLayout::Alignment alignment ) +{ + m_defaultValueAlignment = alignment; + return *this; +} + bool TableLayout::isLineBreakEnabled() const { return m_lineBreakAtBegin; } @@ -165,7 +176,7 @@ void TableLayout::Cell::setText( string_view text ) } TableLayout::Column::Column(): - m_header( CellType::Header, defaultHeaderAlignment ) + m_header( CellType::Header, Alignment::center ) {} TableLayout::Column::Column( string_view name, TableLayout::ColumnAlignement alignment ): diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 31f7c498852..889d986e129 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -43,12 +43,6 @@ class TableLayout /// Type of aligment for a column enum Alignment { right, left, center }; - /// default value for columns header cells alignement - static constexpr Alignment defaultHeaderAlignment = Alignment::center; - - /// default value for data cells alignement - static constexpr Alignment defaultValueAlignment = Alignment::right; - /// Space to apply between all data and border enum MarginValue : integer { @@ -69,9 +63,9 @@ class TableLayout struct ColumnAlignement { /// Alignment for column name. By default aligned to center - Alignment headerAlignment = defaultHeaderAlignment; + Alignment headerAlignment = Alignment::center; /// Alignment for column values. By default aligned to right side - Alignment valueAlignment = defaultValueAlignment; + Alignment valueAlignment = Alignment::right; }; /** @@ -607,6 +601,18 @@ class TableLayout string_view getTitleStr() const { return m_tableTitleStr; } + /** + * @return the default value for columns header cells alignement. Used with column-free layout. + */ + Alignment getDefaultHeaderAlignment() const + { return m_defaultHeaderAlignment; } + + /** + * @return the default value for data cells alignement. Used with column-free layout. + */ + Alignment getDefaultValueAlignment() const + { return m_defaultValueAlignment; } + /** * @param title The table title * @return The tableLayout reference @@ -640,6 +646,16 @@ class TableLayout */ TableLayout & setIndentation( size_t spacesCount ); + /** + * @brief Sets the default value for columns header cells alignement. Used with column-free layout. + */ + TableLayout & setDefaultHeaderAlignment( Alignment alignment ); + + /** + * @brief Sets the default value for data cells alignement. Used with column-free layout. + */ + TableLayout & setDefaultValueAlignment( Alignment alignment ); + /** * @brief check if a column max width has been set * @return Truef a column max width has been set, otherwise false @@ -677,7 +693,7 @@ class TableLayout { return m_maxColumnWidth; } /** - * @return The number of spaces at the left of the table. + * @return The number of spaces at the left of the table. */ size_t const & getIndentation() const { return m_indentation; } @@ -756,10 +772,16 @@ class TableLayout /// The number of margin spaces around contents. integer m_marginValue; - + /// The number of spaces at the left of the table. size_t m_indentation = 0; + /// default value for columns header cells alignement. + Alignment m_defaultHeaderAlignment = Alignment::center; + + /// default value for data cells alignement. + Alignment m_defaultValueAlignment = Alignment::right; + }; /** From da89daf1784259f994b7be243ff848d54089af4b Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 27 May 2025 17:09:02 +0200 Subject: [PATCH 23/67] =?UTF-8?q?=F0=9F=92=84=20new=20table=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SolutionCheckHelpers.cpp | 46 ++++++++++++++----- .../fluidFlow/SolutionCheckHelpers.hpp | 3 ++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 748013e725d..c2ec3a8e208 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -68,26 +68,48 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", linesPrefix, m_ranksSignaledIdsCount, valueNaming, minValueStr ) ); - string const indentation = string( linesPrefix.size(), ' ' ); if( m_ranksCollectedIdsCount > 0 ) { - TableLayout const layout = TableLayout( GEOS_FMT( "Summary of {} element", valueNaming ), - { "Rank", "Global id", "Value" } ). + TableLayout const layout = TableLayout(). + setTitle( GEOS_FMT( "Summary of {} elements", valueNaming ) ). enableLineBreak( false ). - setIndentation( linesPrefix.size() ); + setIndentation( linesPrefix.size() ). + setMargin( TableLayout::MarginValue::small ). + setDefaultHeaderAlignment( TableLayout::Alignment::left ); TableData data; - if( m_buffer.getSignaledIdsCount() > 0 ) + integer const signaledCount = m_buffer.getSignaledIdsCount(); + integer const collectedCount = m_buffer.getCollectedIdsCount(); + + if( signaledCount > 0 ) { - integer rank = MpiWrapper::commRank(); - integer omitted = m_buffer.getSignaledIdsCount() - m_buffer.getCollectedIdsCount(); + integer const omittedCount = signaledCount - collectedCount; + // adding a columns for row name, each collected value, and one last if a "..." have to be added + integer const columnsCount = MpiWrapper::max( 1 + collectedCount + integer( omittedCount > 0 ) ); + enum class Lines : integer { Title, Separator, GlobalId, Value }; + auto & cells = data.getCellsData(); + string const title = GEOS_FMT( "Rank {}, {} / {} {} values:", + MpiWrapper::commRank(), collectedCount, signaledCount, valueNaming ); + + data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); + cells[integer( Lines::Title )].back() = { CellType::Header, title }; + + data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); - for( auto const & wrongOccurence : m_buffer ) + data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); + cells[integer( Lines::GlobalId )].front() = { CellType::Value, "Global Id" }; + for( int i = 0; i < collectedCount; ++i ) + cells[integer( Lines::GlobalId )][i+1] = { CellType::Value, std::to_string( m_buffer[i] ) }; + + data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); + cells[integer( Lines::Value )].front() = { CellType::Value, string( units::getDescription( unit ) ) }; + for( int i = 0; i < collectedCount; ++i ) + cells[integer( Lines::Value )][i+1] = { CellType::Value, std::to_string( 0.0 ) }; + + if( omittedCount > 0 ) { - data.addRow( rank, m_buffer.getSignaledIdsCount(), wrongOccurence ); + cells[integer( Lines::GlobalId )].back() = { CellType::Value, "..." }; + cells[integer( Lines::Value )].back() = { CellType::Value, "..." }; } - - if( omitted > 0 ) - data.addRow( rank, CellType::MergeNext, GEOS_FMT( "Omitted {} values ...", omitted ) ); } TableTextFormatter const formatter( layout ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index cdeb054eb90..8cccdc356df 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -84,6 +84,9 @@ class IdReporterBuffer IdCountType getCollectedIdsCount() const { return LvArray::math::min( getSignaledIdsCount(), m_idsBuffer.size() ); } + IdType operator[]( IdCountType id ) const + { return m_idsBuffer[id]; } + auto begin() const { return m_idsBuffer.begin(); } From 00d8c577c219a1785c1ebe581838d81a08719119 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 28 May 2025 11:00:31 +0200 Subject: [PATCH 24/67] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20dead=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernels/SolutionCheckKernelsHelpers.hpp | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index c73c1002d67..53dbe946583 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -110,61 +110,6 @@ class IdReporterCollector }; -// /** -// * @brief TODO -// * @tparam AtomicPolicy The policy of the atomic increment on idsCounter. -// * @tparam KernelStackArray TODO -// * @tparam IdType TODO -// * @tparam IdCountType TODO -// * @param idsCounter The ids counter to increment with an atomic operation. -// * @param idsBuffer The output id buffer, in the same memory space as idsCounter. -// * If its size is 0 (= disabled output) or not not large enought, the buffer is not filled. -// * @param id The Id to add to the buffer. -// * @return TODO -// */ -// template< typename AtomicPolicy, typename OutputStackArray, typename IdType, typename IdCountType > -// GEOS_HOST_DEVICE -// void collectKernelId( IdCountType & idsCounter, OutputStackArray & idsBuffer, IdType id ) -// { -// static constexpr IdCountType addingRequest = 1; -// IdCountType const idsBufferStart = RAJA::atomicAdd< AtomicPolicy >( &idsCounter, addingRequest ); -// if( idsBufferStart < idsBuffer.size() ) -// { -// idsBuffer[idsBufferStart] = kernelIds[i]; -// } -// } - -// // // currently unused version for adding multiple ids from a given kernel -// // template< typename ReducePolicy, typename OutputStackArray, typename KernelStackArray, typename IdCountType > -// // GEOS_HOST_DEVICE -// // void collectKernelIds( OutputStackArray & outputBuffer, -// // IdCountType & outputIdsCounter, -// // KernelStackArray const & kernelIds, -// // IdCountType const kernelIdsCount ) -// // { -// // IdCountType const outputBufferStart = RAJA::atomicAdd< ReducePolicy >( &outputIdsCounter, kernelIdsCount ); -// // IdCountType const maxNbIdToAdd = IdCountType( outputBuffer.capacity() - outputBufferStart ); -// // IdCountType const nbIdToAdd = LvArray::math::min( kernelIdsCount, maxNbIdToAdd ); -// // for( IdCountType i = 0; i < nbIdToAdd; ++i ) -// // { -// // outputBuffer[outputBufferStart + i] = kernelIds[i]; -// // } -// // } - -// template< typename OutputDynamicArray, typename InputArray, typename IdCountType > -// void aggregateIdsBuffers( OutputDynamicArray & outputBuffer, -// IdCountType & outputIdsCounter, -// InputArray const & ids, -// IdCountType const idsCount ) -// { -// outputIdsCounter += idsCount; -// IdCountType const numIdsToAdd = std::min( idsCount, IdCountType( ids.capacity() ) ); -// for( int i = 0; i < numIdsToAdd; ++i ) -// { -// outputBuffer.emplace_back( ids[i] ); // todo local -> global -// } -// } - } // namespace geos From 4a9f7803e20fb9cb676864b68eea3f5863bbea52 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 28 May 2025 14:16:22 +0200 Subject: [PATCH 25/67] =?UTF-8?q?=E2=9C=A8extending=20reported=20data=20to?= =?UTF-8?q?=20pressure/density=20(IdReporter=20->=20ElementReporter)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 8 +- .../CompositionalMultiphaseHybridFVM.cpp | 4 +- .../fluidFlow/SinglePhaseBase.cpp | 6 +- .../fluidFlow/SolutionCheckHelpers.cpp | 70 +++++++++-------- .../fluidFlow/SolutionCheckHelpers.hpp | 74 +++++++++--------- .../kernels/SolutionCheckKernelsHelpers.hpp | 76 ++++++++++--------- .../compositional/SolutionCheckKernel.hpp | 16 ++-- .../ThermalSolutionCheckKernel.hpp | 8 +- .../singlePhase/SolutionCheckKernel.hpp | 4 +- .../wells/CompositionalMultiphaseWell.cpp | 12 +-- .../fluidFlow/wells/SinglePhaseWell.cpp | 6 +- .../CompositionalMultiphaseWellKernels.hpp | 4 +- 12 files changed, 150 insertions(+), 138 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index df134c19299..bfc62957ebc 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -847,9 +847,9 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; - IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; - IdReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, @@ -929,11 +929,11 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, minTotalDens = MpiWrapper::min( minTotalDens ); numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); - rankNegPressureIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative pressure", minPres, units::Unit::Pressure ); units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; - rankNegDensityIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + rankNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative component density", minDens, massUnit ); if( numNegTotalDens > 0 ) { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index c7349278108..2a928794740 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -554,8 +554,8 @@ bool CompositionalMultiphaseHybridFVM::checkSystemSolution( DomainPartition & do elemDofKey, subRegion, localSolution, - IdReporterCollector::disabled(), - IdReporterCollector::disabled() ); + ElementsReporterCollector::disabled(), + ElementsReporterCollector::disabled() ); localCheck = std::min( localCheck, subRegionData.localMinVal ); } ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index c803c66880a..dedd3a5ef3f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -1329,7 +1329,7 @@ bool SinglePhaseBase::checkSystemSolution( DomainPartition & domain, GEOS_MARK_FUNCTION; string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); - IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; real64 minPressure = 0.0; @@ -1360,10 +1360,10 @@ bool SinglePhaseBase::checkSystemSolution( DomainPartition & domain, } ); } ); - rankNegPressureIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative pressure", minPressure, units::Unit::Pressure ); - return (m_allowNegativePressure || rankNegPressureIds.getSignaledIdsCount() == 0) ? 1 : 0; + return (m_allowNegativePressure || rankNegPressureIds.getSignaledElementsCount() == 0) ? 1 : 0; } void SinglePhaseBase::saveConvergedState( ElementSubRegionBase & subRegion ) const diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index c2ec3a8e208..f5e65d8fef4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -25,50 +25,51 @@ namespace geos { -IdReporterBuffer::IdReporterBuffer( bool enabled, IdCountType maxCollectionSize ): - m_idsCounter( enabled ? 1 : 0 ), - m_idsBuffer( enabled ? maxCollectionSize : 0 ) +ElementsReporterBuffer::ElementsReporterBuffer( bool enabled, ElementCount maxCollectionSize ): + m_elementsCounter( enabled ? 1 : 0 ), + m_elementsBuffer( enabled ? maxCollectionSize : 0 ) { if( enabled ) { - m_idsCounter.zero(); - m_idsBuffer.zero(); + m_elementsCounter.zero(); + m_elementsBuffer.zero(); } } -IdReporterCollector IdReporterBuffer::createCollector( arrayView1d< globalIndex const > const & localToGlobalId ) const +ElementsReporterCollector +ElementsReporterBuffer::createCollector( arrayView1d< globalIndex const > const & localToGlobalId ) const { - return IdReporterCollector( m_idsCounter, m_idsBuffer, localToGlobalId ); + return ElementsReporterCollector( m_elementsCounter, m_elementsBuffer, localToGlobalId ); } -IdReporterOutput IdReporterBuffer::createOutput() const +ElementsReporterOutput ElementsReporterBuffer::createOutput() const { - m_idsCounter.move( LvArray::MemorySpace::host, false ); - m_idsBuffer.move( LvArray::MemorySpace::host, false ); - return IdReporterOutput( *this ); + m_elementsCounter.move( LvArray::MemorySpace::host, false ); + m_elementsBuffer.move( LvArray::MemorySpace::host, false ); + return ElementsReporterOutput( *this ); } -IdReporterOutput::IdReporterOutput( IdReporterBuffer const & buffer ): +ElementsReporterOutput::ElementsReporterOutput( ElementsReporterBuffer const & buffer ): m_buffer( buffer ), - m_ranksSignaledIdsCount( MpiWrapper::sum( buffer.getSignaledIdsCount() ) ), - m_ranksCollectedIdsCount( MpiWrapper::sum( buffer.getCollectedIdsCount() ) ) + m_ranksSignaledElementsCount( MpiWrapper::sum( buffer.getSignaledElementsCount() ) ), + m_ranksCollectedElementsCount( MpiWrapper::sum( buffer.getCollectedElementsCount() ) ) {} -void IdReporterOutput::outputWrongValues( string_view linesPrefix, - string_view valueNaming, - real64 minValue, - units::Unit unit ) const +void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, + string_view valueNaming, + real64 minValue, + units::Unit unit ) const { if( m_buffer.enabled() ) { - if( m_ranksSignaledIdsCount > 0 ) + if( m_ranksSignaledElementsCount > 0 ) { string const minValueStr = GEOS_FMT( "{:.{}f} [{}]", minValue, 3, units::getSymbol( unit ) ); GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", - linesPrefix, m_ranksSignaledIdsCount, valueNaming, minValueStr ) ); + linesPrefix, m_ranksSignaledElementsCount, valueNaming, minValueStr ) ); - if( m_ranksCollectedIdsCount > 0 ) + if( m_ranksCollectedElementsCount > 0 ) { TableLayout const layout = TableLayout(). setTitle( GEOS_FMT( "Summary of {} elements", valueNaming ) ). @@ -77,38 +78,43 @@ void IdReporterOutput::outputWrongValues( string_view linesPrefix, setMargin( TableLayout::MarginValue::small ). setDefaultHeaderAlignment( TableLayout::Alignment::left ); TableData data; - integer const signaledCount = m_buffer.getSignaledIdsCount(); - integer const collectedCount = m_buffer.getCollectedIdsCount(); + integer const signaledCount = m_buffer.getSignaledElementsCount(); + integer const collectedCount = m_buffer.getCollectedElementsCount(); if( signaledCount > 0 ) { integer const omittedCount = signaledCount - collectedCount; // adding a columns for row name, each collected value, and one last if a "..." have to be added integer const columnsCount = MpiWrapper::max( 1 + collectedCount + integer( omittedCount > 0 ) ); - enum class Lines : integer { Title, Separator, GlobalId, Value }; auto & cells = data.getCellsData(); string const title = GEOS_FMT( "Rank {}, {} / {} {} values:", - MpiWrapper::commRank(), collectedCount, signaledCount, valueNaming ); + MpiWrapper::commRank(), + collectedCount, + signaledCount, + valueNaming ); + static constexpr integer titleLine = 0; + static constexpr integer globalIdLine = 2; + static constexpr integer valueLine = 3; data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); - cells[integer( Lines::Title )].back() = { CellType::Header, title }; + cells[titleLine].back() = { CellType::Header, title }; data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); - cells[integer( Lines::GlobalId )].front() = { CellType::Value, "Global Id" }; + cells[globalIdLine].front() = { CellType::Value, "Global Id" }; for( int i = 0; i < collectedCount; ++i ) - cells[integer( Lines::GlobalId )][i+1] = { CellType::Value, std::to_string( m_buffer[i] ) }; + cells[globalIdLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_id ) }; data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); - cells[integer( Lines::Value )].front() = { CellType::Value, string( units::getDescription( unit ) ) }; + cells[valueLine].front() = { CellType::Value, string( units::getDescription( unit ) ) }; for( int i = 0; i < collectedCount; ++i ) - cells[integer( Lines::Value )][i+1] = { CellType::Value, std::to_string( 0.0 ) }; + cells[valueLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_value ) }; if( omittedCount > 0 ) { - cells[integer( Lines::GlobalId )].back() = { CellType::Value, "..." }; - cells[integer( Lines::Value )].back() = { CellType::Value, "..." }; + cells[globalIdLine].back() = { CellType::Value, "..." }; + cells[valueLine].back() = { CellType::Value, "..." }; } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index 8cccdc356df..434285dde35 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -26,96 +26,94 @@ namespace geos { -class IdReporterOutput +class ElementsReporterOutput { public: - using IdCountType = IdReporterCollector::IdCountType; - using IdType = IdReporterCollector::IdType; + using ElementCount = ElementsReporterCollector::ElementCount; - IdReporterOutput( IdReporterBuffer const & buffer ); + ElementsReporterOutput( ElementsReporterBuffer const & buffer ); - IdCountType getRanksSignaledIdsCount() const - { return m_ranksSignaledIdsCount; } + ElementCount getRanksSignaledIdsCount() const + { return m_ranksSignaledElementsCount; } - IdCountType getRanksCollectedIdsCount() const - { return m_ranksCollectedIdsCount; } + ElementCount getRanksCollectedIdsCount() const + { return m_ranksCollectedElementsCount; } - void outputWrongValues( string_view linesPrefix, - string_view valueNaming, - real64 minValue, - units::Unit valueUnit ) const; + void outputTooLowValues( string_view linesPrefix, + string_view valueNaming, + real64 minValue, + units::Unit valueUnit ) const; private: - IdReporterBuffer const & m_buffer; + ElementsReporterBuffer const & m_buffer; - IdCountType m_ranksSignaledIdsCount; + ElementCount m_ranksSignaledElementsCount; - IdCountType m_ranksCollectedIdsCount; + ElementCount m_ranksCollectedElementsCount; }; -class IdReporterBuffer +class ElementsReporterBuffer { public: - using IdCountType = IdReporterCollector::IdCountType; - using IdType = IdReporterCollector::IdType; + using ElementCount = ElementsReporterCollector::ElementCount; /** * @brief Construct a preallocated buffer to collect a limited quantity of ids in kernels. * @param maxCollectionSize Limit of the buffer. * If 0, the buffering functionnality is disabled and only the counting is enabled. */ - IdReporterBuffer( bool enabled, IdCountType maxCollectionSize ); + ElementsReporterBuffer( bool enabled, ElementCount maxCollectionSize ); // TODO: Proper docs. can be moved without any issue. - IdReporterBuffer( IdReporterBuffer && other ) = default; - IdReporterBuffer & operator=( IdReporterBuffer && other ) = default; + ElementsReporterBuffer( ElementsReporterBuffer && other ) = default; + ElementsReporterBuffer & operator=( ElementsReporterBuffer && other ) = default; // TODO: Proper docs. copying prevented has it doesn't seem useful / relevant. - IdReporterBuffer( IdReporterBuffer const & other ) = delete; - IdReporterBuffer & operator=( IdReporterBuffer const & other ) = delete; + ElementsReporterBuffer( ElementsReporterBuffer const & other ) = delete; + ElementsReporterBuffer & operator=( ElementsReporterBuffer const & other ) = delete; - IdCountType getSignaledIdsCount() const - { return m_idsCounter.empty() ? 0 : m_idsCounter[0]; } + ElementCount getSignaledElementsCount() const + { return m_elementsCounter.empty() ? 0 : m_elementsCounter[0]; } - IdCountType getCollectedIdsCount() const - { return LvArray::math::min( getSignaledIdsCount(), m_idsBuffer.size() ); } + ElementCount getCollectedElementsCount() const + { return LvArray::math::min( getSignaledElementsCount(), m_elementsBuffer.size() ); } - IdType operator[]( IdCountType id ) const - { return m_idsBuffer[id]; } + ElementReport operator[]( ElementCount id ) const + { return m_elementsBuffer[id]; } auto begin() const - { return m_idsBuffer.begin(); } + { return m_elementsBuffer.begin(); } auto end() const - { return m_idsBuffer.begin() + getCollectedIdsCount(); } + { return m_elementsBuffer.begin() + getCollectedElementsCount(); } bool enabled() const - { return !m_idsCounter.empty(); } + { return !m_elementsCounter.empty(); } bool empty() const - { return getCollectedIdsCount() == 0; } + { return getCollectedElementsCount() == 0; } bool isComplete() const - { return getCollectedIdsCount() < getSignaledIdsCount(); } + { return getCollectedElementsCount() < getSignaledElementsCount(); } /** * @return A view on the ids array owned by the instance. -> change comment to explain the interest for kernels */ - IdReporterCollector createCollector( arrayView1d< globalIndex const > const & localToGlobalId ) const; + ElementsReporterCollector createCollector( arrayView1d< globalIndex const > const & localToGlobalId ) const; - IdReporterOutput createOutput() const; + ElementsReporterOutput createOutput() const; private: // array of one element to get benefit of managed host-device memory. - array1d< IdCountType > m_idsCounter; + array1d< ElementCount > m_elementsCounter; // ids of detected elements - array1d< IdType > m_idsBuffer; + array1d< ElementReport > m_elementsBuffer; }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 53dbe946583..62d628fe30d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -25,86 +25,94 @@ namespace geos { -class IdReporterBuffer; +class ElementsReporterBuffer; + +struct ElementReport +{ + /// the global id of the reported element + globalIndex m_id; + /// a single value to report for the given element (i.e. a negative pressure, a density...) + real64 m_value; +}; /** * @brief TODO - * @tparam IdCountType TODO + * @tparam ElementCount TODO * @tparam IdType TODO */ -class IdReporterCollector +class ElementsReporterCollector { - friend class IdReporterBuffer; + friend class ElementsReporterBuffer; public: - using IdCountType = int32_t; - using IdType = globalIndex; + using ElementCount = int32_t; // TODO : proper docs. can be copied & moved as this class only has views to the internal chai memory buffers - IdReporterCollector( IdReporterCollector const & other ) = default; - IdReporterCollector( IdReporterCollector && other ) = default; - IdReporterCollector & operator=( IdReporterCollector const & other ) = default; - IdReporterCollector & operator=( IdReporterCollector && other ) = default; + ElementsReporterCollector( ElementsReporterCollector const & other ) = default; + ElementsReporterCollector( ElementsReporterCollector && other ) = default; + ElementsReporterCollector & operator=( ElementsReporterCollector const & other ) = default; + ElementsReporterCollector & operator=( ElementsReporterCollector && other ) = default; - static IdReporterCollector disabled() + static ElementsReporterCollector disabled() { - return IdReporterCollector( arrayView1d< IdCountType >(), - arrayView1d< IdType >(), - arrayView1d< globalIndex const >() ); + return ElementsReporterCollector( arrayView1d< ElementCount >(), + arrayView1d< ElementReport >(), + arrayView1d< globalIndex const >() ); } /** * @brief TODO * @tparam CollectorAtomicPolicy The policy of the atomic increment on the ids counter. - * @param m_idsCounter The ids counter to increment with an atomic operation. - * @param m_idsBuffer The output id buffer, in the same memory space as m_idsCounter. + * @param m_elementsCounter The ids counter to increment with an atomic operation. + * @param m_elementsBuffer The output id buffer, in the same memory space as m_elementsCounter. * If its size is 0 (= disabled output) or not not large enought, the buffer is not filled. * @param id The Id to add to the buffer. */ template< typename CollectorAtomicPolicy > GEOS_HOST_DEVICE - void collectId( CollectorAtomicPolicy, IdType id ) const + void collectElement( CollectorAtomicPolicy, ElementReport const & report ) const { - if( !m_idsCounter.empty() ) + if( !m_elementsCounter.empty() ) { - IdCountType const outputStart = RAJA::atomicInc< CollectorAtomicPolicy >( &m_idsCounter[0] ); + ElementCount const outputStart = RAJA::atomicInc< CollectorAtomicPolicy >( &m_elementsCounter[0] ); - if( outputStart < m_idsBuffer.size() ) + if( outputStart < m_elementsBuffer.size() ) { - m_idsBuffer[outputStart] = m_localToGlobalId[id]; + m_elementsBuffer[outputStart].m_id = m_localToGlobalId[report.m_id]; + m_elementsBuffer[outputStart].m_value = report.m_value; } } } // // currently unused version for adding multiple ids from a given kernel - // template< typename AddedArray, typename IdCountType > + // template< typename AddedArray, typename ElementCount > // GEOS_HOST_DEVICE - // void collectIds( AddedArray const & newIds, IdCountType newIdsCount ) + // void collectIds( AddedArray const & newIds, ElementCount newIdsCount ) // { - // IdCountType const outputStart = RAJA::atomicAdd< CollectorAtomicPolicy >( &m_idsCounter[0], newIdsCount ); - // IdCountType const maxNbIdToAdd = IdCountType( m_idsBuffer.size() - outputStart ); + // ElementCount const outputStart = RAJA::atomicAdd< CollectorAtomicPolicy >( &m_elementsCounter[0], newIdsCount ); + // ElementCount const maxNbIdToAdd = ElementCount( m_elementsBuffer.size() - outputStart ); // newIdsCount = LvArray::math::min( newIdsCount, maxNbIdToAdd ); - // for( IdCountType i = 0; i < newIdsCount; ++i ) + // for( ElementCount i = 0; i < newIdsCount; ++i ) // { - // m_idsBuffer[outputStart + i] = newIds[i]; + // m_elementsBuffer[outputStart + i] = newIds[i]; // } // } private: // array of one element to get benefit of chai managed memory. - arrayView1d< IdCountType > m_idsCounter; + arrayView1d< ElementCount > m_elementsCounter; // ids of detected elements, quantity limited to 'maxIdsCount' - arrayView1d< IdType > m_idsBuffer; + arrayView1d< ElementReport > m_elementsBuffer; arrayView1d< globalIndex const > m_localToGlobalId; - IdReporterCollector( arrayView1d< IdCountType > const & idsCounter, - arrayView1d< IdType > const & idsArray, - arrayView1d< globalIndex const > const & localToGlobalId ): - m_idsCounter( idsCounter ), - m_idsBuffer( idsArray ), + ElementsReporterCollector( arrayView1d< ElementCount > const & elementsCounter, + arrayView1d< ElementReport > const & elementsBuffer, + arrayView1d< globalIndex const > const & localToGlobalId ): + m_elementsCounter( elementsCounter ), + m_elementsBuffer( elementsBuffer ), m_localToGlobalId( localToGlobalId ) {} diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 4ea7c458bb7..a510181508f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -75,8 +75,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer string const dofKey, ElementSubRegionBase const & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector const & negPressureIds, - IdReporterCollector const & negDensityIds ) + ElementsReporterCollector const & negPressureIds, + ElementsReporterCollector const & negDensityIds ) : Base( rankOffset, numComp, dofKey, @@ -181,10 +181,10 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer minTotalDens.min( stack.localMinNegTotalDens ); if( stack.localNumNegPres > 0 ) - kernelComponent.m_negPressureIds.collectId( atomicPolicy{}, ei ); + kernelComponent.m_negPressureIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegPres } ); if( stack.localNumNegDens > 0 ) - kernelComponent.m_negDensityIds.collectId( atomicPolicy{}, ei ); + kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegDens } ); numNegTotalDens += stack.localNumNegTotalDens; } ); @@ -303,9 +303,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer /// scaling type (global or local) compositionalMultiphaseUtilities::ScalingType const m_scalingType; - IdReporterCollector const m_negPressureIds; + ElementsReporterCollector const m_negPressureIds; - IdReporterCollector const m_negDensityIds; + ElementsReporterCollector const m_negDensityIds; }; @@ -342,8 +342,8 @@ class SolutionCheckKernelFactory string const dofKey, ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector const & negPressureIds, - IdReporterCollector const & negDensityIds ) // TODO : ajouter bool reportWrongValues + ElementsReporterCollector const & negPressureIds, + ElementsReporterCollector const & negDensityIds ) // TODO : ajouter bool reportWrongValues { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp index 283702a665d..455eec757dd 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp @@ -73,8 +73,8 @@ class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels: string const dofKey, ElementSubRegionBase const & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector const & negPressureIds, - IdReporterCollector const & negDensityIds, + ElementsReporterCollector const & negPressureIds, + ElementsReporterCollector const & negDensityIds, integer const temperatureOffset ) : Base( allowCompDensChopping, allowNegativePressure, @@ -166,8 +166,8 @@ class SolutionCheckKernelFactory string const dofKey, ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector const & negPressureIds, - IdReporterCollector const & negDensityIds, + ElementsReporterCollector const & negPressureIds, + ElementsReporterCollector const & negDensityIds, integer temperatureOffset ) { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp index bfbe3021863..46ee6972ed0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp @@ -47,7 +47,7 @@ struct SolutionCheckKernel arrayView1d< integer const > const & ghostRank, arrayView1d< real64 const > const & pres, real64 const scalingFactor, - IdReporterCollector const & negPressureIds ) + ElementsReporterCollector const & negPressureIds ) { using reducePolicy = ReducePolicy< POLICY >; using atomicPolicy = AtomicPolicy< POLICY >; @@ -63,7 +63,7 @@ struct SolutionCheckKernel if( newPres < 0.0 ) { minNegPres.min( newPres ); - negPressureIds.collectId( atomicPolicy{}, ei ); + negPressureIds.collectElement( atomicPolicy{}, { ei, newPres } ); } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 679416a5259..def53f3c8a1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1538,8 +1538,8 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, wellDofKey, subRegion, localSolution, - IdReporterCollector::disabled(), - IdReporterCollector::disabled() ); + ElementsReporterCollector::disabled(), + ElementsReporterCollector::disabled() ); if( !subRegionData.localMinVal ) { @@ -1556,9 +1556,9 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; - IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), + ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; - IdReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), + ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), isLogLevelActive< logInfo::WellValidityDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, @@ -1641,11 +1641,11 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, minTotalDens = MpiWrapper::min( minTotalDens ); numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); - rankNegPressureIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative pressure", minPres, units::Unit::Pressure ); units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; - rankNegDensityIds.createOutput().outputWrongValues( GEOS_FMT( " {}: ", getName() ), + rankNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative component density", minDens, massUnit ); if( numNegTotalDens > 0 ) { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index de44a4d6539..e8c102e14a5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -884,7 +884,7 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, GEOS_MARK_FUNCTION; string const wellDofKey = dofManager.getKey( wellElementDofName() ); - IdReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), + ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; real64 minNegPres = 0.0; @@ -925,8 +925,8 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, } ); } ); - IdReporterOutput const rankNegPressureIdsOutput = rankNegPressureIds.createOutput(); - rankNegPressureIdsOutput.outputWrongValues( GEOS_FMT( " {}: ", getName() ), + ElementsReporterOutput const rankNegPressureIdsOutput = rankNegPressureIds.createOutput(); + rankNegPressureIdsOutput.outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative pressure", minNegPres, units::Unit::Pressure ); return (m_allowNegativePressure || rankNegPressureIdsOutput.getRanksSignaledIdsCount() == 0) ? 1 : 0; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index 5c985e67efc..020a1db3b3a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -821,8 +821,8 @@ class SolutionCheckKernelFactory string const dofKey, ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, - IdReporterCollector const & negPressureIds, - IdReporterCollector const & negDensityIds ) + ElementsReporterCollector const & negPressureIds, + ElementsReporterCollector const & negDensityIds ) { isothermalCompositionalMultiphaseBaseKernels:: From 66f2d727e9c1df6c1c5c805082e5be0f76db5657 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 28 May 2025 14:33:57 +0200 Subject: [PATCH 26/67] =?UTF-8?q?=E2=9C=A8=20adding=20info=20to=20warn=20t?= =?UTF-8?q?he=20user=20to=20increase=20a=20logLevel=20to=20get=20the=20rep?= =?UTF-8?q?ort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index f5e65d8fef4..afc2cc37543 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -57,9 +57,9 @@ ElementsReporterOutput::ElementsReporterOutput( ElementsReporterBuffer const & b {} void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, - string_view valueNaming, - real64 minValue, - units::Unit unit ) const + string_view valueNaming, + real64 minValue, + units::Unit unit ) const { if( m_buffer.enabled() ) { @@ -121,6 +121,11 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, TableTextFormatter const formatter( layout ); GEOS_LOG( formatter.toString( data ) ); } + else + { + GEOS_LOG( GEOS_FMT( "{}Increase the log level to enable a reporting of the {} values.", + string( linesPrefix.size(), ' ' ), valueNaming ) ); + } } } } From 854dc3e11a464e60b365edf729b1c09a06172c64 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 28 May 2025 14:34:17 +0200 Subject: [PATCH 27/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20minor=20refactor=20o?= =?UTF-8?q?f=20TableFormatter.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableFormatter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 68fcd3f1a54..7bc4ebf97c7 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -18,7 +18,6 @@ * @file TableFormatter.cpp */ -#include "TableFormatter.hpp" #include #include "common/format/StringUtilities.hpp" #include "common/logger/Logger.hpp" @@ -696,4 +695,5 @@ void TableTextFormatter::outputLines( PreparedTableLayout const & tableLayout, idxRow++; } } -} + +} /* namespace geos */ From 6487d6c2b3e774eb86e0ea64f4a6f389cb99e6f2 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 2 Jun 2025 14:13:33 +0200 Subject: [PATCH 28/67] =?UTF-8?q?=E2=9C=A8=20=F0=9F=A7=AA=20=20first=20att?= =?UTF-8?q?empt=20at=20creating=20MPI=20tables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/CMakeLists.txt | 10 +- .../common/format/table/TableFormatter.cpp | 12 ++- .../common/format/table/TableFormatter.hpp | 7 +- .../format/table/TableMpiComponents.cpp | 98 +++++++++++++++++++ .../format/table/TableMpiComponents.hpp | 90 +++++++++++++++++ .../fluidFlow/SolutionCheckHelpers.cpp | 7 +- 6 files changed, 212 insertions(+), 12 deletions(-) create mode 100644 src/coreComponents/common/format/table/TableMpiComponents.cpp create mode 100644 src/coreComponents/common/format/table/TableMpiComponents.hpp diff --git a/src/coreComponents/common/CMakeLists.txt b/src/coreComponents/common/CMakeLists.txt index 287b0ceee3d..40cb2ce186d 100644 --- a/src/coreComponents/common/CMakeLists.txt +++ b/src/coreComponents/common/CMakeLists.txt @@ -25,9 +25,10 @@ Also provides commonly used components for such as logging, formatting, memory a # set( common_headers ${CMAKE_BINARY_DIR}/include/common/GeosxConfig.hpp - format/table/TableLayout.hpp - format/table/TableFormatter.hpp format/table/TableData.hpp + format/table/TableFormatter.hpp + format/table/TableLayout.hpp + format/table/TableMpiComponents.hpp format/EnumStrings.hpp format/LogPart.hpp format/Format.hpp @@ -70,9 +71,10 @@ endif( ) # Specify all sources # set( common_sources - format/table/TableLayout.cpp - format/table/TableFormatter.cpp format/table/TableData.cpp + format/table/TableFormatter.cpp + format/table/TableLayout.cpp + format/table/TableMpiComponents.cpp format/LogPart.cpp format/StringUtilities.cpp logger/Logger.cpp diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 7bc4ebf97c7..4c77daaad9a 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -146,7 +146,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) initalizeTableGrids( m_tableLayout, tableData, headerCellsLayout, dataCellsLayout, - tableTotalWidth ); + tableTotalWidth, nullptr ); string const sepLine = string( tableTotalWidth, m_horizontalLine ); outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, sepLine ); @@ -160,7 +160,8 @@ void TableTextFormatter::initalizeTableGrids( PreparedTableLayout const & tableL TableData const & tableInputData, CellLayoutRows & headerCellsLayout, CellLayoutRows & dataCellsLayout, - size_t & tableTotalWidth ) const + size_t & tableTotalWidth, + ColumnWidthModifier columnWidthModifier ) const { RowsCellInput const & inputDataValues( tableInputData.getCellsData() ); bool const hasColumnLayout = tableLayout.getColumnLayersCount() > 0; @@ -189,6 +190,9 @@ void TableTextFormatter::initalizeTableGrids( PreparedTableLayout const & tableL stretchColumnsByMergedCellsWidth( columnsWidth, headerCellsLayout, tableLayout, false ); stretchColumnsByMergedCellsWidth( columnsWidth, dataCellsLayout, tableLayout, true ); + if( columnWidthModifier ) + columnWidthModifier( columnsWidth ); + // the columns width array is now sized after all the table, we can compute the total table width tableTotalWidth = tableLayout.getBorderMargin() * 2 + 2; for( size_t columnId = 0; columnId < columnsWidth.size(); ++columnId ) @@ -383,8 +387,8 @@ void TableTextFormatter::populateDataCellsLayout( PreparedTableLayout const & ta string_view( &m_horizontalLine, 1 ) : string_view( inputCell.value ); TableLayout::Alignment const alignment = inputCell.type == CellType::Header ? - tableLayout.getDefaultHeaderAlignment() : - tableLayout.getDefaultValueAlignment(); + tableLayout.getDefaultHeaderAlignment() : + tableLayout.getDefaultValueAlignment(); TableLayout::CellLayout & outputCell = outputRow.cells[idxColumn]; outputCell = TableLayout::CellLayout( inputCell.type, alignment ); diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 10f2aa550c5..299b0e3f793 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -165,6 +165,9 @@ class TableTextFormatter : public TableFormatter /// for the extremity of a row static constexpr char m_horizontalLine = '-'; + /// A functor which allow to customize the columns width after their computation. + using ColumnWidthModifier = std::function< void( stdVector< size_t > & ) >; + /** * @brief Initializes the table layout with the given table data and prepares necessary layouts for headers and data cells. * @param tableLayout A reference to the `TableLayout` object. @@ -172,12 +175,14 @@ class TableTextFormatter : public TableFormatter * @param headerCellsLayout A reference to a `CellLayoutRows` where the header cells will be populated. * @param dataCellsLayout A reference to a `CellLayoutRows` where the data cells will be populated. * @param tableTotalWidth A string that will be used as the table separator line + * @param columnWidthModifier A functor which allow to customize the columns width after their computation. */ void initalizeTableGrids( PreparedTableLayout const & tableLayout, TableData const & tableData, CellLayoutRows & dataCellsLayout, CellLayoutRows & headerCellsLayout, - size_t & tableTotalWidth ) const; + size_t & tableTotalWidth, + ColumnWidthModifier columnWidthModifier ) const; /** * @brief Outputs the formatted table to the provided output stream. diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp new file mode 100644 index 00000000000..050c941a511 --- /dev/null +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -0,0 +1,98 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 TotalEnergies + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + + +/** + * @file TableMpiComponents.cpp + */ + +#include "TableMpiComponents.hpp" +#include "common/MpiWrapper.hpp" +#include "common/format/StringUtilities.hpp" // todo delete + +namespace geos +{ + +TableTextMpiOutput::TableTextMpiOutput( ParallelOutputMode parallelOutputMode ): + TableTextFormatter(), + m_parallelOutputMode( parallelOutputMode ) +{} + +TableTextMpiOutput::TableTextMpiOutput( TableLayout const & tableLayout, + ParallelOutputMode parallelOutputMode ): + TableTextFormatter( tableLayout ), + m_parallelOutputMode( parallelOutputMode ) +{} + +template<> +void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, + TableData const & tableData ) const +{ + // only the master rank does the output of the header && bottom of the table + bool isMasterRank = MpiWrapper::commRank() == 0; + // some ranks does not have any output to produce, they can sleep while waiting the next barrier. + bool isContributing = !tableData.getCellsData().empty() || isMasterRank; + + CellLayoutRows headerCellsLayout; + CellLayoutRows dataCellsLayout; + size_t tableTotalWidth = 0; + string sepLine; + + MPI_Barrier( MPI_COMM_GEOS ); + + { + ColumnWidthModifier const columnWidthModifier = [this]( stdVector< size_t > & columnsWidth ) { + stretchColumnsByRanks( columnsWidth ); + }; + initalizeTableGrids( m_tableLayout, tableData, + headerCellsLayout, dataCellsLayout, + tableTotalWidth, columnWidthModifier ); + } + MPI_Barrier( MPI_COMM_GEOS ); + + if( isMasterRank ) + { + sepLine = string( tableTotalWidth, m_horizontalLine ); + outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, sepLine ); + tableOutput.flush(); + } + MPI_Barrier( MPI_COMM_GEOS ); + + if( isContributing ) + { + outputTableData( tableOutput, m_tableLayout, dataCellsLayout, + m_parallelOutputMode == ParallelOutputMode::MixedRanksRows ); + + if( m_parallelOutputMode == ParallelOutputMode::InsecableRanks ) + tableOutput.flush(); + } + MPI_Barrier( MPI_COMM_GEOS ); + + if( isMasterRank ) + { + outputTableBottom( tableOutput, m_tableLayout, sepLine, !dataCellsLayout.empty() ); + tableOutput.flush(); + } + +} + +void TableTextMpiOutput::stretchColumnsByRanks( stdVector< size_t > & columnsWidth ) const +{ + stdVector< size_t > oldColumnsWidth( columnsWidth ); + MpiWrapper::allReduce( oldColumnsWidth, columnsWidth, int( columnsWidth.size() ), + MpiWrapper::Reduction::Max, MPI_COMM_GEOS ); +} + +} /* namespace geos */ diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp new file mode 100644 index 00000000000..df4a6fdbbae --- /dev/null +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -0,0 +1,90 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 TotalEnergies + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableMpiComponents.hpp + * @brief contains variation of tables components for MPI communication. + */ + +#ifndef GEOS_COMMON_FORMAT_TABLE_TABLEMPICOMPONENTS_HPP +#define GEOS_COMMON_FORMAT_TABLE_TABLEMPICOMPONENTS_HPP + +#include "TableFormatter.hpp" + +namespace geos +{ + +/** + * @brief class to format data in a formatted text format, allowing contributions from multiple + * MPI ranks. + */ +class TableTextMpiOutput : public TableTextFormatter +{ +public: + + using Base = TableTextFormatter; + + enum class ParallelOutputMode + { + /// Each ranks output cannot be mixed with the content of other ranks. Each rank flushes after full output. + InsecableRanks, + /// The rows of every ranks are output randomly. Each rank flushes after each row formatting. + MixedRanksRows, + }; + + /** + * @brief Construct a default Table Formatter without layout specification (to only insert data in it, + * without any column / title). Feature is not tested. + */ + TableTextMpiOutput( ParallelOutputMode parallelOutputMode = ParallelOutputMode::MixedRanksRows ); + + /** + * @brief Construct a new TableTextMpiOutput from a tableLayout + * @param tableLayout Contain all tableColumnData names and optionnaly the table title + */ + TableTextMpiOutput( TableLayout const & tableLayout, + ParallelOutputMode parallelOutputMode = ParallelOutputMode::MixedRanksRows ); + + /** + * @brief Convert a data source to a table string. + * @param tableData The data source to convert. + * @param outputStream The same target output stream for all ranks, to output the table string + * representation of the TableData. The output is partial, each rank + * contributing to common output stream with their local data. It may be the + * log or a file stream. + */ + template< typename DATASOURCE > + void toStream( std::ostream & outputStream, DATASOURCE const & tableData ) const; + +private: + + // hiding toString() methods as they are not implemented with MPI support. + using Base::toString; + + ParallelOutputMode m_parallelOutputMode; + + /** + * @brief Expend the columns width to accomodate with the content of all MPI ranks. + * As it is based on MPI communications, every ranks must call this method. + * @param columnsWidth The array to store the resulting columns width in. + * @param tableGrid The grid of cells containing content. + */ + void stretchColumnsByRanks( stdVector< size_t > & columnsWidth ) const; + +}; + +} + +#endif /* GEOS_COMMON_FORMAT_TABLE_TABLEMPICOMPONENTS_HPP */ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index afc2cc37543..9c05ae1da0f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -20,7 +20,7 @@ #include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" #include "common/MpiWrapper.hpp" #include "common/format/StringUtilities.hpp" -#include "common/format/table/TableFormatter.hpp" +#include "common/format/table/TableMpiComponents.hpp" namespace geos { @@ -118,8 +118,9 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, } } - TableTextFormatter const formatter( layout ); - GEOS_LOG( formatter.toString( data ) ); + auto const outputStrat = TableTextMpiOutput::ParallelOutputMode::InsecableRanks; + TableTextMpiOutput const formatter = TableTextMpiOutput( layout, outputStrat ); + formatter.toStream( std::cout, data ); } else { From 6a43cb9dd0d24def34d0acad25ed376cf1c0a8df Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 3 Jun 2025 18:24:38 +0200 Subject: [PATCH 29/67] =?UTF-8?q?=E2=9C=A8=20finishing=20MPI=20tables=20wi?= =?UTF-8?q?th=20a=20different=20approach=20(log=20output=20on=20rank0=20on?= =?UTF-8?q?ly)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableFormatter.cpp | 14 +-- .../common/format/table/TableFormatter.hpp | 11 +- .../format/table/TableMpiComponents.cpp | 118 +++++++++++++----- .../format/table/TableMpiComponents.hpp | 34 +++-- .../fluidFlow/SolutionCheckHelpers.cpp | 17 +-- 5 files changed, 124 insertions(+), 70 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 4c77daaad9a..a3037ccbb3f 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -150,7 +150,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) string const sepLine = string( tableTotalWidth, m_horizontalLine ); outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, sepLine ); - outputTableData( tableOutput, m_tableLayout, dataCellsLayout, false ); + outputTableData( tableOutput, m_tableLayout, dataCellsLayout ); outputTableBottom( tableOutput, m_tableLayout, sepLine, !dataCellsLayout.empty() ); return tableOutput.str(); @@ -573,17 +573,16 @@ void TableTextFormatter::outputTableHeader( std::ostream & tableOutput, tableOutput << '\n'; } tableOutput << tableLayout.getIndentationStr() << sepLine << '\n'; - outputLines( tableLayout, headerCellsLayout, tableOutput, false ); + outputLines( tableLayout, headerCellsLayout, tableOutput ); } void TableTextFormatter::outputTableData( std::ostream & tableOutput, PreparedTableLayout const & tableLayout, - CellLayoutRows const & dataCellsLayout, - bool flushAfterEachLines ) const + CellLayoutRows const & dataCellsLayout ) const { if( !dataCellsLayout.empty() ) { - outputLines( tableLayout, dataCellsLayout, tableOutput, flushAfterEachLines ); + outputLines( tableLayout, dataCellsLayout, tableOutput ); } } @@ -640,8 +639,7 @@ void TableTextFormatter::formatCell( std::ostream & tableOutput, void TableTextFormatter::outputLines( PreparedTableLayout const & tableLayout, CellLayoutRows const & rows, - std::ostream & tableOutput, - bool flushOnEachLines ) const + std::ostream & tableOutput ) const { size_t const nbRows = rows.size(); size_t const nbColumns = !rows.empty() ? rows[0].cells.size() : 0; @@ -690,8 +688,6 @@ void TableTextFormatter::outputLines( PreparedTableLayout const & tableLayout, else { // right table border tableOutput << string( nbBorderSpaces, cellSpaceChar ) << m_verticalLine << "\n"; - if( flushOnEachLines ) - tableOutput << std::flush; } } } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 299b0e3f793..11baa4deeeb 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -199,16 +199,13 @@ class TableTextFormatter : public TableFormatter /** * @brief Outputs the formatted table to the provided output stream. - * @param tableLayout The layout of the table * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. - * @param headerCellsLayout The layout of the header rows + * @param tableLayout The layout of the table * @param dataCellsLayout The layout of the data rows - * @param separatorLine A string that will be used as the table separator line */ void outputTableData( std::ostream & tableOutput, PreparedTableLayout const & tableLayout, - CellLayoutRows const & dataCellsLayout, - bool flushAfterEachLines ) const; + CellLayoutRows const & dataCellsLayout ) const; /** * @brief Outputs the formatted table to the provided output stream. @@ -321,12 +318,10 @@ class TableTextFormatter : public TableFormatter * @param tableLayout The layout of the table * @param cellsLayout A collection of rows, each containing a layout of cells to be processed and formatted. * @param tableOutput The output stream - * @param flushOnEachLines flush the output stream each time a line is finished */ void outputLines( PreparedTableLayout const & tableLayout, CellLayoutRows const & cellsLayout, - std::ostream & tableOutput, - bool flushOnEachLines ) const; + std::ostream & tableOutput ) const; }; /** diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index 050c941a511..740532d3d1a 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -25,74 +25,126 @@ namespace geos { -TableTextMpiOutput::TableTextMpiOutput( ParallelOutputMode parallelOutputMode ): +TableTextMpiOutput::TableTextMpiOutput( TableMpiLayout mpiLayout ): TableTextFormatter(), - m_parallelOutputMode( parallelOutputMode ) + m_mpiLayout( mpiLayout ) {} TableTextMpiOutput::TableTextMpiOutput( TableLayout const & tableLayout, - ParallelOutputMode parallelOutputMode ): + TableMpiLayout mpiLayout ): TableTextFormatter( tableLayout ), - m_parallelOutputMode( parallelOutputMode ) + m_mpiLayout( mpiLayout ) {} template<> void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, TableData const & tableData ) const { - // only the master rank does the output of the header && bottom of the table - bool isMasterRank = MpiWrapper::commRank() == 0; - // some ranks does not have any output to produce, they can sleep while waiting the next barrier. - bool isContributing = !tableData.getCellsData().empty() || isMasterRank; + TableTextMpiOutputStatus status { + // m_isMasterRank (only the master rank does the output of the header && bottom of the table) + MpiWrapper::commRank() == 0, + // m_isContributing (some ranks does not have any output to produce) + !tableData.getCellsData().empty(), + // m_sepLine + "" + }; CellLayoutRows headerCellsLayout; CellLayoutRows dataCellsLayout; size_t tableTotalWidth = 0; - string sepLine; - - MPI_Barrier( MPI_COMM_GEOS ); { - ColumnWidthModifier const columnWidthModifier = [this]( stdVector< size_t > & columnsWidth ) { - stretchColumnsByRanks( columnsWidth ); + ColumnWidthModifier const columnWidthModifier = [this, status]( stdVector< size_t > & columnsWidth ) { + stretchColumnsByRanks( columnsWidth, status ); }; initalizeTableGrids( m_tableLayout, tableData, headerCellsLayout, dataCellsLayout, tableTotalWidth, columnWidthModifier ); } - MPI_Barrier( MPI_COMM_GEOS ); - if( isMasterRank ) + if( status.m_isMasterRank ) { - sepLine = string( tableTotalWidth, m_horizontalLine ); - outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, sepLine ); + status.m_sepLine = string( tableTotalWidth, m_horizontalLine ); + outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, status.m_sepLine ); tableOutput.flush(); } - MPI_Barrier( MPI_COMM_GEOS ); - - if( isContributing ) - { - outputTableData( tableOutput, m_tableLayout, dataCellsLayout, - m_parallelOutputMode == ParallelOutputMode::MixedRanksRows ); - if( m_parallelOutputMode == ParallelOutputMode::InsecableRanks ) - tableOutput.flush(); - } - MPI_Barrier( MPI_COMM_GEOS ); + outputTableDataToRank0( tableOutput, m_tableLayout, dataCellsLayout, status ); - if( isMasterRank ) + if( status.m_isMasterRank ) { - outputTableBottom( tableOutput, m_tableLayout, sepLine, !dataCellsLayout.empty() ); + outputTableBottom( tableOutput, m_tableLayout, status.m_sepLine, !dataCellsLayout.empty() ); tableOutput.flush(); } +} +void TableTextMpiOutput::stretchColumnsByRanks( stdVector< size_t > & columnsWidth, + TableTextMpiOutputStatus const status ) const +{ + size_t const rankColumnsCount = columnsWidth.size(); + size_t const maxRanksColumnsCount = MpiWrapper::max( rankColumnsCount ); + + if( status.m_isContributing ) + GEOS_ASSERT_EQ( rankColumnsCount, maxRanksColumnsCount ); // TODO: contribute to the new table error system with this one + + columnsWidth.resize( maxRanksColumnsCount, 0 ); + + MpiWrapper::allReduce( columnsWidth, columnsWidth, MpiWrapper::Reduction::Max ); } -void TableTextMpiOutput::stretchColumnsByRanks( stdVector< size_t > & columnsWidth ) const +void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + CellLayoutRows const & dataCellsLayout, + TableTextMpiOutputStatus const status ) const { - stdVector< size_t > oldColumnsWidth( columnsWidth ); - MpiWrapper::allReduce( oldColumnsWidth, columnsWidth, int( columnsWidth.size() ), - MpiWrapper::Reduction::Max, MPI_COMM_GEOS ); + integer const ranksCount = MpiWrapper::commSize(); + + // master rank does the output directly to the output, other ranks will have to send it through a string. + std::ostringstream localStringStream; + std::ostream & rankOutput = status.m_isMasterRank ? tableOutput : localStringStream; + + if( status.m_isContributing ) + { + outputTableData( rankOutput, tableLayout, dataCellsLayout ); + } + + // all other ranks than rank 0 render their output in a string and comunicate its size + stdVector< integer > ranksStrsSizes{ ranksCount, 0 }; + string const rankStr = !status.m_isMasterRank && status.m_isContributing ? localStringStream.str() : ""; + integer const rankStrSize = rankStr.size(); + + localStringStream.clear(); + MpiWrapper::allgather( &rankStrSize, 1, ranksStrsSizes.data(), 1 ); + + // we compute the memory layout of the ranks strings + stdVector< integer > ranksStrsDisps{ ranksCount, 0 }; + integer ranksStrsTotalSize = 0; + for( integer rankId = 1; rankId < ranksCount; ++rankId ) + { + ranksStrsDisps[rankId] = ranksStrsTotalSize; + ranksStrsTotalSize += ranksStrsSizes[rankId]; + } + + // finally, we can send all text data to rank 0, then we output it in the output stream. + string ranksStrs = string( ranksStrsTotalSize, '\0' ); + MpiWrapper::gatherv( &rankStr[0], rankStrSize, + &ranksStrs[0], ranksStrsSizes.data(), ranksStrsDisps.data(), + 0, MPI_COMM_GEOS ); + if( status.m_isMasterRank ) + { + for( integer rankId = 1; rankId < ranksCount; ++rankId ) + { + if( m_mpiLayout.m_separatorBetweenRanks ) + tableOutput << tableLayout.getIndentationStr() << m_verticalLine + << string( status.m_sepLine.size() - 2, m_horizontalLine ) + << m_verticalLine << '\n'; + + if( ranksStrsSizes[rankId] > 0 ) + { + tableOutput << string_view( &ranksStrs[ranksStrsDisps[rankId]], ranksStrsSizes[rankId] ); + } + } + } } } /* namespace geos */ diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index df4a6fdbbae..091112255e8 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -26,6 +26,11 @@ namespace geos { +struct TableMpiLayout +{ + bool m_separatorBetweenRanks = false; +}; + /** * @brief class to format data in a formatted text format, allowing contributions from multiple * MPI ranks. @@ -36,26 +41,18 @@ class TableTextMpiOutput : public TableTextFormatter using Base = TableTextFormatter; - enum class ParallelOutputMode - { - /// Each ranks output cannot be mixed with the content of other ranks. Each rank flushes after full output. - InsecableRanks, - /// The rows of every ranks are output randomly. Each rank flushes after each row formatting. - MixedRanksRows, - }; - /** * @brief Construct a default Table Formatter without layout specification (to only insert data in it, * without any column / title). Feature is not tested. */ - TableTextMpiOutput( ParallelOutputMode parallelOutputMode = ParallelOutputMode::MixedRanksRows ); + TableTextMpiOutput( TableMpiLayout mpiLayout = TableMpiLayout() ); /** * @brief Construct a new TableTextMpiOutput from a tableLayout * @param tableLayout Contain all tableColumnData names and optionnaly the table title */ TableTextMpiOutput( TableLayout const & tableLayout, - ParallelOutputMode parallelOutputMode = ParallelOutputMode::MixedRanksRows ); + TableMpiLayout mpiLayout = TableMpiLayout() ); /** * @brief Convert a data source to a table string. @@ -73,7 +70,19 @@ class TableTextMpiOutput : public TableTextFormatter // hiding toString() methods as they are not implemented with MPI support. using Base::toString; - ParallelOutputMode m_parallelOutputMode; + struct TableTextMpiOutputStatus + { + bool m_isMasterRank; + bool m_isContributing; + string m_sepLine; + }; + + TableMpiLayout m_mpiLayout; + + void outputTableDataToRank0( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + CellLayoutRows const & dataCellsLayout, + TableTextMpiOutputStatus const status ) const; /** * @brief Expend the columns width to accomodate with the content of all MPI ranks. @@ -81,7 +90,8 @@ class TableTextMpiOutput : public TableTextFormatter * @param columnsWidth The array to store the resulting columns width in. * @param tableGrid The grid of cells containing content. */ - void stretchColumnsByRanks( stdVector< size_t > & columnsWidth ) const; + void stretchColumnsByRanks( stdVector< size_t > & columnsWidth, + TableTextMpiOutputStatus const status ) const; }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 9c05ae1da0f..d99e718cb52 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -65,6 +65,7 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, { if( m_ranksSignaledElementsCount > 0 ) { + string const minValueStr = GEOS_FMT( "{:.{}f} [{}]", minValue, 3, units::getSymbol( unit ) ); GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", linesPrefix, m_ranksSignaledElementsCount, valueNaming, minValueStr ) ); @@ -80,12 +81,12 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, TableData data; integer const signaledCount = m_buffer.getSignaledElementsCount(); integer const collectedCount = m_buffer.getCollectedElementsCount(); + integer const omittedCount = signaledCount - collectedCount; + integer const tableColumnsCount = MpiWrapper::max( 1 + collectedCount + integer( omittedCount > 0 ) ); if( signaledCount > 0 ) { - integer const omittedCount = signaledCount - collectedCount; // adding a columns for row name, each collected value, and one last if a "..." have to be added - integer const columnsCount = MpiWrapper::max( 1 + collectedCount + integer( omittedCount > 0 ) ); auto & cells = data.getCellsData(); string const title = GEOS_FMT( "Rank {}, {} / {} {} values:", MpiWrapper::commRank(), @@ -96,17 +97,17 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, static constexpr integer globalIdLine = 2; static constexpr integer valueLine = 3; - data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); + data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); cells[titleLine].back() = { CellType::Header, title }; - data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); + data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); - data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); + data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); cells[globalIdLine].front() = { CellType::Value, "Global Id" }; for( int i = 0; i < collectedCount; ++i ) cells[globalIdLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_id ) }; - data.addRow( stdVector< TableData::CellData >( columnsCount, { CellType::MergeNext, "" } ) ); + data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); cells[valueLine].front() = { CellType::Value, string( units::getDescription( unit ) ) }; for( int i = 0; i < collectedCount; ++i ) cells[valueLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_value ) }; @@ -118,9 +119,9 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, } } - auto const outputStrat = TableTextMpiOutput::ParallelOutputMode::InsecableRanks; - TableTextMpiOutput const formatter = TableTextMpiOutput( layout, outputStrat ); + TableTextMpiOutput const formatter = TableTextMpiOutput( layout, TableMpiLayout{ true } ); formatter.toStream( std::cout, data ); + GEOS_LOG_RANK_0( '\n' ); } else { From 5ab8421400cf2143049706dc84eb022be131f910 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 4 Jun 2025 11:46:15 +0200 Subject: [PATCH 30/67] =?UTF-8?q?=E2=9C=A8=20adding=20ranks=20separator=20?= =?UTF-8?q?titles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../format/table/TableMpiComponents.cpp | 30 ++++++++++++------- .../format/table/TableMpiComponents.hpp | 1 + .../fluidFlow/SolutionCheckHelpers.cpp | 30 +++++++++---------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index 740532d3d1a..ceadadb7e79 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -60,11 +60,11 @@ void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, initalizeTableGrids( m_tableLayout, tableData, headerCellsLayout, dataCellsLayout, tableTotalWidth, columnWidthModifier ); + status.m_sepLine = string( tableTotalWidth, m_horizontalLine ); } if( status.m_isMasterRank ) { - status.m_sepLine = string( tableTotalWidth, m_horizontalLine ); outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, status.m_sepLine ); tableOutput.flush(); } @@ -81,14 +81,22 @@ void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, void TableTextMpiOutput::stretchColumnsByRanks( stdVector< size_t > & columnsWidth, TableTextMpiOutputStatus const status ) const { - size_t const rankColumnsCount = columnsWidth.size(); - size_t const maxRanksColumnsCount = MpiWrapper::max( rankColumnsCount ); + { // we ensure we have the correct amount of columns on all ranks (for correct MPI reduction operation) + size_t const rankColumnsCount = columnsWidth.size(); + size_t const maxRanksColumnsCount = MpiWrapper::max( rankColumnsCount ); - if( status.m_isContributing ) - GEOS_ASSERT_EQ( rankColumnsCount, maxRanksColumnsCount ); // TODO: contribute to the new table error system with this one + // TODO: contribute to the new table error system with this one + if( status.m_isContributing ) + GEOS_ASSERT_EQ( rankColumnsCount, maxRanksColumnsCount ); + + columnsWidth.resize( maxRanksColumnsCount, 0 ); + } - columnsWidth.resize( maxRanksColumnsCount, 0 ); + // the ranks that does not contribute must not interfere in the column width computing + if( !status.m_isContributing ) + std::fill( columnsWidth.begin(), columnsWidth.end(), 0 ); + // we keep the largest column widths so we have the same layout on all ranks MpiWrapper::allReduce( columnsWidth, columnsWidth, MpiWrapper::Reduction::Max ); } @@ -105,6 +113,11 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, if( status.m_isContributing ) { + if( m_mpiLayout.m_separatorBetweenRanks ) + { + string const rankSepLine = GEOS_FMT( "{:-^{}}", m_mpiLayout.m_rankTitle, status.m_sepLine.size() - 2 ); + rankOutput << tableLayout.getIndentationStr() << m_verticalLine << rankSepLine << m_verticalLine << '\n'; + } outputTableData( rankOutput, tableLayout, dataCellsLayout ); } @@ -134,11 +147,6 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, { for( integer rankId = 1; rankId < ranksCount; ++rankId ) { - if( m_mpiLayout.m_separatorBetweenRanks ) - tableOutput << tableLayout.getIndentationStr() << m_verticalLine - << string( status.m_sepLine.size() - 2, m_horizontalLine ) - << m_verticalLine << '\n'; - if( ranksStrsSizes[rankId] > 0 ) { tableOutput << string_view( &ranksStrs[ranksStrsDisps[rankId]], ranksStrsSizes[rankId] ); diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index 091112255e8..d04ca7e40c9 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -29,6 +29,7 @@ namespace geos struct TableMpiLayout { bool m_separatorBetweenRanks = false; + string m_rankTitle; }; /** diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index d99e718cb52..ce45f6ffdec 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -84,23 +84,18 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, integer const omittedCount = signaledCount - collectedCount; integer const tableColumnsCount = MpiWrapper::max( 1 + collectedCount + integer( omittedCount > 0 ) ); + TableMpiLayout mpiLayout; + mpiLayout.m_separatorBetweenRanks = true; + if( signaledCount > 0 ) { // adding a columns for row name, each collected value, and one last if a "..." have to be added auto & cells = data.getCellsData(); - string const title = GEOS_FMT( "Rank {}, {} / {} {} values:", - MpiWrapper::commRank(), - collectedCount, - signaledCount, - valueNaming ); - static constexpr integer titleLine = 0; - static constexpr integer globalIdLine = 2; - static constexpr integer valueLine = 3; + static constexpr integer globalIdLine = 0; + static constexpr integer valuesLine = 1; - data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); - cells[titleLine].back() = { CellType::Header, title }; - - data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); + mpiLayout.m_rankTitle = GEOS_FMT( "Rank {}, {} / {} values", + MpiWrapper::commRank(), collectedCount, signaledCount ); data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); cells[globalIdLine].front() = { CellType::Value, "Global Id" }; @@ -108,18 +103,21 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, cells[globalIdLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_id ) }; data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); - cells[valueLine].front() = { CellType::Value, string( units::getDescription( unit ) ) }; + cells[valuesLine].front() = { CellType::Value, string( units::getDescription( unit ) ) }; for( int i = 0; i < collectedCount; ++i ) - cells[valueLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_value ) }; + cells[valuesLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_value ) }; if( omittedCount > 0 ) { cells[globalIdLine].back() = { CellType::Value, "..." }; - cells[valueLine].back() = { CellType::Value, "..." }; + cells[valuesLine].back() = { CellType::Value, "..." }; } + + // ending blank cells + data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::Value, "" } ) ); } - TableTextMpiOutput const formatter = TableTextMpiOutput( layout, TableMpiLayout{ true } ); + TableTextMpiOutput const formatter = TableTextMpiOutput( layout, mpiLayout ); formatter.toStream( std::cout, data ); GEOS_LOG_RANK_0( '\n' ); } From 390e451f746fb6d3612b93955560d5f209f58031 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 6 Jun 2025 10:18:17 +0200 Subject: [PATCH 31/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Adding=20missing=20s?= =?UTF-8?q?ignatures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableLayout.cpp | 18 ++++++++++++++---- .../common/format/table/TableLayout.hpp | 14 ++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 674bca02c5a..29663dcb49d 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -24,31 +24,41 @@ namespace geos { -void TableLayout::addColumns( stdVector< string > const & columnNames ) +TableLayout & TableLayout::addColumns( stdVector< string > const & columnNames ) { for( auto const & columnName : columnNames ) { addColumn( columnName ); } + return *this; } -void TableLayout::addColumns( stdVector< TableLayout::Column > const & columns ) +TableLayout & TableLayout::addColumns( stdVector< TableLayout::Column > const & columns ) { for( auto const & column : columns ) { addColumn( column ); } + return *this; +} + +TableLayout & TableLayout::addColumns( TableLayoutArgs columns ) +{ + processArguments( columns ); + return *this; } -void TableLayout::addColumn( string_view columnName ) +TableLayout & TableLayout::addColumn( string_view columnName ) { TableLayout::Column column = TableLayout::Column().setName( columnName ); m_tableColumns.emplace_back( column ); + return *this; } -void TableLayout::addColumn( TableLayout::Column const & column ) +TableLayout & TableLayout::addColumn( TableLayout::Column const & column ) { m_tableColumns.emplace_back( column ); + return *this; } TableLayout & TableLayout::setTitle( string_view title ) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 889d986e129..d9ded936d04 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -702,25 +702,31 @@ class TableLayout * @brief Create and add columns to the columns vector given a string vector * @param columnNames The columns name */ - void addColumns( stdVector< TableLayout::Column > const & columnNames ); + TableLayout & addColumns( stdVector< Column > const & columnNames ); /** * @brief Create and add columns to the columns vector given a string vector * @param columns The columns list */ - void addColumns( stdVector< string > const & columns ); + TableLayout & addColumns( stdVector< string > const & columns ); + + /** + * @brief Create and add columns to the columns vector given a string and/or columns + * @param columns brace enclosed parameters, consisting of column names or Column instances + */ + TableLayout & addColumns( TableLayoutArgs columns ); /** * @brief Create and add a column to the columns vector given a string * @param columnName The column name */ - void addColumn( string_view columnName ); + TableLayout & addColumn( string_view columnName ); /** * @brief Create and add a column to the columns vector given a Column * @param column Vector containing addition information on the column */ - void addColumn( TableLayout::Column const & column ); + TableLayout & addColumn( Column const & column ); protected: From 72e8ecdf301da46d80354a3e045289e8a5e9917d Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 6 Jun 2025 10:22:27 +0200 Subject: [PATCH 32/67] =?UTF-8?q?=F0=9F=92=84=20transposing=20table=20layo?= =?UTF-8?q?ut=20for=20clarity=20(user=20review)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SolutionCheckHelpers.cpp | 26 +++++++------------ .../fluidFlow/SolutionCheckHelpers.hpp | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index ce45f6ffdec..a5bfea047f9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -65,7 +65,6 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, { if( m_ranksSignaledElementsCount > 0 ) { - string const minValueStr = GEOS_FMT( "{:.{}f} [{}]", minValue, 3, units::getSymbol( unit ) ); GEOS_LOG_RANK_0( GEOS_FMT( "{}{} {} values encountered. Minimum value: {}.", linesPrefix, m_ranksSignaledElementsCount, valueNaming, minValueStr ) ); @@ -74,9 +73,9 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, { TableLayout const layout = TableLayout(). setTitle( GEOS_FMT( "Summary of {} elements", valueNaming ) ). + addColumns( { "Global Id", units::getDescription( unit ) } ). enableLineBreak( false ). setIndentation( linesPrefix.size() ). - setMargin( TableLayout::MarginValue::small ). setDefaultHeaderAlignment( TableLayout::Alignment::left ); TableData data; integer const signaledCount = m_buffer.getSignaledElementsCount(); @@ -97,24 +96,19 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, mpiLayout.m_rankTitle = GEOS_FMT( "Rank {}, {} / {} values", MpiWrapper::commRank(), collectedCount, signaledCount ); - data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); - cells[globalIdLine].front() = { CellType::Value, "Global Id" }; - for( int i = 0; i < collectedCount; ++i ) - cells[globalIdLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_id ) }; - - data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::MergeNext, "" } ) ); - cells[valuesLine].front() = { CellType::Value, string( units::getDescription( unit ) ) }; - for( int i = 0; i < collectedCount; ++i ) - cells[valuesLine][i+1] = { CellType::Value, std::to_string( m_buffer[i].m_value ) }; + for( ElementReport const & report : m_buffer ) + { + data.addRow( report.m_id, report.m_value ); + } if( omittedCount > 0 ) { - cells[globalIdLine].back() = { CellType::Value, "..." }; - cells[valuesLine].back() = { CellType::Value, "..." }; + data.addRow( "...", "..." ); + } + else + { + data.addRow( "", "" ); } - - // ending blank cells - data.addRow( stdVector< TableData::CellData >( tableColumnsCount, { CellType::Value, "" } ) ); } TableTextMpiOutput const formatter = TableTextMpiOutput( layout, mpiLayout ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index 434285dde35..ef33aad6911 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -82,7 +82,7 @@ class ElementsReporterBuffer ElementCount getCollectedElementsCount() const { return LvArray::math::min( getSignaledElementsCount(), m_elementsBuffer.size() ); } - ElementReport operator[]( ElementCount id ) const + ElementReport const & operator[]( ElementCount id ) const { return m_elementsBuffer[id]; } auto begin() const From 04754361d56ad26a96486c5bb896b33c3a3b8a54 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 1 Jul 2025 15:45:59 +0200 Subject: [PATCH 33/67] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20unused=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index a5bfea047f9..800476b222d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -81,18 +81,12 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, integer const signaledCount = m_buffer.getSignaledElementsCount(); integer const collectedCount = m_buffer.getCollectedElementsCount(); integer const omittedCount = signaledCount - collectedCount; - integer const tableColumnsCount = MpiWrapper::max( 1 + collectedCount + integer( omittedCount > 0 ) ); TableMpiLayout mpiLayout; mpiLayout.m_separatorBetweenRanks = true; if( signaledCount > 0 ) { - // adding a columns for row name, each collected value, and one last if a "..." have to be added - auto & cells = data.getCellsData(); - static constexpr integer globalIdLine = 0; - static constexpr integer valuesLine = 1; - mpiLayout.m_rankTitle = GEOS_FMT( "Rank {}, {} / {} values", MpiWrapper::commRank(), collectedCount, signaledCount ); @@ -101,6 +95,7 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, data.addRow( report.m_id, report.m_value ); } + // adding one last line for signaling partial data & readability if( omittedCount > 0 ) { data.addRow( "...", "..." ); From b086a4f90e2e275edc7fccae615da50d2e98cf02 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 1 Jul 2025 15:46:33 +0200 Subject: [PATCH 34/67] =?UTF-8?q?=F0=9F=90=9B=20fixing=20scarce=20crash=20?= =?UTF-8?q?when=20mpi-tables=20are=20constructed=20from=20more=20than=202?= =?UTF-8?q?=20ranks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableMpiComponents.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index ceadadb7e79..e28c4c16dab 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -122,15 +122,13 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, } // all other ranks than rank 0 render their output in a string and comunicate its size - stdVector< integer > ranksStrsSizes{ ranksCount, 0 }; + auto ranksStrsSizes = std::vector( ranksCount, 0 ); string const rankStr = !status.m_isMasterRank && status.m_isContributing ? localStringStream.str() : ""; integer const rankStrSize = rankStr.size(); - - localStringStream.clear(); MpiWrapper::allgather( &rankStrSize, 1, ranksStrsSizes.data(), 1 ); // we compute the memory layout of the ranks strings - stdVector< integer > ranksStrsDisps{ ranksCount, 0 }; + auto ranksStrsDisps = std::vector( ranksCount, 0 ); integer ranksStrsTotalSize = 0; for( integer rankId = 1; rankId < ranksCount; ++rankId ) { From 112be17fb935f425d1461fbd1ceb99e4ab292e10 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 1 Jul 2025 17:54:09 +0200 Subject: [PATCH 35/67] =?UTF-8?q?=F0=9F=93=9D=20updating=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableMpiComponents.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index d04ca7e40c9..277082dbff0 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -58,10 +58,10 @@ class TableTextMpiOutput : public TableTextFormatter /** * @brief Convert a data source to a table string. * @param tableData The data source to convert. - * @param outputStream The same target output stream for all ranks, to output the table string - * representation of the TableData. The output is partial, each rank - * contributing to common output stream with their local data. It may be the - * log or a file stream. + * @param outputStream The target output stream for rank 0, to output the table strin grepresentation + * of the TableData. Each rank contributing to the common rank 0 output stream + * with their local data. It may be the log or a file stream. + * @note This method must be called by all MPI ranks. */ template< typename DATASOURCE > void toStream( std::ostream & outputStream, DATASOURCE const & tableData ) const; From e5ae68ec78694ae737a23292ed8581451b149f4d Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 1 Jul 2025 17:54:36 +0200 Subject: [PATCH 36/67] =?UTF-8?q?=E2=9C=85=20adding=20mpi=20tables=20unit?= =?UTF-8?q?=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../format/table/unitTests/CMakeLists.txt | 20 ++++ .../format/table/unitTests/testMpiTable.cpp | 111 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/coreComponents/common/format/table/unitTests/testMpiTable.cpp diff --git a/src/coreComponents/common/format/table/unitTests/CMakeLists.txt b/src/coreComponents/common/format/table/unitTests/CMakeLists.txt index f5a4a358e97..594f08577a7 100644 --- a/src/coreComponents/common/format/table/unitTests/CMakeLists.txt +++ b/src/coreComponents/common/format/table/unitTests/CMakeLists.txt @@ -2,6 +2,9 @@ set( gtest_geosx_tests testTable.cpp ) +set( gtest_geosx_mpi_tests + testMpiTable.cpp ) + set( dependencyList gtest common ${parallelDeps} ) # Add gtest C++ based tests @@ -16,3 +19,20 @@ foreach(test ${gtest_geosx_tests}) COMMAND ${test_name} ) endforeach() + +if( ENABLE_MPI ) + set( nranks 4 ) + + foreach( test ${gtest_geosx_mpi_tests} ) + get_filename_component( file_we ${test} NAME_WE ) + set( test_name ${file_we}_mpi ) + blt_add_executable( NAME ${test_name} + SOURCES ${test} + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON ${dependencyList} ) + + geos_add_test( NAME ${test_name} + COMMAND ${test_name} -x ${nranks} + NUM_MPI_TASKS ${nranks} ) + endforeach() +endif() diff --git a/src/coreComponents/common/format/table/unitTests/testMpiTable.cpp b/src/coreComponents/common/format/table/unitTests/testMpiTable.cpp new file mode 100644 index 00000000000..8ee868701db --- /dev/null +++ b/src/coreComponents/common/format/table/unitTests/testMpiTable.cpp @@ -0,0 +1,111 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 TotalEnergies + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +// Source includes +#include "common/format/table/TableMpiComponents.hpp" +#include "common/initializeEnvironment.hpp" +#include "common/MpiWrapper.hpp" +// TPL includes +#include +#include + +using namespace geos; + +class MpiTestScope +{ +public: + + MpiTestScope( int argc, char * argv[] ) + { + ::testing::InitGoogleTest( &argc, argv ); + geos::setupEnvironment( argc, argv ); + } + + ~MpiTestScope() + { + geos::cleanupEnvironment(); + } + +}; + +TEST( testMpiTables, testDifferentRankData ) +{ + stdVector< stdVector< std::pair< integer, real64 > > > const testValues = { + { {1, 0.502} }, + { {2, 0.624}, {3, 0.791} }, + {}, + { {4, 0.243}, {5, 0.804}, {6, 0.302} }, + }; + + int const rankId = MpiWrapper::commRank(); + int const nbRanks = MpiWrapper::commSize(); + if( nbRanks > 1 ) + { + ASSERT_EQ( nbRanks, 4 ); + + TableLayout const layout = TableLayout(). + setTitle( "Summary of negative pressure elements" ). + addColumns( { "Global Id", "pressure [Pa]" } ). + setDefaultHeaderAlignment( TableLayout::Alignment::left ); + TableData data; + auto const & rankTestData = testValues[rankId]; + + TableMpiLayout mpiLayout; + mpiLayout.m_separatorBetweenRanks = true; + + if( !rankTestData.empty() ) + { + mpiLayout.m_rankTitle = GEOS_FMT( "Rank {}, {} values", rankId, rankTestData.size() ); + for( auto const & [id, value] : rankTestData ) + { + data.addRow( id, value ); + } + } + + TableTextMpiOutput const formatter = TableTextMpiOutput( layout, mpiLayout ); + std::ostringstream oss; + formatter.toStream( oss, data ); + if( rankId == 0 ) + { + EXPECT_STREQ( "\n" + "-------------------------------------------\n" + "| Summary of negative pressure elements |\n" + "|-----------------------------------------|\n" + "| Global Id | pressure [Pa] |\n" + "|------------------|----------------------|\n" + "|------------Rank 0, 1 values-------------|\n" + "| 1 | 0.502 |\n" + "|------------Rank 1, 2 values-------------|\n" + "| 2 | 0.624 |\n" + "| 3 | 0.791 |\n" + "|------------Rank 3, 3 values-------------|\n" + "| 4 | 0.243 |\n" + "| 5 | 0.804 |\n" + "| 6 | 0.302 |\n" + "-------------------------------------------\n", + oss.str().data() ); + } + } +} + +int main( int argc, char * * argv ) +{ + int r; + { + MpiTestScope testScope{ argc, argv }; + r = RUN_ALL_TESTS(); + } + return r; +} From 411636da54c1ab1acde6cd359b9e7bea006df4d1 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 2 Jul 2025 11:48:22 +0200 Subject: [PATCH 37/67] =?UTF-8?q?=F0=9F=93=9D=20Adding=20las=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableFormatter.hpp | 18 ++++++++---------- .../common/format/table/TableLayout.hpp | 10 ++++++++++ .../common/format/table/TableMpiComponents.hpp | 8 ++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 11baa4deeeb..a3c8b924833 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -185,11 +185,10 @@ class TableTextFormatter : public TableFormatter ColumnWidthModifier columnWidthModifier ) const; /** - * @brief Outputs the formatted table to the provided output stream. - * @param tableLayout The layout of the table + * @brief Outputs the top part of the formatted table to the provided output stream. * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. - * @param headerCellsLayout The layout of the header rows - * @param dataCellsLayout The layout of the data rows + * @param tableLayout The layout of the table + * @param headerCellsLayout The header rows in a grid layout * @param separatorLine A string that will be used as the table separator line */ void outputTableHeader( std::ostream & tableOutput, @@ -198,22 +197,21 @@ class TableTextFormatter : public TableFormatter string_view separatorLine ) const; /** - * @brief Outputs the formatted table to the provided output stream. + * @brief Outputs the data part of the formatted table to the provided output stream. * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. * @param tableLayout The layout of the table - * @param dataCellsLayout The layout of the data rows + * @param dataCellsLayout The data rows in a grid layout */ void outputTableData( std::ostream & tableOutput, PreparedTableLayout const & tableLayout, CellLayoutRows const & dataCellsLayout ) const; /** - * @brief Outputs the formatted table to the provided output stream. - * @param tableLayout The layout of the table + * @brief Outputs the bottom part of the formatted table to the provided output stream. * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. - * @param headerCellsLayout The layout of the header rows - * @param dataCellsLayout The layout of the data rows + * @param tableLayout The layout of the table * @param separatorLine A string that will be used as the table separator line + * @param hasData Indicates whether there is data in the table TableData. */ void outputTableBottom( std::ostream & tableOutput, PreparedTableLayout const & tableLayout, diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index d9ded936d04..92719acddec 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -643,16 +643,21 @@ class TableLayout /** * @brief Set the indentation of the whole table. * @param spacesCount The number of indentation spaces. + * @return the TableLayout instance, for builder pattern */ TableLayout & setIndentation( size_t spacesCount ); /** * @brief Sets the default value for columns header cells alignement. Used with column-free layout. + * @param alignment The desired alignment + * @return the TableLayout instance, for builder pattern */ TableLayout & setDefaultHeaderAlignment( Alignment alignment ); /** * @brief Sets the default value for data cells alignement. Used with column-free layout. + * @param alignment The desired alignment + * @return the TableLayout instance, for builder pattern */ TableLayout & setDefaultValueAlignment( Alignment alignment ); @@ -701,30 +706,35 @@ class TableLayout /** * @brief Create and add columns to the columns vector given a string vector * @param columnNames The columns name + * @return the TableLayout instance, for builder pattern */ TableLayout & addColumns( stdVector< Column > const & columnNames ); /** * @brief Create and add columns to the columns vector given a string vector * @param columns The columns list + * @return the TableLayout instance, for builder pattern */ TableLayout & addColumns( stdVector< string > const & columns ); /** * @brief Create and add columns to the columns vector given a string and/or columns * @param columns brace enclosed parameters, consisting of column names or Column instances + * @return the TableLayout instance, for builder pattern */ TableLayout & addColumns( TableLayoutArgs columns ); /** * @brief Create and add a column to the columns vector given a string * @param columnName The column name + * @return the TableLayout instance, for builder pattern */ TableLayout & addColumn( string_view columnName ); /** * @brief Create and add a column to the columns vector given a Column * @param column Vector containing addition information on the column + * @return the TableLayout instance, for builder pattern */ TableLayout & addColumn( Column const & column ); diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index 277082dbff0..550a535faac 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -26,9 +26,15 @@ namespace geos { +/** + * @struct TableMpiLayout + * @brief Layout information specific to MPI distributed tables, completing those in TableLayout. + */ struct TableMpiLayout { + /// Enable a separating line between ranks in the table output. bool m_separatorBetweenRanks = false; + /// Title for each rank's section visible in the separating line. string m_rankTitle; }; @@ -45,12 +51,14 @@ class TableTextMpiOutput : public TableTextFormatter /** * @brief Construct a default Table Formatter without layout specification (to only insert data in it, * without any column / title). Feature is not tested. + * @param mpiLayout MPI-specific layout information (default is having contiguous ranks data). */ TableTextMpiOutput( TableMpiLayout mpiLayout = TableMpiLayout() ); /** * @brief Construct a new TableTextMpiOutput from a tableLayout * @param tableLayout Contain all tableColumnData names and optionnaly the table title + * @param mpiLayout MPI-specific layout information (default is having contiguous ranks data). */ TableTextMpiOutput( TableLayout const & tableLayout, TableMpiLayout mpiLayout = TableMpiLayout() ); From 8eb526bf24fc2c9908cf35281fb70cd859f9c9a7 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 2 Jul 2025 11:51:48 +0200 Subject: [PATCH 38/67] =?UTF-8?q?=F0=9F=8E=A8=20uncrustify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableFormatter.hpp | 2 +- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 8 ++++---- .../physicsSolvers/fluidFlow/SinglePhaseBase.cpp | 4 ++-- .../fluidFlow/wells/CompositionalMultiphaseWell.cpp | 8 ++++---- .../physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index a3c8b924833..608160518f6 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -166,7 +166,7 @@ class TableTextFormatter : public TableFormatter static constexpr char m_horizontalLine = '-'; /// A functor which allow to customize the columns width after their computation. - using ColumnWidthModifier = std::function< void( stdVector< size_t > & ) >; + using ColumnWidthModifier = std::function< void ( stdVector< size_t > & ) >; /** * @brief Initializes the table layout with the given table data and prepares necessary layouts for headers and data cells. diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index bfc62957ebc..9734848c0f0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -848,9 +848,9 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), - isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), - isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -930,11 +930,11 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), - "negative pressure", minPres, units::Unit::Pressure ); + "negative pressure", minPres, units::Unit::Pressure ); units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; rankNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), - "negative component density", minDens, massUnit ); + "negative component density", minDens, massUnit ); if( numNegTotalDens > 0 ) { GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index d03e7edaaed..6caf29a7f92 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -1298,7 +1298,7 @@ bool SinglePhaseBase::checkSystemSolution( DomainPartition & domain, string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), - isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; real64 minPressure = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, @@ -1329,7 +1329,7 @@ bool SinglePhaseBase::checkSystemSolution( DomainPartition & domain, } ); rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), - "negative pressure", minPressure, units::Unit::Pressure ); + "negative pressure", minPressure, units::Unit::Pressure ); return (m_allowNegativePressure || rankNegPressureIds.getSignaledElementsCount() == 0) ? 1 : 0; } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index d65f2e97c58..afa7d025349 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1551,9 +1551,9 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::WellValidityDetails >( this->getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::WellValidityDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -1636,11 +1636,11 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), - "negative pressure", minPres, units::Unit::Pressure ); + "negative pressure", minPres, units::Unit::Pressure ); units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; rankNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), - "negative component density", minDens, massUnit ); + "negative component density", minDens, massUnit ); if( numNegTotalDens > 0 ) { GEOS_LOG_LEVEL_RANK_0( logInfo::WellValidity, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index f10585c08b3..143bec08c21 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -882,7 +882,7 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, string const wellDofKey = dofManager.getKey( wellElementDofName() ); ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; real64 minNegPres = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, @@ -924,7 +924,7 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, ElementsReporterOutput const rankNegPressureIdsOutput = rankNegPressureIds.createOutput(); rankNegPressureIdsOutput.outputTooLowValues( GEOS_FMT( " {}: ", getName() ), - "negative pressure", minNegPres, units::Unit::Pressure ); + "negative pressure", minNegPres, units::Unit::Pressure ); return (m_allowNegativePressure || rankNegPressureIdsOutput.getRanksSignaledIdsCount() == 0) ? 1 : 0; } From 5af2601ebf61f44c61ce5c6146e85e9ca2c14641 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 2 Jul 2025 12:05:25 +0200 Subject: [PATCH 39/67] =?UTF-8?q?=F0=9F=93=9D=20missing=20last=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableMpiComponents.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index 550a535faac..e8d800c1b5a 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -45,7 +45,7 @@ struct TableMpiLayout class TableTextMpiOutput : public TableTextFormatter { public: - + /// base class using Base = TableTextFormatter; /** From 61c4199041e44e81be0198b5d5e84e1db4478b4a Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 4 Jul 2025 15:38:45 +0200 Subject: [PATCH 40/67] =?UTF-8?q?=F0=9F=93=9D=20doc=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableMpiComponents.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index e8d800c1b5a..d9da5a38c40 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -66,7 +66,7 @@ class TableTextMpiOutput : public TableTextFormatter /** * @brief Convert a data source to a table string. * @param tableData The data source to convert. - * @param outputStream The target output stream for rank 0, to output the table strin grepresentation + * @param outputStream The target output stream for rank 0, to output the table string representation * of the TableData. Each rank contributing to the common rank 0 output stream * with their local data. It may be the log or a file stream. * @note This method must be called by all MPI ranks. From ef29d771be9d734f01483d74530f682165c55fc6 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 4 Jul 2025 15:55:31 +0200 Subject: [PATCH 41/67] ranksStrsDisps -> ranksStrsOffsets --- .../common/format/table/TableMpiComponents.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index e28c4c16dab..a3a08bcc944 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -122,24 +122,24 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, } // all other ranks than rank 0 render their output in a string and comunicate its size - auto ranksStrsSizes = std::vector( ranksCount, 0 ); + std::vector< integer > ranksStrsSizes = std::vector( ranksCount, 0 ); string const rankStr = !status.m_isMasterRank && status.m_isContributing ? localStringStream.str() : ""; integer const rankStrSize = rankStr.size(); MpiWrapper::allgather( &rankStrSize, 1, ranksStrsSizes.data(), 1 ); // we compute the memory layout of the ranks strings - auto ranksStrsDisps = std::vector( ranksCount, 0 ); + std::vector< integer > ranksStrsOffsets = std::vector( ranksCount, 0 ); integer ranksStrsTotalSize = 0; for( integer rankId = 1; rankId < ranksCount; ++rankId ) { - ranksStrsDisps[rankId] = ranksStrsTotalSize; + ranksStrsOffsets[rankId] = ranksStrsTotalSize; ranksStrsTotalSize += ranksStrsSizes[rankId]; } // finally, we can send all text data to rank 0, then we output it in the output stream. string ranksStrs = string( ranksStrsTotalSize, '\0' ); MpiWrapper::gatherv( &rankStr[0], rankStrSize, - &ranksStrs[0], ranksStrsSizes.data(), ranksStrsDisps.data(), + &ranksStrs[0], ranksStrsSizes.data(), ranksStrsOffsets.data(), 0, MPI_COMM_GEOS ); if( status.m_isMasterRank ) { @@ -147,7 +147,7 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, { if( ranksStrsSizes[rankId] > 0 ) { - tableOutput << string_view( &ranksStrs[ranksStrsDisps[rankId]], ranksStrsSizes[rankId] ); + tableOutput << string_view( &ranksStrs[ranksStrsOffsets[rankId]], ranksStrsSizes[rankId] ); } } } From 8d50b4cb020fd9bd16c75289abbe22582df7e41e Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 16 Jul 2025 16:11:18 +0200 Subject: [PATCH 42/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20set=20constant=20par?= =?UTF-8?q?ams=20const?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableMpiComponents.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index d9da5a38c40..72491b868ac 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -81,8 +81,8 @@ class TableTextMpiOutput : public TableTextFormatter struct TableTextMpiOutputStatus { - bool m_isMasterRank; - bool m_isContributing; + bool const m_isMasterRank; + bool const m_isContributing; string m_sepLine; }; From 92e9abbdb5be474697c206a8c7e524b20a15b60e Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 16 Jul 2025 17:04:55 +0200 Subject: [PATCH 43/67] =?UTF-8?q?=F0=9F=A7=AA=20adding=20a=20(failing)=20t?= =?UTF-8?q?est=20to=20highlight=20a=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../format/table/unitTests/testMpiTable.cpp | 128 ++++++++++++------ 1 file changed, 83 insertions(+), 45 deletions(-) diff --git a/src/coreComponents/common/format/table/unitTests/testMpiTable.cpp b/src/coreComponents/common/format/table/unitTests/testMpiTable.cpp index 8ee868701db..7b01cf49515 100644 --- a/src/coreComponents/common/format/table/unitTests/testMpiTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testMpiTable.cpp @@ -42,60 +42,98 @@ class MpiTestScope TEST( testMpiTables, testDifferentRankData ) { - stdVector< stdVector< std::pair< integer, real64 > > > const testValues = { - { {1, 0.502} }, - { {2, 0.624}, {3, 0.791} }, - {}, - { {4, 0.243}, {5, 0.804}, {6, 0.302} }, + struct TestCase + { + stdVector< stdVector< std::pair< integer, real64 > > > m_ranksValues; + string m_expectedResult; }; - int const rankId = MpiWrapper::commRank(); - int const nbRanks = MpiWrapper::commSize(); - if( nbRanks > 1 ) + stdVector< TestCase > const testCases = + { + { + { // m_ranksValues: in this test, rank 2 has no value + { {1, 0.502} }, + { {2, 0.624}, {3, 0.791} }, + {}, + { {4, 0.243}, {5, 0.804}, {6, 0.302} }, + }, + "\n" // m_expectedResult + "-------------------------------------------\n" + "| Summary of negative pressure elements |\n" + "|-----------------------------------------|\n" + "| Global Id | pressure [Pa] |\n" + "|------------------|----------------------|\n" + "|------------Rank 0, 1 values-------------|\n" + "| 1 | 0.502 |\n" + "|------------Rank 1, 2 values-------------|\n" + "| 2 | 0.624 |\n" + "| 3 | 0.791 |\n" + "|------------Rank 3, 3 values-------------|\n" + "| 4 | 0.243 |\n" + "| 5 | 0.804 |\n" + "| 6 | 0.302 |\n" + "-------------------------------------------\n" + }, + { // m_ranksValues: in this test, rank 0 has no value + { + {}, + { {4, 0.243}, {5, 0.804}, {6, 0.302} }, + { {1, 0.502} }, + { {2, 0.624}, {3, 0.791} }, + }, + "\n" // m_expectedResult + "-------------------------------------------\n" + "| Summary of negative pressure elements |\n" + "|-----------------------------------------|\n" + "| Global Id | pressure [Pa] |\n" + "|------------------|----------------------|\n" + "|------------Rank 1, 3 values-------------|\n" + "| 4 | 0.243 |\n" + "| 5 | 0.804 |\n" + "| 6 | 0.302 |\n" + "|------------Rank 2, 1 values-------------|\n" + "| 1 | 0.502 |\n" + "|------------Rank 3, 2 values-------------|\n" + "| 2 | 0.624 |\n" + "| 3 | 0.791 |\n" + "-------------------------------------------\n" + }, + }; + for( TestCase const & testCase: testCases ) { - ASSERT_EQ( nbRanks, 4 ); + int const rankId = MpiWrapper::commRank(); + int const nbRanks = MpiWrapper::commSize(); + if( nbRanks > 1 ) + { + ASSERT_EQ( nbRanks, 4 ); - TableLayout const layout = TableLayout(). - setTitle( "Summary of negative pressure elements" ). - addColumns( { "Global Id", "pressure [Pa]" } ). - setDefaultHeaderAlignment( TableLayout::Alignment::left ); - TableData data; - auto const & rankTestData = testValues[rankId]; + TableLayout const layout = TableLayout(). + setTitle( "Summary of negative pressure elements" ). + addColumns( { "Global Id", "pressure [Pa]" } ). + setDefaultHeaderAlignment( TableLayout::Alignment::left ); + TableData data; + auto const & rankTestData = testCase.m_ranksValues[rankId]; - TableMpiLayout mpiLayout; - mpiLayout.m_separatorBetweenRanks = true; + TableMpiLayout mpiLayout; + mpiLayout.m_separatorBetweenRanks = true; - if( !rankTestData.empty() ) - { - mpiLayout.m_rankTitle = GEOS_FMT( "Rank {}, {} values", rankId, rankTestData.size() ); - for( auto const & [id, value] : rankTestData ) + if( !rankTestData.empty() ) { - data.addRow( id, value ); + mpiLayout.m_rankTitle = GEOS_FMT( "Rank {}, {} values", rankId, rankTestData.size() ); + for( auto const & [id, value] : rankTestData ) + { + data.addRow( id, value ); + } } - } - TableTextMpiOutput const formatter = TableTextMpiOutput( layout, mpiLayout ); - std::ostringstream oss; - formatter.toStream( oss, data ); - if( rankId == 0 ) - { - EXPECT_STREQ( "\n" - "-------------------------------------------\n" - "| Summary of negative pressure elements |\n" - "|-----------------------------------------|\n" - "| Global Id | pressure [Pa] |\n" - "|------------------|----------------------|\n" - "|------------Rank 0, 1 values-------------|\n" - "| 1 | 0.502 |\n" - "|------------Rank 1, 2 values-------------|\n" - "| 2 | 0.624 |\n" - "| 3 | 0.791 |\n" - "|------------Rank 3, 3 values-------------|\n" - "| 4 | 0.243 |\n" - "| 5 | 0.804 |\n" - "| 6 | 0.302 |\n" - "-------------------------------------------\n", - oss.str().data() ); + TableTextMpiOutput const formatter = TableTextMpiOutput( layout, mpiLayout ); + std::ostringstream oss; + formatter.toStream( oss, data ); + if( rankId == 0 ) + { + EXPECT_STREQ( testCase.m_expectedResult.data(), + oss.str().data() ); + } } } } From 4b46f19f10e6e87825174dd44d1050c2240d7f37 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 16 Jul 2025 17:21:18 +0200 Subject: [PATCH 44/67] =?UTF-8?q?=F0=9F=90=9B=20solve=20a=20bug=20where=20?= =?UTF-8?q?the=20last=20line=20of=20the=20table=20was=20cut=20(when=20the?= =?UTF-8?q?=20r0=20had=20no=20content)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/format/table/TableMpiComponents.cpp | 11 +++++++---- .../common/format/table/TableMpiComponents.hpp | 15 ++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index a3a08bcc944..413f8dbc698 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -40,11 +40,13 @@ template<> void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, TableData const & tableData ) const { - TableTextMpiOutputStatus status { + TableTextMpiOutput::Status status { // m_isMasterRank (only the master rank does the output of the header && bottom of the table) MpiWrapper::commRank() == 0, // m_isContributing (some ranks does not have any output to produce) !tableData.getCellsData().empty(), + // m_hasContent + false, // m_sepLine "" }; @@ -73,13 +75,13 @@ void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, if( status.m_isMasterRank ) { - outputTableBottom( tableOutput, m_tableLayout, status.m_sepLine, !dataCellsLayout.empty() ); + outputTableBottom( tableOutput, m_tableLayout, status.m_sepLine, status.m_hasContent ); tableOutput.flush(); } } void TableTextMpiOutput::stretchColumnsByRanks( stdVector< size_t > & columnsWidth, - TableTextMpiOutputStatus const status ) const + TableTextMpiOutput::Status const & status ) const { { // we ensure we have the correct amount of columns on all ranks (for correct MPI reduction operation) size_t const rankColumnsCount = columnsWidth.size(); @@ -103,7 +105,7 @@ void TableTextMpiOutput::stretchColumnsByRanks( stdVector< size_t > & columnsWid void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, PreparedTableLayout const & tableLayout, CellLayoutRows const & dataCellsLayout, - TableTextMpiOutputStatus const status ) const + TableTextMpiOutput::Status & status ) const { integer const ranksCount = MpiWrapper::commSize(); @@ -147,6 +149,7 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, { if( ranksStrsSizes[rankId] > 0 ) { + status.m_hasContent = true; tableOutput << string_view( &ranksStrs[ranksStrsOffsets[rankId]], ranksStrsSizes[rankId] ); } } diff --git a/src/coreComponents/common/format/table/TableMpiComponents.hpp b/src/coreComponents/common/format/table/TableMpiComponents.hpp index 72491b868ac..aeb37caa0ce 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.hpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.hpp @@ -79,20 +79,16 @@ class TableTextMpiOutput : public TableTextFormatter // hiding toString() methods as they are not implemented with MPI support. using Base::toString; - struct TableTextMpiOutputStatus + struct Status { bool const m_isMasterRank; bool const m_isContributing; + bool m_hasContent; string m_sepLine; }; TableMpiLayout m_mpiLayout; - void outputTableDataToRank0( std::ostream & tableOutput, - PreparedTableLayout const & tableLayout, - CellLayoutRows const & dataCellsLayout, - TableTextMpiOutputStatus const status ) const; - /** * @brief Expend the columns width to accomodate with the content of all MPI ranks. * As it is based on MPI communications, every ranks must call this method. @@ -100,7 +96,12 @@ class TableTextMpiOutput : public TableTextFormatter * @param tableGrid The grid of cells containing content. */ void stretchColumnsByRanks( stdVector< size_t > & columnsWidth, - TableTextMpiOutputStatus const status ) const; + Status const & status ) const; + + void outputTableDataToRank0( std::ostream & tableOutput, + PreparedTableLayout const & tableLayout, + CellLayoutRows const & dataCellsLayout, + Status & status ) const; }; From aeb8ea02052759bcd5fee2a6a0e7088e5f6201f9 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 16 Jul 2025 17:21:42 +0200 Subject: [PATCH 45/67] =?UTF-8?q?=F0=9F=93=A6=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/schema/schema.xsd.other | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index 90bd4aacb07..77bff2b29ad 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -486,7 +486,7 @@ - + @@ -1343,7 +1343,7 @@ - + @@ -1886,8 +1886,6 @@ - - @@ -1938,8 +1936,6 @@ - - @@ -1990,8 +1986,6 @@ - - @@ -2042,8 +2036,6 @@ - - From 937c446b42e21751566dc2c4076982cbc433c55f Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Thu, 17 Jul 2025 16:12:09 +0200 Subject: [PATCH 46/67] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20removed=20dead=20cod?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableMpiComponents.cpp | 1 - .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 4 ---- .../fluidFlow/kernels/compositional/SolutionCheckKernel.hpp | 4 +--- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index 413f8dbc698..c5669a12888 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -20,7 +20,6 @@ #include "TableMpiComponents.hpp" #include "common/MpiWrapper.hpp" -#include "common/format/StringUtilities.hpp" // todo delete namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 800476b222d..5143a030203 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -100,10 +100,6 @@ void ElementsReporterOutput::outputTooLowValues( string_view linesPrefix, { data.addRow( "...", "..." ); } - else - { - data.addRow( "", "" ); - } } TableTextMpiOutput const formatter = TableTextMpiOutput( layout, mpiLayout ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index a510181508f..1985f8a70ed 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -48,8 +48,6 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer using Base::m_pressure; using Base::m_compDens; - static constexpr int maxWrongValueIds = 16; - /** * @brief Create a new kernel instance * @param[in] allowCompDensChopping flag to allow the component density chopping @@ -343,7 +341,7 @@ class SolutionCheckKernelFactory ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, ElementsReporterCollector const & negPressureIds, - ElementsReporterCollector const & negDensityIds ) // TODO : ajouter bool reportWrongValues + ElementsReporterCollector const & negDensityIds ) { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset, From 409f4619c648d9bd27d38c3ad10671e3c3574b34 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 18 Jul 2025 14:24:51 +0200 Subject: [PATCH 47/67] =?UTF-8?q?=F0=9F=93=9D=20documentation=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SolutionCheckHelpers.hpp | 83 +++++++++++++++++-- .../kernels/SolutionCheckKernelsHelpers.hpp | 38 ++++++--- 2 files changed, 99 insertions(+), 22 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index ef33aad6911..3e37fe6c861 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -26,20 +26,41 @@ namespace geos { +/** + * @brief A class to report elements collected by the solver. + */ class ElementsReporterOutput { public: + /// Type alias for elements count (e.g., localIndex, globalIndex). using ElementCount = ElementsReporterCollector::ElementCount; + /** + * @brief Construct a preallocated buffer for collecting element ids in kernels. + * @param buffer The buffer that will be utilized for counting & collecting elements IDs during kernel execution. + */ ElementsReporterOutput( ElementsReporterBuffer const & buffer ); - ElementCount getRanksSignaledIdsCount() const - { return m_ranksSignaledElementsCount; } + /** + * @return The number of ranks that have signaled an id. + */ + ElementCount getRanksSignaledIdsCount() const; - ElementCount getRanksCollectedIdsCount() const - { return m_ranksCollectedElementsCount; } + /** + * @return The total count of collected elements across all ranks for signaling ids. + */ + ElementCount getRanksCollectedIdsCount() const; + /** + * @brief Report elements with values below a specified threshold in the log: + * Outputs lines indicating which variables have collected element ids whose corresponding + * solution components are too low, potentially signaling underflow or numerical instability. + * @param linesPrefix Prefix for the line of text to be printed + * @param valueNaming The name used when referring to variables within this context (e.g., "pressure", "density"). + * @param minValue Minimum acceptable solution component values. Values below this threshold are reported. + * @param valueUnit Unit in which `minValue` is expressed. + */ void outputTooLowValues( string_view linesPrefix, string_view valueNaming, real64 minValue, @@ -47,18 +68,26 @@ class ElementsReporterOutput private: + /// Preallocated buffer for collecting ids. ElementsReporterBuffer const & m_buffer; + /// Count of signaled elements per rank. ElementCount m_ranksSignaledElementsCount; + /// Total collected signaling id count across ranks. ElementCount m_ranksCollectedElementsCount; }; +/** + * @brief A buffer to count and store element ids during kernel execution. + * This facilitates the reporting mechanism by allowing a preallocated space for storing & counting elements. + */ class ElementsReporterBuffer { public: + /// Type alias for elements count (e.g., localIndex, globalIndex). using ElementCount = ElementsReporterCollector::ElementCount; /** @@ -68,35 +97,71 @@ class ElementsReporterBuffer */ ElementsReporterBuffer( bool enabled, ElementCount maxCollectionSize ); - // TODO: Proper docs. can be moved without any issue. + /** + * @brief Transfers ownership of an ElementsReporterBuffer to another instance (move semantics). + */ ElementsReporterBuffer( ElementsReporterBuffer && other ) = default; + + /** + * @brief Transfers ownership of an ElementsReporterBuffer to another instance (move semantics). + */ ElementsReporterBuffer & operator=( ElementsReporterBuffer && other ) = default; - // TODO: Proper docs. copying prevented has it doesn't seem useful / relevant. - ElementsReporterBuffer( ElementsReporterBuffer const & other ) = delete; - ElementsReporterBuffer & operator=( ElementsReporterBuffer const & other ) = delete; + /** + * @brief Copying prevented as it doesn't seem relevant / useful. + */ + ElementsReporterBuffer( ElementsReporterBuffer const & ) = delete; + /** + * @brief Copying prevented as it doesn't seem relevant / useful. + */ + ElementsReporterBuffer & operator=( ElementsReporterBuffer const & ) = delete; + + /** + * @return the count of signaled elements. + */ ElementCount getSignaledElementsCount() const { return m_elementsCounter.empty() ? 0 : m_elementsCounter[0]; } + /** + * @return the collected elements that could effectivly be stored (zero if no collection is enabled). + */ ElementCount getCollectedElementsCount() const { return LvArray::math::min( getSignaledElementsCount(), m_elementsBuffer.size() ); } + /** + * @return a reference to an element report by its ID within the buffer (0 -> collected count-1). + */ ElementReport const & operator[]( ElementCount id ) const { return m_elementsBuffer[id]; } + /** + * @return iterator pointing at beginning of collected elements in the buffer. + */ auto begin() const { return m_elementsBuffer.begin(); } + /** + * @return iterator pointing after the last collected element in the buffer. + */ auto end() const { return m_elementsBuffer.begin() + getCollectedElementsCount(); } + /** + * @return true when the collection of elements is enabled. + */ bool enabled() const { return !m_elementsCounter.empty(); } + /** + * @return true when there are no elements collected (always false when enabled() is false). + */ bool empty() const { return getCollectedElementsCount() == 0; } + /** + * @return true if the collection of elements completely fills the buffer. + */ bool isComplete() const { return getCollectedElementsCount() < getSignaledElementsCount(); } @@ -112,7 +177,7 @@ class ElementsReporterBuffer // array of one element to get benefit of managed host-device memory. array1d< ElementCount > m_elementsCounter; - // ids of detected elements + // Preallocated array of ids of detected elements array1d< ElementReport > m_elementsBuffer; }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 62d628fe30d..2fefcde0047 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -36,9 +36,10 @@ struct ElementReport }; /** - * @brief TODO - * @tparam ElementCount TODO - * @tparam IdType TODO + * @brief Collects and reports elements ids and data using an atomic counter. + * This class provides functionality to collect data from multiple threads safely by incrementing + * through an atomic counter for each reported element's ID. The collected IDs are stored in a + * size limited buffer, which can be used later for reporting or analysis purposes. */ class ElementsReporterCollector { @@ -47,12 +48,24 @@ class ElementsReporterCollector using ElementCount = int32_t; - // TODO : proper docs. can be copied & moved as this class only has views to the internal chai memory buffers + /** + * @name Constructors + * @brief This object can be copied and moved as it only provides views to internal memory buffers. + */ + ///@{ + /** @cond DO_NOT_DOCUMENT */ + ElementsReporterCollector( ElementsReporterCollector const & other ) = default; + ElementsReporterCollector( ElementsReporterCollector && other ) = default; + ElementsReporterCollector & operator=( ElementsReporterCollector const & other ) = default; + ElementsReporterCollector & operator=( ElementsReporterCollector && other ) = default; + /** @endcond */ + ///@} + static ElementsReporterCollector disabled() { return ElementsReporterCollector( arrayView1d< ElementCount >(), @@ -61,12 +74,10 @@ class ElementsReporterCollector } /** - * @brief TODO - * @tparam CollectorAtomicPolicy The policy of the atomic increment on the ids counter. - * @param m_elementsCounter The ids counter to increment with an atomic operation. - * @param m_elementsBuffer The output id buffer, in the same memory space as m_elementsCounter. - * If its size is 0 (= disabled output) or not not large enought, the buffer is not filled. - * @param id The Id to add to the buffer. + * @brief Collects a single element report and adds its ID to the output buffer if not disabled and + * there are available slots in the buffer. + * @tparam CollectorAtomicPolicy The atomic increment operation to use for thread-safe counter increments. + * @param report A constant reference to an `ElementReport` object containing data from a single element */ template< typename CollectorAtomicPolicy > GEOS_HOST_DEVICE @@ -100,13 +111,14 @@ class ElementsReporterCollector private: - // array of one element to get benefit of chai managed memory. + /// array of one element to get benefit of chai managed memory. arrayView1d< ElementCount > m_elementsCounter; - // ids of detected elements, quantity limited to 'maxIdsCount' + /// ids of detected elements, quantity limited to 'maxIdsCount' arrayView1d< ElementReport > m_elementsBuffer; - arrayView1d< globalIndex const > m_localToGlobalId; + /// Maps local element IDs to their respective global indices. + arrayView1d m_localToGlobalId; ElementsReporterCollector( arrayView1d< ElementCount > const & elementsCounter, arrayView1d< ElementReport > const & elementsBuffer, From 2e4193cef7744bca39f34872d845e5389f1cd30c Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 18 Jul 2025 15:33:57 +0200 Subject: [PATCH 48/67] =?UTF-8?q?=F0=9F=93=9D=20previous=20commit=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp | 2 ++ .../fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index 3e37fe6c861..2939add8120 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -46,11 +46,13 @@ class ElementsReporterOutput * @return The number of ranks that have signaled an id. */ ElementCount getRanksSignaledIdsCount() const; + { return m_ranksSignaledElementsCount; } /** * @return The total count of collected elements across all ranks for signaling ids. */ ElementCount getRanksCollectedIdsCount() const; + { return m_ranksCollectedElementsCount; } /** * @brief Report elements with values below a specified threshold in the log: diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 2fefcde0047..f9537706e5b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -118,7 +118,7 @@ class ElementsReporterCollector arrayView1d< ElementReport > m_elementsBuffer; /// Maps local element IDs to their respective global indices. - arrayView1d m_localToGlobalId; + arrayView1d< globalIndex const > m_localToGlobalId; ElementsReporterCollector( arrayView1d< ElementCount > const & elementsCounter, arrayView1d< ElementReport > const & elementsBuffer, From 7a839613533aaa907f0d2354350a792761aae8f7 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 18 Jul 2025 15:42:12 +0200 Subject: [PATCH 49/67] =?UTF-8?q?=F0=9F=93=9D=20added=20an=20idea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index f9537706e5b..311c05543c9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -31,7 +31,7 @@ struct ElementReport { /// the global id of the reported element globalIndex m_id; - /// a single value to report for the given element (i.e. a negative pressure, a density...) + /// a value to report for the given element (i.e. a negative pressure, a density... Or if needed could be of a templated type for composite values) real64 m_value; }; From 8bf347068d2c1ac95b60cd5d4c3429e1ba7eeec5 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 21 Jul 2025 16:01:43 +0200 Subject: [PATCH 50/67] =?UTF-8?q?=F0=9F=90=9B=20compil=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/SolutionCheckHelpers.hpp | 4 +- src/coreComponents/schema/schema.xsd | 2 +- src/coreComponents/schema/schema.xsd.other | 100 +++++++++++++++++- 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index 2939add8120..11bb44fa465 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -45,13 +45,13 @@ class ElementsReporterOutput /** * @return The number of ranks that have signaled an id. */ - ElementCount getRanksSignaledIdsCount() const; + ElementCount getRanksSignaledIdsCount() const { return m_ranksSignaledElementsCount; } /** * @return The total count of collected elements across all ranks for signaling ids. */ - ElementCount getRanksCollectedIdsCount() const; + ElementCount getRanksCollectedIdsCount() const { return m_ranksCollectedElementsCount; } /** diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index aca2fe256fa..1872c78a1fb 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -1399,7 +1399,7 @@ Information output from lower logLevels is added with the desired log level - + diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index 77bff2b29ad..a5c1ba8bcd9 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -574,6 +574,8 @@ + + @@ -607,6 +609,8 @@ + + @@ -656,6 +660,8 @@ + + @@ -695,6 +701,8 @@ + + @@ -726,6 +734,8 @@ + + @@ -733,6 +743,8 @@ + + @@ -742,6 +754,8 @@ + + @@ -751,6 +765,8 @@ + + @@ -761,6 +777,8 @@ + + @@ -791,6 +809,8 @@ + + @@ -852,6 +872,8 @@ + + @@ -881,6 +903,8 @@ + + @@ -888,6 +912,8 @@ + + @@ -895,6 +921,8 @@ + + @@ -904,6 +932,8 @@ + + @@ -913,6 +943,8 @@ + + @@ -920,6 +952,8 @@ + + @@ -927,6 +961,8 @@ + + @@ -934,6 +970,8 @@ + + @@ -941,6 +979,8 @@ + + @@ -950,6 +990,8 @@ + + @@ -959,6 +1001,8 @@ + + @@ -968,6 +1012,8 @@ + + @@ -977,6 +1023,8 @@ + + @@ -984,6 +1032,8 @@ + + @@ -993,6 +1043,8 @@ + + @@ -1002,6 +1054,8 @@ + + @@ -1009,6 +1063,8 @@ + + @@ -1016,6 +1072,8 @@ + + @@ -1025,6 +1083,8 @@ + + @@ -1032,6 +1092,8 @@ + + @@ -1039,6 +1101,8 @@ + + @@ -1048,6 +1112,8 @@ + + @@ -1057,6 +1123,8 @@ + + @@ -1066,6 +1134,8 @@ + + @@ -1075,6 +1145,8 @@ + + @@ -1084,6 +1156,8 @@ + + @@ -1091,6 +1165,8 @@ + + @@ -1100,6 +1176,8 @@ + + @@ -1109,6 +1187,8 @@ + + @@ -1118,6 +1198,8 @@ + + @@ -1128,6 +1210,8 @@ + + @@ -1139,6 +1223,8 @@ + + @@ -1152,6 +1238,8 @@ + + @@ -1165,6 +1253,8 @@ + + @@ -1178,6 +1268,8 @@ + + @@ -1189,6 +1281,8 @@ + + @@ -1232,6 +1326,8 @@ + + @@ -1249,6 +1345,8 @@ + + @@ -3213,7 +3311,7 @@ - + From de56d0df5ff48a2037ddc3424200be8b2ac9592d Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Wed, 6 Aug 2025 17:16:17 -0500 Subject: [PATCH 51/67] code style --- .../fluidFlow/SolutionCheckHelpers.hpp | 16 ++++++++-------- .../kernels/SolutionCheckKernelsHelpers.hpp | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index 11bb44fa465..98ecfd798f0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -55,14 +55,14 @@ class ElementsReporterOutput { return m_ranksCollectedElementsCount; } /** - * @brief Report elements with values below a specified threshold in the log: - * Outputs lines indicating which variables have collected element ids whose corresponding - * solution components are too low, potentially signaling underflow or numerical instability. - * @param linesPrefix Prefix for the line of text to be printed - * @param valueNaming The name used when referring to variables within this context (e.g., "pressure", "density"). - * @param minValue Minimum acceptable solution component values. Values below this threshold are reported. - * @param valueUnit Unit in which `minValue` is expressed. - */ + * @brief Report elements with values below a specified threshold in the log: + * Outputs lines indicating which variables have collected element ids whose corresponding + * solution components are too low, potentially signaling underflow or numerical instability. + * @param linesPrefix Prefix for the line of text to be printed + * @param valueNaming The name used when referring to variables within this context (e.g., "pressure", "density"). + * @param minValue Minimum acceptable solution component values. Values below this threshold are reported. + * @param valueUnit Unit in which `minValue` is expressed. + */ void outputTooLowValues( string_view linesPrefix, string_view valueNaming, real64 minValue, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 311c05543c9..995ed362150 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -31,7 +31,8 @@ struct ElementReport { /// the global id of the reported element globalIndex m_id; - /// a value to report for the given element (i.e. a negative pressure, a density... Or if needed could be of a templated type for composite values) + /// a value to report for the given element (i.e. a negative pressure, a density... Or if needed could be of a templated type for + /// composite values) real64 m_value; }; From e4431512e691e9a748d289939921466adc934fd9 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 26 Aug 2025 15:46:38 +0200 Subject: [PATCH 52/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20renamings=20(after?= =?UTF-8?q?=20Pavel=20review)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableFormatter.cpp | 4 ++-- src/coreComponents/common/format/table/TableFormatter.hpp | 2 +- src/coreComponents/common/format/table/TableMpiComponents.cpp | 2 +- .../fluidFlow/wells/CompositionalMultiphaseWell.cpp | 4 ++-- .../physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp | 2 +- .../physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 897ce8b8c88..ed2453a2c7e 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -240,7 +240,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) string const sepLine = string( tableTotalWidth, m_horizontalLine ); outputTableHeader( tableOutput, m_tableLayout, headerCellsLayout, sepLine ); outputTableData( tableOutput, m_tableLayout, dataCellsLayout ); - outputTableBottom( tableOutput, m_tableLayout, errorCellsLayout, sepLine, !dataCellsLayout.empty() ); + outputTableFooter( tableOutput, m_tableLayout, errorCellsLayout, sepLine, !dataCellsLayout.empty() ); return tableOutput.str(); } @@ -731,7 +731,7 @@ void TableTextFormatter::outputTableData( std::ostream & tableOutput, } } -void TableTextFormatter::outputTableBottom( std::ostream & tableOutput, +void TableTextFormatter::outputTableFooter( std::ostream & tableOutput, PreparedTableLayout const & tableLayout, CellLayoutRows & errorCellsLayout, string_view sepLine, diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 522b1e0c0ed..7a197cee32b 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -303,7 +303,7 @@ class TableTextFormatter : public TableFormatter * @param separatorLine A string that will be used as the table separator line * @param hasData Indicates whether there is data in the table TableData. */ - void outputTableBottom( std::ostream & tableOutput, + void outputTableFooter( std::ostream & tableOutput, PreparedTableLayout const & tableLayout, CellLayoutRows & errorCellsLayout, string_view separatorLine, diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index c1a10cee1f4..6aa9d921557 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -75,7 +75,7 @@ void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, if( status.m_isMasterRank ) { - outputTableBottom( tableOutput, m_tableLayout,errorCellsLayout, + outputTableFooter( tableOutput, m_tableLayout,errorCellsLayout, status.m_sepLine, status.m_hasContent ); tableOutput.flush(); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index beefe81c35b..f58ad5688b7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1506,9 +1506,9 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::SoutionDetails >( getLogLevel() ) ? 16 : 0 }; ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::WellValidityDetails >( this->getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::SoutionDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp index 792d8f18243..71b2be540a7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp @@ -66,7 +66,7 @@ struct WellValidity static constexpr std::string_view getDescription() { return "Well validity information"; } }; -struct WellValidityDetails +struct SoutionDetails { static constexpr int getMinLogLevel() { return 2; } static constexpr std::string_view getDescription() { return "Well validity details (negative pressure element ids)"; } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index 8f5893e8fbd..fbe42eb38e8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -967,7 +967,7 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, string const wellDofKey = dofManager.getKey( wellElementDofName() ); ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::WellValidityDetails >( getLogLevel() ) ? 16 : 0 }; + isLogLevelActive< logInfo::SoutionDetails >( getLogLevel() ) ? 16 : 0 }; real64 minNegPres = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, From 79e1b11134179b39bb9fcefe0ac520423b379ddf Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 28 Oct 2025 14:22:50 +0100 Subject: [PATCH 53/67] =?UTF-8?q?=F0=9F=90=9B=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compositional/parameters/KValueFlashParameters.cpp | 4 ++-- .../fluidFlow/wells/CompositionalMultiphaseWell.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/compositional/parameters/KValueFlashParameters.cpp b/src/coreComponents/constitutive/fluid/multifluid/compositional/parameters/KValueFlashParameters.cpp index 3160bf2644b..e17f9e6efde 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/compositional/parameters/KValueFlashParameters.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/compositional/parameters/KValueFlashParameters.cpp @@ -381,7 +381,7 @@ bool KValueFlashParameters< NUM_PHASE >::validateKValues( MultiFluidBase const * } hasAtLeastOneNegative = hasAtLeastOneNegative || hasNegative; hasAtLeastOneOneSided = hasAtLeastOneOneSided || (allMoreThanUnity || allLessThanUnity); - if( (allMoreThanUnity || allLessThanUnity || hasNegative) && tableData.getTableDataRows().size() < 5 ) + if( (allMoreThanUnity || allLessThanUnity || hasNegative) && tableData.getCellsData().size() < 5 ) { tableRow[0].value = phaseNames[phaseIndex+1]; tableRow[1].value = GEOS_FMT( "{0:.3e}", m_pressureValues[0][pressureIndex] ); @@ -397,7 +397,7 @@ bool KValueFlashParameters< NUM_PHASE >::validateKValues( MultiFluidBase const * } } - if( !tableData.getTableDataRows().empty()) + if( !tableData.getCellsData().empty()) { std::vector< TableLayout::Column > columns; columns.emplace_back( TableLayout::Column().setName( "Phase" ).setValuesAlignment( TableLayout::Alignment::left ) ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index a32de8c0070..d125e08ca86 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1620,10 +1620,10 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; integer numNegTotalDens = 0; - ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::SoutionDetails >( getLogLevel() ) ? 16 : 0 }; - ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::SoutionDetails >( this->getLogLevel() ) ? 16 : 0 }; + ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; + ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -1713,7 +1713,7 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, "negative component density", minDens, massUnit ); if( numNegTotalDens > 0 ) { - GEOS_LOG_LEVEL_RANK_0( logInfo::WellValidity, + GEOS_LOG_LEVEL_RANK_0( logInfo::SolutionDetails, GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}", getName(), numNegTotalDens, fmt::format( "{:.{}f}", minTotalDens, 3 ), units::getSymbol( massUnit ) ) ); } From b78a3d79c1cfab6cbd828942f48f0144106d05a7 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 27 Oct 2025 16:52:03 +0100 Subject: [PATCH 54/67] =?UTF-8?q?=F0=9F=93=9D=20small=20precision=20on=20l?= =?UTF-8?q?oginfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/physicsSolvers/LogLevelsInfo.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp b/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp index e288170a6cb..73037d8bb04 100644 --- a/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp +++ b/src/coreComponents/physicsSolvers/LogLevelsInfo.hpp @@ -94,7 +94,7 @@ struct Solution struct SolutionDetails { static constexpr int getMinLogLevel() { return 2; } - static constexpr std::string_view getDescription() { return "Solution details (negative values ids)"; } + static constexpr std::string_view getDescription() { return "Solution details (incoherent negative values ids)"; } }; struct SolverInitialization From 9cf5abe9c1f474adfb994acdf0a4fffe1589bd29 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 28 Oct 2025 14:36:31 +0100 Subject: [PATCH 55/67] =?UTF-8?q?=F0=9F=90=9B=20typo=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index 30e8eb12450..bacbb39dbc6 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -1013,8 +1013,8 @@ bool SinglePhaseWell::checkSystemSolution( DomainPartition & domain, GEOS_MARK_FUNCTION; string const wellDofKey = dofManager.getKey( wellElementDofName() ); - ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::WellValidity >( getLogLevel() ), - isLogLevelActive< logInfo::SoutionDetails >( getLogLevel() ) ? 16 : 0 }; + ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; real64 minNegPres = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, From 69cd64c57ffc358b2706777d423ee257b86eb1e7 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Wed, 29 Oct 2025 10:50:29 +0100 Subject: [PATCH 56/67] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20merge=20missing=20va?= =?UTF-8?q?riable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/unitTests/testTable.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 0dec25ca47c..5194c9fd622 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -827,8 +827,6 @@ TEST( testTable, tableSpecialsValues ) .setName( "Next\nelement" ) .setHeaderAlignment( TableLayout::Alignment::center )} ); - LvArray::NumericLimits< double > const realLimit; - TableData tableData; tableData.addRow( "Global Id", 1234, 40, 5678, 60 ); tableData.addRow( "pressure", 0.1234, 0.40, 0.5678, 0.60 ); From b3bfe1a880ddd9690b665c862e87e363d31321e1 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 4 Nov 2025 14:38:43 +0100 Subject: [PATCH 57/67] =?UTF-8?q?=F0=9F=8E=A8=20=20copilot=20code=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp | 2 +- .../physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp | 2 +- .../fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp | 2 +- .../fluidFlow/kernels/compositional/SolutionCheckKernel.hpp | 2 +- src/coreComponents/schema/schema.xsd.other | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp index 5143a030203..3d9366ef3b7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.cpp @@ -14,7 +14,7 @@ */ /** - * @file SolutionCheckKernel.hpp + * @file SolutionCheckKernel.cpp */ #include "physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp index 98ecfd798f0..9965dcb3d75 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SolutionCheckHelpers.hpp @@ -187,4 +187,4 @@ class ElementsReporterBuffer } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPER_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKHELPERS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp index 995ed362150..46a28a532b5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SolutionCheckKernelsHelpers.hpp @@ -134,4 +134,4 @@ class ElementsReporterCollector } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPER_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLUTIONCHECKKERNELSHELPERS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 1985f8a70ed..e7544fc655d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -120,7 +120,7 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer real64 localMinNegDens; real64 localMinNegTotalDens; - localIndex localNumNegTotalDens; // ne peuvent être que 0 ou 1 dans chaque kernel + localIndex localNumNegTotalDens; // Can only be 0 or 1 in each kernel }; /** diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index 1e46dbb59ce..be1be670c48 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -516,7 +516,7 @@ - + @@ -1502,7 +1502,7 @@ - + From b5d66becd7e175c149bf8437aeec270837d08eac Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 4 Nov 2025 14:46:27 +0100 Subject: [PATCH 58/67] =?UTF-8?q?=F0=9F=8E=A8=20=F0=9F=93=9D=20=20code=20s?= =?UTF-8?q?tyle=20&=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableFormatter.hpp | 2 +- src/coreComponents/common/format/table/TableMpiComponents.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 7a197cee32b..890979ca9b2 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -289,7 +289,6 @@ class TableTextFormatter : public TableFormatter * @brief Outputs the data part of the formatted table to the provided output stream. * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. * @param tableLayout The layout of the table - * @param errorCellsLayout The layout of the error rows * @param dataCellsLayout The data rows in a grid layout */ void outputTableData( std::ostream & tableOutput, @@ -301,6 +300,7 @@ class TableTextFormatter : public TableFormatter * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. * @param tableLayout The layout of the table * @param separatorLine A string that will be used as the table separator line + * @param errorCellsLayout The layout of the error rows * @param hasData Indicates whether there is data in the table TableData. */ void outputTableFooter( std::ostream & tableOutput, diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index 6aa9d921557..ad553f72771 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -75,7 +75,7 @@ void TableTextMpiOutput::toStream< TableData >( std::ostream & tableOutput, if( status.m_isMasterRank ) { - outputTableFooter( tableOutput, m_tableLayout,errorCellsLayout, + outputTableFooter( tableOutput, m_tableLayout, errorCellsLayout, status.m_sepLine, status.m_hasContent ); tableOutput.flush(); } From 89c5505246f650df3d3375ab054a9e7bcbe8d58c Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 4 Nov 2025 15:17:52 +0100 Subject: [PATCH 59/67] =?UTF-8?q?=F0=9F=93=9D=20=20doc=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableFormatter.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 890979ca9b2..eed907975c2 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -277,7 +277,6 @@ class TableTextFormatter : public TableFormatter * @param tableOutput A reference to an `std::ostream` where the formatted table will be written. * @param tableLayout The layout of the table * @param headerCellsLayout The header rows in a grid layout - * @param errorCellsLayout The layout of the error rows * @param separatorLine A string that will be used as the table separator line */ void outputTableHeader( std::ostream & tableOutput, From 370da84f2ac20c11617360682ca414b000a0b38e Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Tue, 4 Nov 2025 17:10:52 +0100 Subject: [PATCH 60/67] =?UTF-8?q?=F0=9F=90=9B=20unit=20test=20merge=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../format/table/unitTests/testTable.cpp | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 5194c9fd622..b8f76efa758 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -827,19 +827,32 @@ TEST( testTable, tableSpecialsValues ) .setName( "Next\nelement" ) .setHeaderAlignment( TableLayout::Alignment::center )} ); + LvArray::NumericLimits< double > const realLimit; + TableData tableData; - tableData.addRow( "Global Id", 1234, 40, 5678, 60 ); - tableData.addRow( "pressure", 0.1234, 0.40, 0.5678, 0.60 ); + tableData.addRow( realLimit.infinity, "dummy1", "dummy2", "dummy3", "dummy4", "dummy5" ); + tableData.addRow( realLimit.quiet_NaN, "dummy1", "dummy2", "dummy3", "dummy4", "dummy5" ); + tableData.addRow( realLimit.signaling_NaN, "dummy1", "dummy2", "dummy3", "dummy4", "dummy5" ); + tableData.addRow( realLimit.lowest, "dummy1", "dummy2", "dummy3", "dummy4", "dummy5" ); + tableData.addRow( realLimit.max, "dummy1", "dummy2", "dummy3", "dummy4", "dummy5" ); + tableData.addRow( realLimit.denorm_min, "dummy1", "dummy2", "dummy3", "dummy4", "dummy5" ); TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n" - " -------------------------------------------\n" - " | Title |\n" - " |-----------------------------------------|\n" - " | Global Id | 1234 | 40 | 5678 | 60 |\n" - " | pressure | 0.1234 | 0.4 | 0.5678 | 0.6 |\n" - " -------------------------------------------\n" + "---------------------------------------------------------------------------------------\n" + "| Special values | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "|----------------------------|----------|----------|----------|-----------|-----------|\n" + "| inf | dummy1 | dummy2 | dummy3 | dummy4 | dummy5 |\n" + "| nan | dummy1 | dummy2 | dummy3 | dummy4 | dummy5 |\n" + "| nan | dummy1 | dummy2 | dummy3 | dummy4 | dummy5 |\n" + "| -1.7976931348623157e+308 | dummy1 | dummy2 | dummy3 | dummy4 | dummy5 |\n" + "| 1.7976931348623157e+308 | dummy1 | dummy2 | dummy3 | dummy4 | dummy5 |\n" + "| 5e-324 | dummy1 | dummy2 | dummy3 | dummy4 | dummy5 |\n" + "|-------------------------------------------------------------------------------------|\n" + "| Warning : Invalid values detected (nan/inf). |\n" + "---------------------------------------------------------------------------------------\n" ); } From fe602227ee7e5f51e70ede6f28528d685ceed658 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 9 Feb 2026 16:14:35 +0100 Subject: [PATCH 61/67] =?UTF-8?q?=F0=9F=94=8A=20pressures/densities=20equa?= =?UTF-8?q?l=20to=200.0=20are=20also=20reported=20(not=20only=20negatives)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/kernels/compositional/SolutionCheckKernel.hpp | 6 +++--- .../fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index e7544fc655d..1e57ed629cf 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -237,7 +237,7 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer bool const localScaling = m_scalingType == compositionalMultiphaseUtilities::ScalingType::Local; real64 const newPres = m_pressure[ei] + (localScaling ? m_pressureScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow]; - if( newPres < 0 ) + if( newPres <= 0.0 ) { stack.localNumNegPres = 1; @@ -256,7 +256,7 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer for( integer ic = 0; ic < m_numComp; ++ic ) { real64 const newDens = m_compDens[ei][ic] + (localScaling ? m_compDensScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow + ic + 1]; - if( newDens < 0 ) + if( newDens <= 0.0 ) { stack.localNumNegDens = 1; stack.localMinVal = 0; @@ -274,7 +274,7 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer real64 const newDens = m_compDens[ei][ic] + (localScaling ? m_compDensScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow + ic + 1]; totalDens += ( newDens > 0.0 ) ? newDens : 0.0; } - if( totalDens < 0 ) + if( totalDens <= 0.0 ) { stack.localNumNegTotalDens = 1; stack.localMinVal = 0; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp index 46ee6972ed0..16bd95ea27d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp @@ -60,7 +60,7 @@ struct SolutionCheckKernel localIndex const lid = dofNumber[ei] - rankOffset; real64 const newPres = pres[ei] + scalingFactor * localSolution[lid]; - if( newPres < 0.0 ) + if( newPres <= 0.0 ) { minNegPres.min( newPres ); negPressureIds.collectElement( atomicPolicy{}, { ei, newPres } ); From 7c6e4b19d52876ac52d92da4de67f28fceb7c438 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 13 Feb 2026 15:42:29 +0100 Subject: [PATCH 62/67] =?UTF-8?q?=E2=9A=A1=EF=B8=8Fthanks=20dudes-guy=20fo?= =?UTF-8?q?r=20com=20optimisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableMpiComponents.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index ad553f72771..d0276eabb70 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -128,7 +128,7 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, std::vector< integer > ranksStrsSizes = std::vector( ranksCount, 0 ); string const rankStr = !status.m_isMasterRank && status.m_isContributing ? localStringStream.str() : ""; integer const rankStrSize = rankStr.size(); - MpiWrapper::allgather( &rankStrSize, 1, ranksStrsSizes.data(), 1 ); + MpiWrapper::gather( &rankStrSize, 1, ranksStrsSizes.data(), 1, 0 ); // we compute the memory layout of the ranks strings std::vector< integer > ranksStrsOffsets = std::vector( ranksCount, 0 ); From d56680569d2da0d88ba85d4715db60833f22717c Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 13 Feb 2026 15:42:29 +0100 Subject: [PATCH 63/67] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20std::vector->stdVect?= =?UTF-8?q?or?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableMpiComponents.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index d0276eabb70..4f981b25f92 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -125,13 +125,13 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, } // all other ranks than rank 0 render their output in a string and comunicate its size - std::vector< integer > ranksStrsSizes = std::vector( ranksCount, 0 ); + stdVector< integer > ranksStrsSizes = stdVector< integer >( ranksCount, 0 ); string const rankStr = !status.m_isMasterRank && status.m_isContributing ? localStringStream.str() : ""; integer const rankStrSize = rankStr.size(); MpiWrapper::gather( &rankStrSize, 1, ranksStrsSizes.data(), 1, 0 ); // we compute the memory layout of the ranks strings - std::vector< integer > ranksStrsOffsets = std::vector( ranksCount, 0 ); + stdVector< integer > ranksStrsOffsets = stdVector< integer >( ranksCount, 0 ); integer ranksStrsTotalSize = 0; for( integer rankId = 1; rankId < ranksCount; ++rankId ) { From 0a903af1f18c50824e68fa33acf5fd5c5b37f540 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 13 Feb 2026 15:42:30 +0100 Subject: [PATCH 64/67] =?UTF-8?q?=F0=9F=8E=A8=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableFormatter.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index bf5779fdc23..da34bcf242c 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -157,7 +157,6 @@ string TableCSVFormatter::headerToString() const string TableCSVFormatter::dataToString( TableData const & tableData ) const { - RowsCellInput const rowsValues( tableData.getCellsData() ); string result; size_t total_size = 0; @@ -314,14 +313,14 @@ void TableTextFormatter::populateTitleCellsLayout( PreparedTableLayout const & t // the title row consists in a row of cells merging with the last cell containing the title text headerCellsLayout.emplace_back() = { stdVector< TableLayout::CellLayout >( nbVisibleColumns, - TableLayout::CellLayout( CellType::MergeNext ) ), // cells + TableLayout::CellLayout( CellType::MergeNext ) ), // cells titleInput.getHeight(), // sublinesCount }; headerCellsLayout.back().cells.back() = titleInput; headerCellsLayout.emplace_back() = { stdVector< TableLayout::CellLayout >( nbVisibleColumns, - TableLayout::CellLayout( CellType::Separator ) ), // cells + TableLayout::CellLayout( CellType::Separator ) ), // cells 1, // sublinesCount }; } From a30d25944856e437b283e41a9aebcf829b11c80f Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 13 Feb 2026 16:00:56 +0100 Subject: [PATCH 65/67] =?UTF-8?q?=E2=99=BB=EF=B8=8Foutput=20total=20densit?= =?UTF-8?q?y=20the=20same=20way?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 17 +++++++-------- .../CompositionalMultiphaseHybridFVM.cpp | 1 + .../compositional/SolutionCheckKernel.hpp | 21 +++++++++---------- .../wells/CompositionalMultiphaseWell.cpp | 4 +++- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index b1b45318d45..bbd8778d711 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -852,6 +852,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; + ElementsReporterBuffer rankTotalNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), + isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -873,6 +875,7 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, auto const & cellLocalToGlobalIds = subRegion.localToGlobalMap(); auto const negPresCollector = rankNegPressureIds.createCollector( cellLocalToGlobalIds ); auto const negDensCollector = rankNegDensityIds.createCollector( cellLocalToGlobalIds ); + auto const negTotalDensCollector = rankTotalNegDensityIds.createCollector( cellLocalToGlobalIds ); // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K @@ -897,6 +900,7 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, localSolution, negPresCollector, negDensCollector, + negTotalDensCollector, temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: @@ -914,21 +918,20 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, subRegion, localSolution, negPresCollector, - negDensCollector ); + negDensCollector, + negTotalDensCollector ); localCheck = std::min( localCheck, subRegionData.localMinVal ); minPres = std::min( minPres, subRegionData.localMinNegPres ); minDens = std::min( minDens, subRegionData.localMinNegDens ); minTotalDens = std::min( minTotalDens, subRegionData.localMinNegTotalDens ); - numNegTotalDens += subRegionData.localNumNegTotalDens; } ); } ); minPres = MpiWrapper::min( minPres ); minDens = MpiWrapper::min( minDens ); minTotalDens = MpiWrapper::min( minTotalDens ); - numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative pressure", minPres, units::Unit::Pressure ); @@ -936,12 +939,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; rankNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative component density", minDens, massUnit ); - if( numNegTotalDens > 0 ) - { - GEOS_LOG_LEVEL_RANK_0( logInfo::Solution, - GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}", - getName(), numNegTotalDens, fmt::format( "{:.{}f}", minTotalDens, 3 ), units::getSymbol( massUnit ) ) ); - } + rankNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), + "negative component total density", minTotalDens, massUnit ); return MpiWrapper::min( localCheck ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index ede2009eb62..00afd9f6f5f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -624,6 +624,7 @@ bool CompositionalMultiphaseHybridFVM::checkSystemSolution( DomainPartition & do subRegion, localSolution, ElementsReporterCollector::disabled(), + ElementsReporterCollector::disabled(), ElementsReporterCollector::disabled() ); localCheck = std::min( localCheck, subRegionData.localMinVal ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 1e57ed629cf..c75b18a7b72 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -74,7 +74,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer ElementSubRegionBase const & subRegion, arrayView1d< real64 const > const localSolution, ElementsReporterCollector const & negPressureIds, - ElementsReporterCollector const & negDensityIds ) + ElementsReporterCollector const & negDensityIds, + ElementsReporterCollector const & negTotalDensityIds ) : Base( rankOffset, numComp, dofKey, @@ -89,7 +90,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer m_scalingFactor( scalingFactor ), m_scalingType( scalingType ), m_negPressureIds( negPressureIds ), - m_negDensityIds( negDensityIds ) + m_negDensityIds( negDensityIds ), + m_negTotalDensityIds( negTotalDensityIds ) {} /** @@ -112,15 +114,12 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer Base::StackVariables( _localMinVal ), localMinNegPres( _localNegMinPres ), localMinNegDens( _localMinNegDens ), - localMinNegTotalDens( _localMinNegTotalDens ), - localNumNegTotalDens( _localNumNegTotalDens ) + localMinNegTotalDens( _localMinNegTotalDens ) { } real64 localMinNegPres; real64 localMinNegDens; real64 localMinNegTotalDens; - - localIndex localNumNegTotalDens; // Can only be 0 or 1 in each kernel }; /** @@ -134,8 +133,9 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer KernelStats() { } - localIndex localNumNegPres; - localIndex localNumNegDens; + localIndex localNumNegPres; // 0 or 1 + localIndex localNumNegDens; // 0 -> num comp + localIndex localNumNegTotalDens; // 0 or 1 }; /** @@ -159,8 +159,6 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer RAJA::ReduceMin< reducePolicy, real64 > minDens( 0.0 ); RAJA::ReduceMin< reducePolicy, real64 > minTotalDens( 0.0 ); - RAJA::ReduceSum< reducePolicy, localIndex > numNegTotalDens( 0 ); - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) { if( kernelComponent.ghostRank( ei ) >= 0 ) @@ -184,7 +182,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer if( stack.localNumNegDens > 0 ) kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegDens } ); - numNegTotalDens += stack.localNumNegTotalDens; + if( stack.localNumNegTotalDens > 0 ) + kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localNumNegTotalDens } ); } ); return KernelStats( globalMinVal.get(), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index a786a4841e8..2efcc30cc65 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1668,6 +1668,7 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, localSolution, negPresCollector, negDensCollector, + negTotalDensCollector, temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: @@ -1685,7 +1686,8 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, subRegion, localSolution, negPresCollector, - negDensCollector ); + negDensCollector, + negTotalDensCollector ); localCheck = std::min( localCheck, subRegionData.localMinVal ); From f67f639f704918e4e409085f45d0c520f12ebd4d Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 16 Feb 2026 18:28:16 +0100 Subject: [PATCH 66/67] =?UTF-8?q?=F0=9F=90=9Bbugfix=20table=20footer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/format/table/TableMpiComponents.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreComponents/common/format/table/TableMpiComponents.cpp b/src/coreComponents/common/format/table/TableMpiComponents.cpp index 4f981b25f92..4bf969282c9 100644 --- a/src/coreComponents/common/format/table/TableMpiComponents.cpp +++ b/src/coreComponents/common/format/table/TableMpiComponents.cpp @@ -146,6 +146,9 @@ void TableTextMpiOutput::outputTableDataToRank0( std::ostream & tableOutput, 0, MPI_COMM_GEOS ); if( status.m_isMasterRank ) { + // master rank status + status.m_hasContent = !dataCellsLayout.empty(); + for( integer rankId = 1; rankId < ranksCount; ++rankId ) { if( ranksStrsSizes[rankId] > 0 ) From c3891ad963393ebf6c917d7879aa4c7262194146 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 16 Feb 2026 18:37:10 +0100 Subject: [PATCH 67/67] =?UTF-8?q?=F0=9F=90=9Bvarious=20compil=20fixes=20fo?= =?UTF-8?q?r=20total=20density=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 5 ++--- .../compositional/SolutionCheckKernel.hpp | 20 ++++++++++--------- .../ThermalSolutionCheckKernel.hpp | 11 ++++++---- .../wells/CompositionalMultiphaseWell.cpp | 14 +++++-------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index bbd8778d711..d053b9fe64e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -847,13 +847,12 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; - integer numNegTotalDens = 0; ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; - ElementsReporterBuffer rankTotalNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), - isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; + // output only total density sum, not cell details + ElementsReporterBuffer rankTotalNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index c75b18a7b72..93b026df798 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -106,13 +106,12 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer {} KernelStats( real64 _localMinVal, - real64 _localNegMinPres, + real64 _localMinNegPres, real64 _localMinNegDens, - real64 _localMinNegTotalDens, - integer _localNumNegTotalDens ) + real64 _localMinNegTotalDens ) : Base::StackVariables( _localMinVal ), - localMinNegPres( _localNegMinPres ), + localMinNegPres( _localMinNegPres ), localMinNegDens( _localMinNegDens ), localMinNegTotalDens( _localMinNegTotalDens ) { } @@ -183,14 +182,13 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegDens } ); if( stack.localNumNegTotalDens > 0 ) - kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localNumNegTotalDens } ); + kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegTotalDens } ); } ); return KernelStats( globalMinVal.get(), minPres.get(), minDens.get(), - minTotalDens.get(), - numNegTotalDens.get() ); + minTotalDens.get() ); } GEOS_HOST_DEVICE @@ -304,6 +302,8 @@ class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer ElementsReporterCollector const m_negDensityIds; + ElementsReporterCollector const m_negTotalDensityIds; + }; /** @@ -340,11 +340,13 @@ class SolutionCheckKernelFactory ElementSubRegionBase & subRegion, arrayView1d< real64 const > const localSolution, ElementsReporterCollector const & negPressureIds, - ElementsReporterCollector const & negDensityIds ) + ElementsReporterCollector const & negDensityIds, + ElementsReporterCollector const & negTotalDensityIds ) { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset, - numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds ); + numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds, + negTotalDensityIds ); return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp index 455eec757dd..10566b06827 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp @@ -75,6 +75,7 @@ class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels: arrayView1d< real64 const > const localSolution, ElementsReporterCollector const & negPressureIds, ElementsReporterCollector const & negDensityIds, + ElementsReporterCollector const & negTotalDensityIds, integer const temperatureOffset ) : Base( allowCompDensChopping, allowNegativePressure, @@ -90,7 +91,8 @@ class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels: subRegion, localSolution, negPressureIds, - negDensityIds ), + negDensityIds, + negTotalDensityIds ), m_temperature( temperature ), m_temperatureScalingFactor( temperatureScalingFactor ), m_temperatureOffset( temperatureOffset ) @@ -168,12 +170,13 @@ class SolutionCheckKernelFactory arrayView1d< real64 const > const localSolution, ElementsReporterCollector const & negPressureIds, ElementsReporterCollector const & negDensityIds, + ElementsReporterCollector const & negTotalDensityIds, integer temperatureOffset ) { SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, - pressure, temperature, compDens, pressureScalingFactor, compDensScalingFactor, temperatureScalingFactor, - rankOffset, numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds, - temperatureOffset ); + pressure, temperature, compDens, pressureScalingFactor, compDensScalingFactor, + temperatureScalingFactor, rankOffset, numComp, dofKey, subRegion, localSolution, + negPressureIds, negDensityIds, negTotalDensityIds, temperatureOffset ); return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 2efcc30cc65..46ff46c8fd1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -1615,11 +1615,12 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, string const wellDofKey = dofManager.getKey( wellElementDofName() ); integer localCheck = 1; real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; - integer numNegTotalDens = 0; ElementsReporterBuffer rankNegPressureIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( getLogLevel() ) ? 16 : 0 }; ElementsReporterBuffer rankNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), isLogLevelActive< logInfo::SolutionDetails >( this->getLogLevel() ) ? 16 : 0 }; + // output only total density sum, not cell details + ElementsReporterBuffer rankTotalNegDensityIds{ isLogLevelActive< logInfo::Solution >( getLogLevel() ), 0 }; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -1644,6 +1645,7 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, auto const & cellLocalToGlobalIds = subRegion.localToGlobalMap(); auto const negPresCollector = rankNegPressureIds.createCollector( cellLocalToGlobalIds ); auto const negDensCollector = rankNegDensityIds.createCollector( cellLocalToGlobalIds ); + auto const negTotalDensCollector = rankNegDensityIds.createCollector( cellLocalToGlobalIds ); // check that pressure and component densities are non-negative // for thermal, check that temperature is above 273.15 K @@ -1694,14 +1696,12 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, minPres = std::min( minPres, subRegionData.localMinNegPres ); minDens = std::min( minDens, subRegionData.localMinNegDens ); minTotalDens = std::min( minTotalDens, subRegionData.localMinNegTotalDens ); - numNegTotalDens += subRegionData.localNumNegTotalDens; } ); } ); minPres = MpiWrapper::min( minPres ); minDens = MpiWrapper::min( minDens ); minTotalDens = MpiWrapper::min( minTotalDens ); - numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); rankNegPressureIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative pressure", minPres, units::Unit::Pressure ); @@ -1709,12 +1709,8 @@ CompositionalMultiphaseWell::checkSystemSolution( DomainPartition & domain, units::Unit const massUnit = m_useMass ? units::Unit::Density : units::Unit::MolarDensity; rankNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), "negative component density", minDens, massUnit ); - if( numNegTotalDens > 0 ) - { - GEOS_LOG_LEVEL_RANK_0( logInfo::SolutionDetails, - GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}", - getName(), numNegTotalDens, fmt::format( "{:.{}f}", minTotalDens, 3 ), units::getSymbol( massUnit ) ) ); - } + rankTotalNegDensityIds.createOutput().outputTooLowValues( GEOS_FMT( " {}: ", getName() ), + "negative components total density", minTotalDens, massUnit ); return MpiWrapper::min( localCheck ); }