diff --git a/src/CompositionalMultiphaseStatist.plantuml b/src/CompositionalMultiphaseStatist.plantuml new file mode 100644 index 00000000000..4133442d469 --- /dev/null +++ b/src/CompositionalMultiphaseStatist.plantuml @@ -0,0 +1,86 @@ + + +class Group #text:00000060 +class ExecutableGroup #text:00000060 +class TaskBase #text:00000060 +class FieldStatisticsBase #text:00000060 +class ObjectManagerBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class WellSolverBase #text:00000060 +class PhysicsSolverBase #text:00000060 + +class FieldStatisticsBase< SOLVER_T > #text:00000060 { + string m_solverName (user input : "solverName") + string m_outputDir (user input : "outputDir") + bool m_writeCSV (user input : "writeCSV") +} + +Group <|-- ExecutableGroup +ExecutableGroup <|-- TaskBase +TaskBase <|-- FieldStatisticsBase + +Group <|-- ObjectManagerBase +ObjectManagerBase <|-- ElementSubRegionBase +ElementSubRegionBase <|-- CellElementRegion + +WellSolverBase <|-- CompositionalMultiphaseWell +PhysicsSolverBase <|-- WellSolverBase +ExecutableGroup <|-- PhysicsSolverBase + +class CompositionalMultiphaseStatistics { + m_computeCFLNumbers (user input: "computeCFLNumbers") + m_computeRegionStatistics (user input: "computeRegionStatistics") + m_relpermThreshold (user input: "relpermThreshold") + -- + void postInputInitialization() override + void registerDataOnMesh( Group & meshBodies ) override + void execute( time_n, dt, [...], domain ) + void computeRegionStatistics( time, meshLevel, regionNames ) + void computeCFLNumbers( time, dt, domainPartition ) +} +FieldStatisticsBase <|-- CompositionalMultiphaseStatistics : SOLVER_T = CompositionalMultiphaseBase + + +class RegionStatistics { + real64 averagePressure + real64 minPressure + real64 maxPressure + + real64 minDeltaPressure + real64 maxDeltaPressure + + real64 averageTemperature + real64 minTemperature + real64 maxTemperature + + real64 totalPoreVolume + real64 totalUncompactedPoreVolume + array1d phasePoreVolume + + array1d phaseMass + array1d trappedPhaseMass + array1d immobilePhaseMass + array2d componentMass +} +note left of RegionStatistics + Also exists in single-phase version with: + real64 averagePressure + real64 minPressure + real64 maxPressure + + real64 minDeltaPressure + real64 maxDeltaPressure + + real64 averageTemperature + real64 minTemperature + real64 maxTemperature + + real64 totalPoreVolume + real64 totalUncompactedPoreVolume + + real64 totalMass +end note +CompositionalMultiphaseStatistics ....> RegionStatistics : "instanciate\n&\ncomputes\n&\nreads data from" +CompositionalMultiphaseWell ....> RegionStatistics : "reads data\nfrom" +CellElementRegion *--l--> RegionStatistics : ""regionStatistics"\nWrapper" diff --git a/src/New2CompositionalMultiphaseStatist.plantuml b/src/New2CompositionalMultiphaseStatist.plantuml new file mode 100644 index 00000000000..f4449422be1 --- /dev/null +++ b/src/New2CompositionalMultiphaseStatist.plantuml @@ -0,0 +1,83 @@ + + +class Group #text:00000060 +class ExecutableGroup #text:00000060 +class TaskBase #text:00000060 +class FieldStatisticsBase #text:00000060 +class ObjectManagerBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class WellSolverBase #text:00000060 +class PhysicsSolverBase #text:00000060 + +class FieldStatisticsBase< SOLVER_T > #text:00000060 { + string m_solverName (user input : "solverName") + string m_outputDir (user input : "outputDir") + bool m_writeCSV (user input : "writeCSV") +} + +Group <|-- ExecutableGroup +ExecutableGroup <|-- TaskBase +TaskBase <|-- FieldStatisticsBase + +Group <|-- ObjectManagerBase +ObjectManagerBase <|-- ElementSubRegionBase +ElementSubRegionBase <|-- CellElementRegion + +WellSolverBase <|-- CompositionalMultiphaseWell +PhysicsSolverBase <|-- WellSolverBase +ExecutableGroup <|-- PhysicsSolverBase + +class CompositionalMultiphaseStatisticsTask #text:Green { + bool m_computeCFLNumbers (wrapper: "computeCFLNumbers") + bool m_computeRegionStatistics (wrapper: "computeRegionStatistics") + float m_relpermThreshold (wrapper: "relpermThreshold") + -- + void postInputInitialization() override + void execute( time_n, dt, [...], domain ) +} +note bottom of CompositionalMultiphaseStatisticsTask + User defined executable task for + statistics computation & output +end note +FieldStatisticsBase <|-- CompositionalMultiphaseStatisticsTask : SOLVER_T = CompositionalMultiphaseBase + +class CompositionalMultiphaseStatisticsAggregator #text:Green { + void registerDataOnMesh( Group & meshBodies ) override + void computeRegionStatistics( time, meshLevel, regionNames ) + void computeCFLNumbers( time, dt, domainPartition, m_relpermThreshold ) + void forRegionStatstics( functor ) +} +note bottom of CompositionalMultiphaseStatisticsAggregator + Generated sub-group for instanciating + RegionStatistics over the regions & + doing statistics computation. +end note +CompositionalMultiphaseStatisticsTask *---> CompositionalMultiphaseStatisticsAggregator : "contains one" +CompositionalMultiphaseWell *---> CompositionalMultiphaseStatisticsAggregator : "contains one" + +class RegionStatistics { + real64 averagePressure + real64 minPressure + real64 maxPressure + + real64 minDeltaPressure + real64 maxDeltaPressure + + real64 averageTemperature + real64 minTemperature + real64 maxTemperature + + real64 totalPoreVolume + real64 totalUncompactedPoreVolume + array1d phasePoreVolume + + array1d phaseMass + array1d trappedPhaseMass + array1d immobilePhaseMass + array2d componentMass +} +CompositionalMultiphaseStatisticsAggregator ...> RegionStatistics : "instanciate\n&\ncomputes" +CompositionalMultiphaseStatisticsTask ..> RegionStatistics : "reads data\nfrom" +CompositionalMultiphaseWell ...> RegionStatistics : "reads data\nfrom" +CellElementRegion *--l--> RegionStatistics : ""regionStatistics"\nWrapper" diff --git a/src/New3CompositionalMultiphaseStatist.plantuml b/src/New3CompositionalMultiphaseStatist.plantuml new file mode 100644 index 00000000000..e41f9e36ca1 --- /dev/null +++ b/src/New3CompositionalMultiphaseStatist.plantuml @@ -0,0 +1,115 @@ + + +class Group #text:00000060 +class ExecutableGroup #text:00000060 +class TaskBase #text:00000060 +class FieldStatisticsBase #text:00000060 +class ObjectManagerBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class WellSolverBase #text:00000060 +class PhysicsSolverBase #text:00000060 + +class FieldStatisticsBase< SOLVER_T > #text:00000060 { + string m_solverName (user input : "solverName") + string m_outputDir (user input : "outputDir") + bool m_writeCSV (user input : "writeCSV") +} + +Group <|-- ExecutableGroup +ExecutableGroup <|-- TaskBase +TaskBase <|-- FieldStatisticsBase + +Group <|-- ObjectManagerBase +ObjectManagerBase <|-- ElementSubRegionBase +ElementSubRegionBase <|-- CellElementRegion + +WellSolverBase <|-- CompositionalMultiphaseWell +PhysicsSolverBase <|-- WellSolverBase +ExecutableGroup <|-- PhysicsSolverBase + +class CompositionalMultiphaseStatisticsTask #text:Green { + bool m_computeCFLNumbers (wrapper: "computeCFLNumbers") + bool m_computeRegionStatistics (wrapper: "computeRegionStatistics") + float m_relpermThreshold (wrapper: "relpermThreshold") + -- + void postInputInitialization() override + void execute( time_n, dt, [...], domain ) +} +note bottom of CompositionalMultiphaseStatisticsTask + User defined executable task for + statistics computation & output +end note +FieldStatisticsBase <|-- CompositionalMultiphaseStatisticsTask : SOLVER_T = CompositionalMultiphaseBase + +class CompositionalMultiphaseStatisticsAggregator #text:Green { + void registerDataOnMesh( Group & meshBodies ) override + void computeRegionStatistics( time, meshLevel, regionNames ) + void computeCFLNumbers( time, dt, domainPartition, m_relpermThreshold ) + void forRegionStatstics( functor ) +} +note bottom of CompositionalMultiphaseStatisticsAggregator + Generated sub-group for instanciating + RegionStatistics over the regions & + doing statistics computation. +end note +CompositionalMultiphaseStatisticsTask *---> CompositionalMultiphaseStatisticsAggregator : "contains one" +CompositionalMultiphaseWell *---> CompositionalMultiphaseStatisticsAggregator : "contains one" + +class RegionStatistics #text:Green { +} +note bottom of RegionStatistics + May be removed in favor of direct statistics +end note +CompositionalMultiphaseStatisticsAggregator ...> RegionStatistics : "instanciate\n&\ncomputes" +CompositionalMultiphaseStatisticsTask ..> RegionStatistics : "reads data\nfrom" +CompositionalMultiphaseWell ...> RegionStatistics : "reads data\nfrom" +CellElementRegion *-l--> RegionStatistics : "'regionStatistics' wrapper" + +class PressureStatistics #text:Green { + real64 averagePressure + real64 minPressure + real64 maxPressure + real64 minDeltaPressure + real64 maxDeltaPressure +} +RegionStatistics *--> PressureStatistics : "generated wrapper\n"pressure"" +PressureStatistics [PressureStatistics] --> RegionStatisticsType : "implements" + +class TemperatureStatistics #text:Green { + real64 averageTemperature + real64 minTemperature + real64 maxTemperature +} +RegionStatistics *--> TemperatureStatistics : "generated wrapper\n"temperature"" +TemperatureStatistics [TemperatureStatistics] --> RegionStatisticsType : "implements" + +class PoreVolumeStatistics #text:Green { + real64 totalPoreVolume + real64 totalUncompactedPoreVolume + array1d phasePoreVolume +} +RegionStatistics *--> PoreVolumeStatistics : "generated wrapper\n"poreVolume"" +PoreVolumeStatistics [PoreVolumeStatistics] --> RegionStatisticsType : "implements" + +class MassStatistics #text:Green { + array1d phaseMass + array1d trappedPhaseMass + array1d immobilePhaseMass + array2d componentMass +} +RegionStatistics *--> MassStatistics : "generated wrapper\n"mass"" +MassStatistics [MassStatistics] --> RegionStatisticsType : "implements" + +interface RegionStatisticsType < STATS_TYPE > #text:Green { + void init() + void setKernelViews( RegionStatisticsKernelViews< STATS_TYPE > & views ) + HOST_DEVICE void collectElementStats( RegionStatisticsKernelViews< STATS_TYPE > const & views ) + void kernelReduce() + void mpiReduce() +} + +class STATS_TYPE::KernelViews < STATS_TYPE > #text:Green { + ( structure of views necessary for collectElementStats() ) +} +RegionStatisticsType [STATS_TYPE] ..> STATS_TYPE::KernelViews \ No newline at end of file diff --git a/src/New4CompositionalMultiphaseStatist.plantuml b/src/New4CompositionalMultiphaseStatist.plantuml new file mode 100644 index 00000000000..8c64115b7a4 --- /dev/null +++ b/src/New4CompositionalMultiphaseStatist.plantuml @@ -0,0 +1,115 @@ + + +class Group #text:00000060 +class ExecutableGroup #text:00000060 +class TaskBase #text:00000060 +class FieldStatisticsBase #text:00000060 +class ObjectManagerBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class WellSolverBase #text:00000060 +class PhysicsSolverBase #text:00000060 + +class FieldStatisticsBase< SOLVER_T > #text:00000060 { + string m_solverName (user input : "solverName") + string m_outputDir (user input : "outputDir") + bool m_writeCSV (user input : "writeCSV") +} + +Group <|-- ExecutableGroup +ExecutableGroup <|-- TaskBase +TaskBase <|-- FieldStatisticsBase + +Group <|-- ObjectManagerBase +ObjectManagerBase <|-- ElementSubRegionBase +ElementSubRegionBase <|-- CellElementRegion + +WellSolverBase <|-- CompositionalMultiphaseWell +PhysicsSolverBase <|-- WellSolverBase +ExecutableGroup <|-- PhysicsSolverBase + +class CompositionalMultiphaseStatisticsTask #text:Green { + bool m_computeCFLNumbers (wrapper: "computeCFLNumbers") + bool m_computeRegionStatistics (wrapper: "computeRegionStatistics") + float m_relpermThreshold (wrapper: "relpermThreshold") + -- + void postInputInitialization() override + void execute( time_n, dt, [...], domain ) +} +note bottom of CompositionalMultiphaseStatisticsTask + User defined executable task for + statistics computation & output +end note +FieldStatisticsBase <|-- CompositionalMultiphaseStatisticsTask : SOLVER_T = CompositionalMultiphaseBase + +class CompositionalMultiphaseStatisticsAggregator #text:Green { + void registerDataOnMesh( Group & meshBodies ) override + void computeRegionStatistics( time, meshLevel, regionNames ) + void computeCFLNumbers( time, dt, domainPartition, m_relpermThreshold ) + void forRegionStatstics( functor ) +} +note bottom of CompositionalMultiphaseStatisticsAggregator + Generated sub-group for instanciating + RegionStatistics over the regions & + doing statistics computation. +end note +CompositionalMultiphaseStatisticsTask *---> CompositionalMultiphaseStatisticsAggregator : "contains one" +CompositionalMultiphaseWell *---> CompositionalMultiphaseStatisticsAggregator : "contains one" + +class RegionStatisticsData #text:Green { +} +note left of RegionStatisticsData + May be removed in favor of direct statistics +end note +CompositionalMultiphaseStatisticsAggregator ...> RegionStatisticsData : "instanciate\n&\ncomputes" +CompositionalMultiphaseStatisticsTask ..> RegionStatisticsData : "reads data\nfrom" +CompositionalMultiphaseWell ...> RegionStatisticsData : "reads data\nfrom" +CellElementRegion *-l--> RegionStatisticsData : "'regionStatistics' wrapper" + +class PressureStatistics #text:Green { + real64 averagePressure + real64 minPressure + real64 maxPressure + real64 minDeltaPressure + real64 maxDeltaPressure +} +RegionStatisticsData *--> PressureStatistics : "generated wrapper\n"pressure"" +PressureStatistics [PressureStatistics] --> RegionStatisticsType : "implements" + +class TemperatureStatistics #text:Green { + real64 averageTemperature + real64 minTemperature + real64 maxTemperature +} +RegionStatisticsData *--> TemperatureStatistics : "generated wrapper\n"temperature"" +TemperatureStatistics [TemperatureStatistics] --> RegionStatisticsType : "implements" + +class PoreVolumeStatistics #text:Green { + real64 totalPoreVolume + real64 totalUncompactedPoreVolume + array1d phasePoreVolume +} +RegionStatisticsData *--> PoreVolumeStatistics : "generated wrapper\n"poreVolume"" +PoreVolumeStatistics [PoreVolumeStatistics] --> RegionStatisticsType : "implements" + +class MassStatistics #text:Green { + array1d phaseMass + array1d trappedPhaseMass + array1d immobilePhaseMass + array2d componentMass +} +RegionStatisticsData *--> MassStatistics : "generated wrapper\n"mass"" +MassStatistics [MassStatistics] --> RegionStatisticsType : "implements" + +interface RegionStatisticsType < STATS_TYPE > #text:Green { + void init() + void setKernelViews( RegionStatisticsKernelViews< STATS_TYPE > & views ) + HOST_DEVICE void collectElementStats( RegionStatisticsKernelViews< STATS_TYPE > const & views ) + void kernelReduce() + void mpiReduce() +} + +class STATS_TYPE::KernelViews < STATS_TYPE > #text:Green { + ( structure of views necessary for collectElementStats() ) +} +RegionStatisticsType [STATS_TYPE] ..> STATS_TYPE::KernelViews \ No newline at end of file diff --git a/src/NewCompositionalMultiphaseStatist.plantuml b/src/NewCompositionalMultiphaseStatist.plantuml new file mode 100644 index 00000000000..782ff4b0263 --- /dev/null +++ b/src/NewCompositionalMultiphaseStatist.plantuml @@ -0,0 +1,119 @@ + + +class Group #text:00000060 +class ExecutableGroup #text:00000060 +class TaskBase #text:00000060 +class FieldStatisticsBase #text:00000060 +class ObjectManagerBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class ElementSubRegionBase #text:00000060 +class WellSolverBase #text:00000060 +class PhysicsSolverBase #text:00000060 + +class FieldStatisticsBase< SOLVER_T > #text:00000060 { + string m_solverName (user input : "solverName") + string m_outputDir (user input : "outputDir") + bool m_writeCSV (user input : "writeCSV") +} + +Group <|-- ExecutableGroup +ExecutableGroup <|-- TaskBase +TaskBase <|-- FieldStatisticsBase + +Group <|-- ObjectManagerBase +ObjectManagerBase <|-- ElementSubRegionBase +ElementSubRegionBase <|-- CellElementRegion + +WellSolverBase <|-- CompositionalMultiphaseWell +WellSolverBase <|-- SinglePhaseWell +PhysicsSolverBase <|-- WellSolverBase +ExecutableGroup <|-- PhysicsSolverBase + +class CompositionalMultiphaseStatistics { + m_computeCFLNumbers (user input: "computeCFLNumbers") + m_computeRegionStatistics (user input: "computeRegionStatistics") + m_relpermThreshold (user input: "relpermThreshold") + -- + void postInputInitialization() override + void registerDataOnMesh( Group & meshBodies ) override + + void computeRegionStatistics( time, meshLevel, regionNames ) + void computeCFLNumbers( time, dt, domainPartition ) +} +FieldStatisticsBase <|-- CompositionalMultiphaseStatistics : SOLVER_T = CompositionalMultiphaseBase + + +class RegionStatistics { + real64 dataTime + ---- + void computeRegionStatistics< STATS_TYPES... >() +} +RegionStatistics <..l.. CompositionalMultiphaseStatistics +CellElementRegion *--> RegionStatistics : "Generated Group\nregionStatistics" + +note right of RegionStatistics::dataTime + Added to keep track if stats has + been computed for the current time. + To be aware that stats are computer + after solver computation, "dataTime" + must be //timeStep + dt// (taking + into account the //dt// of cuts). +end note + + +class PressureStatistics #text:Green { + real64 averagePressure + real64 minPressure + real64 maxPressure + real64 minDeltaPressure + real64 maxDeltaPressure +} +RegionStatistics *--> PressureStatistics : "Lazily Generated Wrapper\npressure" +PressureStatistics [PressureStatistics] --> RegionStatisticsType : "implements" + +class TemperatureStatistics #text:Green { + real64 averageTemperature + real64 minTemperature + real64 maxTemperature +} +RegionStatistics *--> TemperatureStatistics : "Lazily Generated Wrapper\ntemperature" +TemperatureStatistics [TemperatureStatistics] --> RegionStatisticsType : "implements" + +class PoreVolumeStatistics #text:Green { + real64 totalPoreVolume + real64 totalUncompactedPoreVolume + array1d phasePoreVolume +} +RegionStatistics *--> PoreVolumeStatistics : "Lazily Generated Wrapper\nporeVolume" +PoreVolumeStatistics [PoreVolumeStatistics] --> RegionStatisticsType : "implements" + +class MassStatistics #text:Green { + array1d phaseMass + array1d trappedPhaseMass + array1d immobilePhaseMass + array2d componentMass +} +RegionStatistics *--> MassStatistics : "Lazily Generated Wrapper\nmass" +MassStatistics [MassStatistics] --> RegionStatisticsType : "implements" + +class CFLNumbers #text:Green { + array1d phaseMass + array1d trappedPhaseMass + array1d immobilePhaseMass + array2d componentMass +} +RegionStatistics *--> CFLNumbers : "Lazily Generated Wrapper\ncflNumbers" +CFLNumbers [CFLNumbers] --> RegionStatisticsType : "implements" + +interface RegionStatisticsType < STATS_TYPE > #text:Green { + void init() + void setKernelViews( RegionStatisticsKernelViews< STATS_TYPE > & views ) + HOST_DEVICE void collectElementStats( RegionStatisticsKernelViews< STATS_TYPE > const & views ) + void kernelReduce() + void mpiReduce() +} + +class STATS_TYPE::KernelViews < STATS_TYPE > #text:Green { + ( structure of views necessary for collectElementStats() ) +} +RegionStatisticsType [STATS_TYPE] ..> STATS_TYPE::KernelViews \ No newline at end of file diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index c2035bc2a1c..e73927a9b2d 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -57,6 +57,12 @@ class TableFormatter TableErrorListing & getErrorsList() const { return *m_errors; } + /** + * @return The prepared table layout + */ + PreparedTableLayout const & getLayout() const + { return m_tableLayout; } + protected: /// Layout for a table diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 7e6a227ee02..be3c45259ac 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -22,7 +22,8 @@ set( fluidFlowSolvers_headers FlowSolverBaseFields.hpp CompositionalMultiphaseBase.hpp CompositionalMultiphaseBaseFields.hpp - CompositionalMultiphaseStatistics.hpp + CompositionalMultiphaseStatisticsAggregator.hpp + CompositionalMultiphaseStatisticsTask.hpp CompositionalMultiphaseFVM.hpp CompositionalMultiphaseHybridFVM.hpp CompositionalMultiphaseUtilities.hpp @@ -129,7 +130,8 @@ set( fluidFlowSolvers_headers set( fluidFlowSolvers_sources CompositionalMultiphaseBase.cpp CompositionalMultiphaseFVM.cpp - CompositionalMultiphaseStatistics.cpp + CompositionalMultiphaseStatisticsAggregator.cpp + CompositionalMultiphaseStatisticsTask.cpp CompositionalMultiphaseHybridFVM.cpp ImmiscibleMultiphaseFlow.cpp ReactiveCompositionalMultiphaseOBL.cpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp deleted file mode 100644 index ab798921033..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ /dev/null @@ -1,556 +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 CompositionalMultiphaseStatistics.cpp - */ - -#include "CompositionalMultiphaseStatistics.hpp" - -#include "mesh/DomainPartition.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "physicsSolvers/LogLevelsInfo.hpp" -#include "physicsSolvers/fluidFlow/LogLevelsInfo.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" -#include "common/format/table/TableData.hpp" -#include "common/format/table/TableFormatter.hpp" -#include "common/format/table/TableLayout.hpp" - - -namespace geos -{ - -using namespace constitutive; -using namespace fields; -using namespace dataRepository; - -CompositionalMultiphaseStatistics::CompositionalMultiphaseStatistics( const string & name, - Group * const parent ): - Base( name, parent ), - m_computeCFLNumbers( 0 ), - m_computeRegionStatistics( 1 ) -{ - registerWrapper( viewKeyStruct::computeCFLNumbersString(), &m_computeCFLNumbers ). - setApplyDefaultValue( 0 ). - setInputFlag( InputFlags::OPTIONAL ). - setDescription( "Flag to decide whether CFL numbers are computed or not" ); - - registerWrapper( viewKeyStruct::computeRegionStatisticsString(), &m_computeRegionStatistics ). - setApplyDefaultValue( 1 ). - setInputFlag( InputFlags::OPTIONAL ). - setDescription( "Flag to decide whether region statistics are computed or not" ); - - registerWrapper( viewKeyStruct::relpermThresholdString(), &m_relpermThreshold ). - setApplyDefaultValue( 1e-6 ). - setInputFlag( InputFlags::OPTIONAL ). - setDescription( "Flag to decide whether a phase is considered mobile (when the relperm is above the threshold) or immobile (when the relperm is below the threshold) in metric 2" ); - - addLogLevel< logInfo::CFL >(); - addLogLevel< logInfo::Statistics >(); -} - -void CompositionalMultiphaseStatistics::postInputInitialization() -{ - Base::postInputInitialization(); - - if( dynamicCast< CompositionalMultiphaseHybridFVM * >( m_solver ) && m_computeCFLNumbers != 0 ) - { - GEOS_THROW( GEOS_FMT( "{} {}: the option to compute CFL numbers is incompatible with CompositionalMultiphaseHybridFVM", - catalogName(), getDataContext() ), - InputError ); - } -} - -void CompositionalMultiphaseStatistics::registerDataOnMesh( Group & meshBodies ) -{ - // the fields have to be registered in "registerDataOnMesh" (and not later) - // otherwise they cannot be targeted by TimeHistory - - // for now, this guard is needed to avoid breaking the xml schema generation - if( m_solver == nullptr ) - { - return; - } - - m_solver->forDiscretizationOnMeshTargets( meshBodies, [&] ( string const &, - MeshLevel & mesh, - string_array const & regionNames ) - { - ElementRegionManager & elemManager = mesh.getElemManager(); - - integer const numPhases = m_solver->numFluidPhases(); - integer const numComps = m_solver->numFluidComponents(); - - // if we have to report region statistics, we have to register them first here - if( m_computeRegionStatistics ) - { - for( size_t i = 0; i < regionNames.size(); ++i ) - { - ElementRegionBase & region = elemManager.getRegion( regionNames[i] ); - - region.registerWrapper< RegionStatistics >( viewKeyStruct::regionStatisticsString() ). - setRestartFlags( RestartFlags::NO_WRITE ); - region.excludeWrappersFromPacking( { viewKeyStruct::regionStatisticsString() } ); - RegionStatistics & stats = region.getReference< RegionStatistics >( viewKeyStruct::regionStatisticsString() ); - - stats.phasePoreVolume.resizeDimension< 0 >( numPhases ); - stats.phaseMass.resizeDimension< 0 >( numPhases ); - stats.trappedPhaseMass.resizeDimension< 0 >( numPhases ); - stats.immobilePhaseMass.resizeDimension< 0 >( numPhases ); - stats.componentMass.resizeDimension< 0, 1 >( numPhases, numComps ); - - if( m_writeCSV > 0 && MpiWrapper::commRank() == 0 ) - { - auto addStatsValue = []( std::ostringstream & pstatsLayout, TableLayout & ptableLayout, - string const & description, string_view punit, - integer pnumPhases, integer pnumComps = 0 ) - { - for( int ip = 0; ip < pnumPhases; ++ip ) - { - if( pnumComps == 0 ) - { - pstatsLayout << description << " (phase " << ip << ") [" << punit << "]"; - } - else - { - for( int ic = 0; ic < pnumComps; ++ic ) - { - pstatsLayout << description << " (component " << ic << " / phase " << ip << ") [" << punit << "]"; - if( ic == 0 ) - { - pstatsLayout << ","; - } - } - } - if( ip == 0 ) - { - pstatsLayout << ","; - } - } - - ptableLayout.addColumn( pstatsLayout.str()); - pstatsLayout.str( "" ); - }; - - string_view massUnit = units::getSymbol( m_solver->getMassUnit() ); - - TableLayout tableLayout( { - TableLayout::Column().setName( GEOS_FMT( "Time [{}]", units::getSymbol( units::Unit::Time ))), - TableLayout::Column().setName( GEOS_FMT( "Min pressure [{}]", units::getSymbol( units::Unit::Pressure ))), - TableLayout::Column().setName( GEOS_FMT( "Average pressure [{}]", units::getSymbol( units::Unit::Pressure )) ), - TableLayout::Column().setName( GEOS_FMT( "Max pressure [{}]", units::getSymbol( units::Unit::Pressure ) ) ), - TableLayout::Column().setName( GEOS_FMT( "Min delta pressure [{}]", units::getSymbol( units::Unit::Pressure ))), - TableLayout::Column().setName( GEOS_FMT( "Max delta pressure [{}]", units::getSymbol( units::Unit::Pressure ))), - TableLayout::Column().setName( GEOS_FMT( "Min temperature [{}]", units::getSymbol( units::Unit::Temperature ) )), - TableLayout::Column().setName( GEOS_FMT( "Average temperature [{}]", units::getSymbol( units::Unit::Temperature ) )), - TableLayout::Column().setName( GEOS_FMT( "Max temperature [{}]", units::getSymbol( units::Unit::Temperature ) )), - TableLayout::Column().setName( GEOS_FMT( "Total dynamic pore volume [{}]", units::getSymbol( units::Unit::ReservoirVolume ) )), - } ); - - std::ostringstream statsLayout; - addStatsValue( statsLayout, tableLayout, "Phase dynamic pore volume", "rm^3", numPhases ); - addStatsValue( statsLayout, tableLayout, "Phase mass", massUnit, numPhases ); - addStatsValue( statsLayout, tableLayout, "Trapped phase mass (metric 1)", massUnit, numPhases ); - addStatsValue( statsLayout, tableLayout, "Non-trapped phase mass (metric 1)", massUnit, numPhases ); - addStatsValue( statsLayout, tableLayout, "Immobile phase mass (metric 2)", massUnit, numPhases ); - addStatsValue( statsLayout, tableLayout, "Mobile phase mass (metric 2)", massUnit, numPhases ); - addStatsValue( statsLayout, tableLayout, "Component mass", massUnit, numPhases, numComps ); - - std::ofstream outputFile( m_outputDir + "/" + regionNames[i] + ".csv" ); - TableCSVFormatter csvFormatter( tableLayout ); - outputFile << csvFormatter.headerToString(); - } - } - } - } ); - - // if we have to compute CFL numbers later, we need to register additional variables - if( m_computeCFLNumbers ) - { - m_solver->registerDataForCFL( meshBodies ); - } -} - -bool CompositionalMultiphaseStatistics::execute( real64 const time_n, - real64 const dt, - integer const GEOS_UNUSED_PARAM( cycleNumber ), - integer const GEOS_UNUSED_PARAM( eventCounter ), - real64 const GEOS_UNUSED_PARAM( eventProgress ), - DomainPartition & domain ) -{ - m_solver->forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, - MeshLevel & mesh, - string_array const & regionNames ) - { - if( m_computeRegionStatistics ) - { - // current time is time_n + dt - computeRegionStatistics( time_n + dt, mesh, regionNames ); - } - } ); - - if( m_computeCFLNumbers ) - { - // current time is time_n + dt - computeCFLNumbers( time_n + dt, dt, domain ); - } - - return false; -} - -void CompositionalMultiphaseStatistics::computeRegionStatistics( real64 const time, - MeshLevel & mesh, - string_array const & regionNames ) const -{ - GEOS_MARK_FUNCTION; - - integer const numPhases = m_solver->numFluidPhases(); - integer const numComps = m_solver->numFluidComponents(); - - // Step 1: initialize the average/min/max quantities - ElementRegionManager & elemManager = mesh.getElemManager(); - for( size_t i = 0; i < regionNames.size(); ++i ) - { - ElementRegionBase & region = elemManager.getRegion( regionNames[i] ); - RegionStatistics & stats = region.getReference< RegionStatistics >( viewKeyStruct::regionStatisticsString() ); - - stats.averagePressure = 0.0; - stats.maxPressure = 0.0; - stats.minPressure = LvArray::NumericLimits< real64 >::max; - - stats.maxDeltaPressure = -LvArray::NumericLimits< real64 >::max; - stats.minDeltaPressure = LvArray::NumericLimits< real64 >::max; - - stats.averageTemperature = 0.0; - stats.maxTemperature = 0.0; - stats.minTemperature = LvArray::NumericLimits< real64 >::max; - - stats.totalPoreVolume = 0.0; - stats.totalUncompactedPoreVolume = 0.0; - stats.phasePoreVolume.setValues< serialPolicy >( 0.0 ); - - stats.phaseMass.setValues< serialPolicy >( 0.0 ); - stats.trappedPhaseMass.setValues< serialPolicy >( 0.0 ); - stats.immobilePhaseMass.setValues< serialPolicy >( 0.0 ); - stats.componentMass.setValues< serialPolicy >( 0.0 ); - } - - // Step 2: increment the average/min/max quantities for all the subRegions - elemManager.forElementSubRegions( regionNames, [&]( localIndex const, - ElementSubRegionBase & subRegion ) - { - - arrayView1d< integer const > const elemGhostRank = subRegion.ghostRank(); - arrayView1d< real64 const > const volume = subRegion.getElementVolume(); - arrayView1d< real64 const > const pres = subRegion.getField< flow::pressure >(); - arrayView1d< real64 const > const temp = subRegion.getField< flow::temperature >(); - arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = - subRegion.getField< flow::phaseVolumeFraction >(); - arrayView1d< real64 const > const deltaPres = subRegion.getField< flow::deltaPressure >(); - - Group const & constitutiveModels = subRegion.getGroup( ElementSubRegionBase::groupKeyStruct::constitutiveModelsString() ); - - string const & solidName = subRegion.getReference< string >( CompositionalMultiphaseBase::viewKeyStruct::solidNamesString() ); - CoupledSolidBase const & solid = constitutiveModels.getGroup< CoupledSolidBase >( solidName ); - arrayView1d< real64 const > const refPorosity = solid.getReferencePorosity(); - arrayView2d< real64 const > const porosity = solid.getPorosity(); - - string const & fluidName = subRegion.getReference< string >( CompositionalMultiphaseBase::viewKeyStruct::fluidNamesString() ); - MultiFluidBase const & fluid = constitutiveModels.getGroup< MultiFluidBase >( fluidName ); - arrayView3d< real64 const, multifluid::USD_PHASE > const phaseDensity = fluid.phaseDensity(); - arrayView4d< real64 const, multifluid::USD_PHASE_COMP > const phaseCompFraction = fluid.phaseCompFraction(); - - - //get min vol fraction for each phase to dispactche immobile/mobile mass - string const & relpermName = subRegion.getReference< string >( CompositionalMultiphaseBase::viewKeyStruct::relPermNamesString() ); - RelativePermeabilityBase const & relperm = constitutiveModels.getGroup< RelativePermeabilityBase >( relpermName ); - arrayView3d< real64 const, relperm::USD_RELPERM > const phaseTrappedVolFrac = relperm.phaseTrappedVolFraction(); - arrayView3d< real64 const, relperm::USD_RELPERM > const phaseRelperm = relperm.phaseRelPerm(); - - real64 subRegionAvgPresNumerator = 0.0; - real64 subRegionMinPres = 0.0; - real64 subRegionMaxPres = 0.0; - real64 subRegionMinDeltaPres = 0.0; - real64 subRegionMaxDeltaPres = 0.0; - real64 subRegionAvgTempNumerator = 0.0; - real64 subRegionMinTemp = 0.0; - real64 subRegionMaxTemp = 0.0; - real64 subRegionTotalUncompactedPoreVol = 0.0; - array1d< real64 > subRegionPhaseDynamicPoreVol( numPhases ); - array1d< real64 > subRegionPhaseMass( numPhases ); - array1d< real64 > subRegionTrappedPhaseMass( numPhases ); - array1d< real64 > subRegionImmobilePhaseMass( numPhases ); - array1d< real64 > subRegionRelpermPhaseMass( numPhases ); - array2d< real64 > subRegionComponentMass( numPhases, numComps ); - - isothermalCompositionalMultiphaseBaseKernels:: - StatisticsKernel:: - launch< parallelDevicePolicy<> >( subRegion.size(), - numComps, - numPhases, - m_relpermThreshold, - elemGhostRank, - volume, - pres, - deltaPres, - temp, - refPorosity, - porosity, - phaseDensity, - phaseCompFraction, - phaseVolFrac, - phaseTrappedVolFrac, - phaseRelperm, - subRegionMinPres, - subRegionAvgPresNumerator, - subRegionMaxPres, - subRegionMinDeltaPres, - subRegionMaxDeltaPres, - subRegionMinTemp, - subRegionAvgTempNumerator, - subRegionMaxTemp, - subRegionTotalUncompactedPoreVol, - subRegionPhaseDynamicPoreVol.toView(), - subRegionPhaseMass.toView(), - subRegionTrappedPhaseMass.toView(), - subRegionImmobilePhaseMass.toView(), - subRegionComponentMass.toView() ); - - ElementRegionBase & region = elemManager.getRegion( ElementRegionBase::getParentRegion( subRegion ).getName() ); - RegionStatistics & stats = region.getReference< RegionStatistics >( viewKeyStruct::regionStatisticsString() ); - - stats.averagePressure += subRegionAvgPresNumerator; - if( subRegionMinPres < stats.minPressure ) - { - stats.minPressure = subRegionMinPres; - } - if( subRegionMaxPres > stats.maxPressure ) - { - stats.maxPressure = subRegionMaxPres; - } - - if( subRegionMinDeltaPres < stats.minDeltaPressure ) - { - stats.minDeltaPressure = subRegionMinDeltaPres; - } - if( subRegionMaxDeltaPres > stats.maxDeltaPressure ) - { - stats.maxDeltaPressure = subRegionMaxDeltaPres; - } - - stats.averageTemperature += subRegionAvgTempNumerator; - if( subRegionMinTemp < stats.minTemperature ) - { - stats.minTemperature = subRegionMinTemp; - } - if( subRegionMaxTemp > stats.maxTemperature ) - { - stats.maxTemperature = subRegionMaxTemp; - } - - stats.totalUncompactedPoreVolume += subRegionTotalUncompactedPoreVol; - for( integer ip = 0; ip < numPhases; ++ip ) - { - stats.phasePoreVolume[ip] += subRegionPhaseDynamicPoreVol[ip]; - stats.phaseMass[ip] += subRegionPhaseMass[ip]; - stats.trappedPhaseMass[ip] += subRegionTrappedPhaseMass[ip]; - stats.immobilePhaseMass[ip] += subRegionImmobilePhaseMass[ip]; - - for( integer ic = 0; ic < numComps; ++ic ) - { - stats.componentMass[ip][ic] += subRegionComponentMass[ip][ic]; - } - } - - } ); - - // Step 3: synchronize the results over the MPI ranks - for( size_t i = 0; i < regionNames.size(); ++i ) - { - ElementRegionBase & region = elemManager.getRegion( regionNames[i] ); - RegionStatistics & stats = region.getReference< RegionStatistics >( viewKeyStruct::regionStatisticsString() ); - - stats.minPressure = MpiWrapper::min( stats.minPressure ); - stats.maxPressure = MpiWrapper::max( stats.maxPressure ); - stats.minDeltaPressure = MpiWrapper::min( stats.minDeltaPressure ); - stats.maxDeltaPressure = MpiWrapper::max( stats.maxDeltaPressure ); - stats.minTemperature = MpiWrapper::min( stats.minTemperature ); - stats.maxTemperature = MpiWrapper::max( stats.maxTemperature ); - stats.totalUncompactedPoreVolume = MpiWrapper::sum( stats.totalUncompactedPoreVolume ); - stats.totalPoreVolume = 0.0; - for( integer ip = 0; ip < numPhases; ++ip ) - { - stats.phasePoreVolume[ip] = MpiWrapper::sum( stats.phasePoreVolume[ip] ); - stats.phaseMass[ip] = MpiWrapper::sum( stats.phaseMass[ip] ); - stats.trappedPhaseMass[ip] = MpiWrapper::sum( stats.trappedPhaseMass[ip] ); - stats.immobilePhaseMass[ip] = MpiWrapper::sum( stats.immobilePhaseMass[ip] ); - stats.totalPoreVolume += stats.phasePoreVolume[ip]; - for( integer ic = 0; ic < numComps; ++ic ) - { - stats.componentMass[ip][ic] = MpiWrapper::sum( stats.componentMass[ip][ic] ); - } - } - stats.averagePressure = MpiWrapper::sum( stats.averagePressure ); - stats.averageTemperature = MpiWrapper::sum( stats.averageTemperature ); - if( stats.totalUncompactedPoreVolume > 0 ) - { - float invTotalUncompactedPoreVolume = 1.0 / stats.totalUncompactedPoreVolume; - stats.averagePressure *= invTotalUncompactedPoreVolume; - stats.averageTemperature *= invTotalUncompactedPoreVolume; - } - else - { - stats.averagePressure = 0.0; - stats.averageTemperature = 0.0; - GEOS_LOG_LEVEL_RANK_0( logInfo::Statistics, - GEOS_FMT( "{}, {}: Cannot compute average pressure because region pore volume is zero.", - getName(), regionNames[i] ) ); - } - - - // helpers to report statistics - array1d< real64 > nonTrappedPhaseMass( numPhases ); - array1d< real64 > mobilePhaseMass( numPhases ); - for( integer ip = 0; ip < numPhases; ++ip ) - { - nonTrappedPhaseMass[ip] = stats.phaseMass[ip] - stats.trappedPhaseMass[ip]; - mobilePhaseMass[ip] = stats.phaseMass[ip] - stats.immobilePhaseMass[ip]; - } - - string_view massUnit = units::getSymbol( m_solver->getMassUnit() ); - - stdVector< string > phaseCompName; - phaseCompName.reserve( numPhases*numComps ); - stdVector< string > massValues; - phaseCompName.reserve( numPhases*numComps ); - - ConstitutiveManager const & constitutiveManager = this->getGroupByPath< ConstitutiveManager >( "/Problem/domain/Constitutive" ); - MultiFluidBase const & fluid = constitutiveManager.getGroup< MultiFluidBase >( m_solver->referenceFluidModelName() ); - auto const phaseNames = fluid.phaseNames(); - auto const componentNames = fluid.componentNames(); - for( integer ip = 0; ip < numPhases; ++ip ) - { - for( integer ic = 0; ic < numComps; ++ic ) - { - std::stringstream ss; - ss << phaseNames[ip] << "/" << componentNames[ic]; - phaseCompName.push_back( ss.str() ); - massValues.push_back( GEOS_FMT( "{}", stats.componentMass[ip][ic] ) ); - } - } - - if( isLogLevelActive< logInfo::Statistics >( this->getLogLevel() ) && MpiWrapper::commRank() == 0 ) - { - TableData compPhaseStatsData; - compPhaseStatsData.addRow( "Pressure [Pa]", stats.minPressure, stats.averagePressure, stats.maxPressure ); - compPhaseStatsData.addRow( "Delta pressure [Pa]", stats.minDeltaPressure, "/", stats.maxDeltaPressure ); - compPhaseStatsData.addRow( "Temperature [K]", stats.minTemperature, stats.averageTemperature, stats.maxTemperature ); - compPhaseStatsData.addSeparator(); - - compPhaseStatsData.addRow( "Total dynamic pore volume [rm^3]", CellType::MergeNext, CellType::MergeNext, stats.totalPoreVolume ); - compPhaseStatsData.addSeparator(); - compPhaseStatsData.addRow( "Phase dynamic pore volume [rm^3]", - stringutilities::joinLambda( phaseNames, "\n", []( auto data ) { return data[0]; } ), - CellType::MergeNext, - stringutilities::joinLambda( stats.phasePoreVolume, "\n", []( auto data ) { return data[0]; } ) ); - compPhaseStatsData.addSeparator(); - - compPhaseStatsData.addRow( GEOS_FMT( "Phase mass [{}]", massUnit ), - stringutilities::joinLambda( phaseNames, "\n", []( auto data ) { return data[0]; } ), - CellType::MergeNext, - stringutilities::joinLambda( stats.phaseMass, "\n", []( auto data ) { return data[0]; } ) ); - compPhaseStatsData.addSeparator(); - - compPhaseStatsData.addRow( GEOS_FMT( "Trapped phase mass (metric 1) [{}]", massUnit ), - stringutilities::joinLambda( phaseNames, "\n", []( auto value ) { return value[0]; } ), - CellType::MergeNext, - stringutilities::joinLambda( stats.trappedPhaseMass, "\n", []( auto value ) { return value[0]; } ) ); - compPhaseStatsData.addSeparator(); - compPhaseStatsData.addRow( GEOS_FMT( "Non-trapped phase mass (metric 1) [{}]", massUnit ), - stringutilities::joinLambda( phaseNames, "\n", []( auto value ) { return value[0]; } ), - CellType::MergeNext, - stringutilities::joinLambda( nonTrappedPhaseMass, "\n", []( auto value ) { return value[0]; } ) ); - compPhaseStatsData.addSeparator(); - - compPhaseStatsData.addRow( GEOS_FMT( "Immobile phase mass (metric 2) [{}]", massUnit ), - stringutilities::joinLambda( phaseNames, "\n", []( auto value ) { return value[0]; } ), - CellType::MergeNext, - stringutilities::joinLambda( stats.immobilePhaseMass, "\n", []( auto value ) { return value[0]; } ) ); - compPhaseStatsData.addSeparator(); - compPhaseStatsData.addRow( GEOS_FMT( "Mobile phase mass (metric 2) [{}]", massUnit ), - stringutilities::joinLambda( phaseNames, "\n", []( auto value ) { return value[0]; } ), - CellType::MergeNext, - stringutilities::joinLambda( mobilePhaseMass, "\n", []( auto value ) { return value[0]; } ) ); - compPhaseStatsData.addSeparator(); - - compPhaseStatsData.addRow( GEOS_FMT( "Component mass [{}]", massUnit ), - stringutilities::join( phaseCompName, '\n' ), - CellType::MergeNext, - stringutilities::join( massValues, '\n' ) ); - - string const title = GEOS_FMT( "{}, {} (time {} s):", getName(), regionNames[i], time ); - TableLayout const compPhaseStatsLayout( title, { "statistics", "min", "average", "max" } ); - TableTextFormatter tableFormatter( compPhaseStatsLayout ); - GEOS_LOG_RANK_0( tableFormatter.toString( compPhaseStatsData ) ); - } - - if( m_writeCSV > 0 && MpiWrapper::commRank() == 0 ) - { - TableData tableData; - tableData.addRow( time, stats.minPressure, stats.averagePressure, stats.maxPressure, stats.minDeltaPressure, stats.maxDeltaPressure, - stats.minTemperature, stats.averageTemperature, stats.maxTemperature, stats.totalPoreVolume, - stringutilities::joinLambda( stats.phasePoreVolume, "\n", []( auto data ) { return data[0]; } ), - stringutilities::joinLambda( stats.phaseMass, "\n", []( auto data ) { return data[0]; } ), - stringutilities::joinLambda( stats.trappedPhaseMass, "\n", []( auto value ) { return value[0]; } ), - stringutilities::joinLambda( nonTrappedPhaseMass, "\n", []( auto value ) { return value[0]; } ), - stringutilities::joinLambda( stats.immobilePhaseMass, "\n", []( auto value ) { return value[0]; } ), - stringutilities::joinLambda( mobilePhaseMass, "\n", []( auto value ) { return value[0]; } ), - stringutilities::join( massValues, '\n' ) ); - - std::ofstream outputFile( m_outputDir + "/" + regionNames[i] + ".csv", std::ios_base::app ); - TableCSVFormatter const csvOutput; - outputFile << csvOutput.dataToString( tableData ); - outputFile.close(); - } - } - -} - -void CompositionalMultiphaseStatistics::computeCFLNumbers( real64 const time, - real64 const dt, - DomainPartition & domain ) const -{ - GEOS_MARK_FUNCTION; - real64 maxPhaseCFL, maxCompCFL; - m_solver->computeCFLNumbers( domain, dt, maxPhaseCFL, maxCompCFL ); - - GEOS_LOG_LEVEL_RANK_0( logInfo::CFL, - GEOS_FMT( "{} (time {} s): Max phase CFL number: {}", getName(), time, maxPhaseCFL ) ); - GEOS_LOG_LEVEL_RANK_0( logInfo::CFL, - GEOS_FMT( "{} (time {} s): Max component CFL number: {}", getName(), time, maxCompCFL ) ); -} - - -REGISTER_CATALOG_ENTRY( TaskBase, - CompositionalMultiphaseStatistics, - string const &, dataRepository::Group * const ) - -} /* namespace geos */ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.cpp new file mode 100644 index 00000000000..c2a923a4b0f --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.cpp @@ -0,0 +1,367 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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 CompositionalMultiphaseStatistics.cpp + */ + +#include "CompositionalMultiphaseStatisticsAggregator.hpp" + +#include "common/DataTypes.hpp" +#include "common/format/Format.hpp" +#include "common/logger/Logger.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" +#include "physicsSolvers/LogLevelsInfo.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include + + +namespace geos +{ + +namespace compositionalMultiphaseStatistics +{ + +using namespace constitutive; +// using namespace fields; +using namespace dataRepository; + +StatsAggregator::StatsAggregator(): + m_params(), + m_isRegionStatsEnabled( false ), + m_isCFLNumberEnabled( false ) +{} + +void StatsAggregator::enableRegionStatistics( dataRepository::Group & /*meshBodies*/ ) +{ + GEOS_ERROR_IF_EQ_MSG( m_solver, nullptr, "Flow solver must be set." ); + + // integer const numPhases = m_solver->numFluidPhases(); + // integer const numComps = m_solver->numFluidComponents(); + + // m_solver->forDiscretizationOnMeshTargets( meshBodies, [&] ( string const &, + // MeshLevel & mesh, + // string_array const & regionNames ) + // { + // ElementRegionManager & elemManager = mesh.getElemManager(); + + // for( size_t i = 0; i < regionNames.size(); ++i ) + // { + // // ElementRegionBase & region = elemManager.getRegion( regionNames[i] ); + + // // RELOCALISER LES DONNEES region.registerWrapper< RegionStatistics >( VKStruct::regionStatisticsString() ). + // // setRestartFlags( RestartFlags::NO_WRITE ); + // // region.excludeWrappersFromPacking( { VKStruct::regionStatisticsString() } ); + // // RegionStatistics & stats = region.getReference< RegionStatistics >( VKStruct::regionStatisticsString() ); + + // // stats.m_phasePoreVolume.resizeDimension< 0 >( numPhases ); + // // stats.m_phaseMass.resizeDimension< 0 >( numPhases ); + // // stats.m_trappedPhaseMass.resizeDimension< 0 >( numPhases ); + // // stats.m_nonTrappedPhaseMass.resizeDimension< 0 >( numPhases ); + // // stats.m_immobilePhaseMass.resizeDimension< 0 >( numPhases ); + // // stats.m_mobilePhaseMass.resizeDimension< 0 >( numPhases ); + // // stats.m_componentMass.resizeDimension< 0, 1 >( numPhases, numComps ); + // } + // } ); + // m_isRegionStatsEnabled = true; +} + +void StatsAggregator::forRegionStatistics( MeshLevel const & mesh, + StatsAggregator::RegionFunctor functor ) const +{ + GEOS_UNUSED_VAR( mesh ); + GEOS_UNUSED_VAR( functor ); +} + +void StatsAggregator::enableCFLStatistics( dataRepository::Group & meshBodies ) +{ + GEOS_ERROR_IF_EQ_MSG( m_solver, nullptr, "Flow solver must be set." ); + + m_solver->registerDataForCFL( meshBodies ); + m_isCFLNumberEnabled = true; +} + +bool StatsAggregator::computeRegionsStatistics( real64 const time, + MeshLevel & mesh, + string_array const & regionNames ) +{ + GEOS_MARK_FUNCTION; + + integer const numPhases = m_solver->numFluidPhases(); + integer const numComps = m_solver->numFluidComponents(); + + // Step 1: initialize the average/min/max quantities + ElementRegionManager & elemManager = mesh.getElemManager(); + for( size_t i = 0; i < regionNames.size(); ++i ) + { + ElementRegionBase & region = elemManager.getRegion( regionNames[i] ); + RegionStatistics & stats = region.getReference< RegionStatistics >( VKStruct::regionStatisticsString() ); + + stats.m_time = time; + + stats.m_averagePressure = 0.0; + stats.m_maxPressure = 0.0; + stats.m_minPressure = LvArray::NumericLimits< real64 >::max; + + stats.m_maxDeltaPressure = -LvArray::NumericLimits< real64 >::max; + stats.m_minDeltaPressure = LvArray::NumericLimits< real64 >::max; + + stats.m_averageTemperature = 0.0; + stats.m_maxTemperature = 0.0; + stats.m_minTemperature = LvArray::NumericLimits< real64 >::max; + + stats.m_totalPoreVolume = 0.0; + stats.m_totalUncompactedPoreVolume = 0.0; + stats.m_phasePoreVolume.setValues< serialPolicy >( 0.0 ); + + stats.m_phaseMass.setValues< serialPolicy >( 0.0 ); + stats.m_trappedPhaseMass.setValues< serialPolicy >( 0.0 ); + stats.m_nonTrappedPhaseMass.setValues< serialPolicy >( 0.0 ); + stats.m_immobilePhaseMass.setValues< serialPolicy >( 0.0 ); + stats.m_mobilePhaseMass.setValues< serialPolicy >( 0.0 ); + stats.m_componentMass.setValues< serialPolicy >( 0.0 ); + } + + // Step 2: increment the average/min/max quantities for all the subRegions + elemManager.forElementSubRegions( regionNames, [&]( localIndex const, + ElementSubRegionBase & subRegion ) + { + + arrayView1d< integer const > const elemGhostRank = subRegion.ghostRank(); + arrayView1d< real64 const > const volume = subRegion.getElementVolume(); + arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); + arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = + subRegion.getField< fields::flow::phaseVolumeFraction >(); + arrayView1d< real64 const > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); + + Group const & constitutiveModels = subRegion.getGroup( ElementSubRegionBase::groupKeyStruct::constitutiveModelsString() ); + + string const & solidName = subRegion.getReference< string >( CompositionalMultiphaseBase::viewKeyStruct::solidNamesString() ); + CoupledSolidBase const & solid = constitutiveModels.getGroup< CoupledSolidBase >( solidName ); + arrayView1d< real64 const > const refPorosity = solid.getReferencePorosity(); + arrayView2d< real64 const > const porosity = solid.getPorosity(); + + string const & fluidName = subRegion.getReference< string >( CompositionalMultiphaseBase::viewKeyStruct::fluidNamesString() ); + MultiFluidBase const & fluid = constitutiveModels.getGroup< MultiFluidBase >( fluidName ); + arrayView3d< real64 const, multifluid::USD_PHASE > const phaseDensity = fluid.phaseDensity(); + arrayView4d< real64 const, multifluid::USD_PHASE_COMP > const phaseCompFraction = fluid.phaseCompFraction(); + + + //get min vol fraction for each phase to dispactche immobile/mobile mass + string const & relpermName = subRegion.getReference< string >( CompositionalMultiphaseBase::viewKeyStruct::relPermNamesString() ); + RelativePermeabilityBase const & relperm = constitutiveModels.getGroup< RelativePermeabilityBase >( relpermName ); + arrayView3d< real64 const, relperm::USD_RELPERM > const phaseTrappedVolFrac = relperm.phaseTrappedVolFraction(); + arrayView3d< real64 const, relperm::USD_RELPERM > const phaseRelperm = relperm.phaseRelPerm(); + + real64 subRegionAvgPresNumerator = 0.0; + real64 subRegionMinPres = 0.0; + real64 subRegionMaxPres = 0.0; + real64 subRegionMinDeltaPres = 0.0; + real64 subRegionMaxDeltaPres = 0.0; + real64 subRegionAvgTempNumerator = 0.0; + real64 subRegionMinTemp = 0.0; + real64 subRegionMaxTemp = 0.0; + real64 subRegionTotalUncompactedPoreVol = 0.0; + array1d< real64 > subRegionPhaseDynamicPoreVol( numPhases ); + array1d< real64 > subRegionPhaseMass( numPhases ); + array1d< real64 > subRegionTrappedPhaseMass( numPhases ); + array1d< real64 > subRegionImmobilePhaseMass( numPhases ); + array1d< real64 > subRegionRelpermPhaseMass( numPhases ); + array2d< real64 > subRegionComponentMass( numPhases, numComps ); + + isothermalCompositionalMultiphaseBaseKernels:: + StatisticsKernel:: + launch< parallelDevicePolicy<> >( subRegion.size(), + numComps, + numPhases, + m_params.m_relpermThreshold, + elemGhostRank, + volume, + pres, + deltaPres, + temp, + refPorosity, + porosity, + phaseDensity, + phaseCompFraction, + phaseVolFrac, + phaseTrappedVolFrac, + phaseRelperm, + subRegionMinPres, + subRegionAvgPresNumerator, + subRegionMaxPres, + subRegionMinDeltaPres, + subRegionMaxDeltaPres, + subRegionMinTemp, + subRegionAvgTempNumerator, + subRegionMaxTemp, + subRegionTotalUncompactedPoreVol, + subRegionPhaseDynamicPoreVol.toView(), + subRegionPhaseMass.toView(), + subRegionTrappedPhaseMass.toView(), + subRegionImmobilePhaseMass.toView(), + subRegionComponentMass.toView() ); + + ElementRegionBase & region = elemManager.getRegion( ElementRegionBase::getParentRegion( subRegion ).getName() ); + RegionStatistics & stats = region.getReference< RegionStatistics >( VKStruct::regionStatisticsString() ); + + stats.m_averagePressure += subRegionAvgPresNumerator; + if( subRegionMinPres < stats.m_minPressure ) + { + stats.m_minPressure = subRegionMinPres; + } + if( subRegionMaxPres > stats.m_maxPressure ) + { + stats.m_maxPressure = subRegionMaxPres; + } + + if( subRegionMinDeltaPres < stats.m_minDeltaPressure ) + { + stats.m_minDeltaPressure = subRegionMinDeltaPres; + } + if( subRegionMaxDeltaPres > stats.m_maxDeltaPressure ) + { + stats.m_maxDeltaPressure = subRegionMaxDeltaPres; + } + + stats.m_averageTemperature += subRegionAvgTempNumerator; + if( subRegionMinTemp < stats.m_minTemperature ) + { + stats.m_minTemperature = subRegionMinTemp; + } + if( subRegionMaxTemp > stats.m_maxTemperature ) + { + stats.m_maxTemperature = subRegionMaxTemp; + } + + stats.m_totalUncompactedPoreVolume += subRegionTotalUncompactedPoreVol; + for( integer ip = 0; ip < numPhases; ++ip ) + { + stats.m_phasePoreVolume[ip] += subRegionPhaseDynamicPoreVol[ip]; + stats.m_phaseMass[ip] += subRegionPhaseMass[ip]; + stats.m_trappedPhaseMass[ip] += subRegionTrappedPhaseMass[ip]; + stats.m_immobilePhaseMass[ip] += subRegionImmobilePhaseMass[ip]; + + for( integer ic = 0; ic < numComps; ++ic ) + { + stats.m_componentMass[ip][ic] += subRegionComponentMass[ip][ic]; + } + } + + } ); + + // Step 3: synchronize the results over the MPI ranks + for( size_t i = 0; i < regionNames.size(); ++i ) + { + ElementRegionBase & region = elemManager.getRegion( regionNames[i] ); + RegionStatistics & stats = region.getReference< RegionStatistics >( VKStruct::regionStatisticsString() ); + + stats.m_minPressure = MpiWrapper::min( stats.m_minPressure ); + stats.m_maxPressure = MpiWrapper::max( stats.m_maxPressure ); + stats.m_minDeltaPressure = MpiWrapper::min( stats.m_minDeltaPressure ); + stats.m_maxDeltaPressure = MpiWrapper::max( stats.m_maxDeltaPressure ); + stats.m_minTemperature = MpiWrapper::min( stats.m_minTemperature ); + stats.m_maxTemperature = MpiWrapper::max( stats.m_maxTemperature ); + stats.m_totalUncompactedPoreVolume = MpiWrapper::sum( stats.m_totalUncompactedPoreVolume ); + stats.m_totalPoreVolume = 0.0; + for( integer ip = 0; ip < numPhases; ++ip ) + { + stats.m_phasePoreVolume[ip] = MpiWrapper::sum( stats.m_phasePoreVolume[ip] ); + stats.m_phaseMass[ip] = MpiWrapper::sum( stats.m_phaseMass[ip] ); + stats.m_trappedPhaseMass[ip] = MpiWrapper::sum( stats.m_trappedPhaseMass[ip] ); + stats.m_immobilePhaseMass[ip] = MpiWrapper::sum( stats.m_immobilePhaseMass[ip] ); + stats.m_totalPoreVolume += stats.m_phasePoreVolume[ip]; + for( integer ic = 0; ic < numComps; ++ic ) + { + stats.m_componentMass[ip][ic] = MpiWrapper::sum( stats.m_componentMass[ip][ic] ); + } + } + stats.m_averagePressure = MpiWrapper::sum( stats.m_averagePressure ); + stats.m_averageTemperature = MpiWrapper::sum( stats.m_averageTemperature ); + if( stats.m_totalUncompactedPoreVolume > 0 ) + { + float invTotalUncompactedPoreVolume = 1.0 / stats.m_totalUncompactedPoreVolume; + stats.m_averagePressure *= invTotalUncompactedPoreVolume; + stats.m_averageTemperature *= invTotalUncompactedPoreVolume; + } + else + { + stats.m_averagePressure = 0.0; + stats.m_averageTemperature = 0.0; + m_issues.emplace_back( GEOS_FMT( "Cannot compute average pressure because region pore volume is zero in region '{}'.", + regionNames[i] ) ); + } + + for( integer ip = 0; ip < numPhases; ++ip ) + { + stats.m_nonTrappedPhaseMass[ip] = stats.m_phaseMass[ip] - stats.m_trappedPhaseMass[ip]; + stats.m_mobilePhaseMass[ip] = stats.m_phaseMass[ip] - stats.m_immobilePhaseMass[ip]; + } + + stdVector< string > phaseCompName; + phaseCompName.reserve( numPhases*numComps ); + stdVector< string > massValues; + phaseCompName.reserve( numPhases*numComps ); + + ConstitutiveManager const & constitutiveManager = mesh.getGroupByPath< ConstitutiveManager >( "/Problem/domain/Constitutive" ); + MultiFluidBase const & fluid = constitutiveManager.getGroup< MultiFluidBase >( m_solver->referenceFluidModelName() ); + auto const phaseNames = fluid.phaseNames(); + auto const componentNames = fluid.componentNames(); + for( integer ip = 0; ip < numPhases; ++ip ) + { + for( integer ic = 0; ic < numComps; ++ic ) + { + std::stringstream ss; + ss << phaseNames[ip] << "/" << componentNames[ic]; + phaseCompName.push_back( ss.str() ); + massValues.push_back( GEOS_FMT( "{}", stats.m_componentMass[ip][ic] ) ); + } + } + } + + return true; +} + +bool StatsAggregator::computeCFLNumbers( real64 const time, + real64 const dt, + DomainPartition & domain ) +{ + GEOS_MARK_FUNCTION; + real64 maxPhaseCFL, maxCompCFL; + CFLStatistics * stats = getCFLStatistics( domain ); + + m_issues.clear(); + + if( stats!=nullptr ) + { + m_issues.emplace_back( GEOS_FMT( "No statistics structure to compute CFL numbers for domain '{}'.", domain.getName() )); + return false; + } + + m_solver->computeCFLNumbers( domain, dt, maxPhaseCFL, maxCompCFL ); + + stats->m_time = time; + stats->m_maxPhaseCFL = maxPhaseCFL; + stats->m_maxCompCFL = maxCompCFL; + + return true; +} + + +} /* namespace compositionalMultiphaseStatistics */ + +} /* namespace geos */ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.hpp new file mode 100644 index 00000000000..1e751dd2825 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.hpp @@ -0,0 +1,238 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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 CompositionalMultiphaseStatisticsAggregator.hpp + */ + +#ifndef SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICSAGGREGATOR_HPP_ +#define SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICSAGGREGATOR_HPP_ + +#include "common/StdContainerWrappers.hpp" +#include "dataRepository/Group.hpp" +#include "mesh/DomainPartition.hpp" +#include "mesh/MeshLevel.hpp" + +namespace geos +{ + +class CompositionalMultiphaseBase; + +namespace compositionalMultiphaseStatistics +{ + +struct AggregatorParameters +{ + /// Threshold to decide whether a phase is considered "mobile" or not + real64 m_relpermThreshold; + + // TODO: add other params like views and stuff +}; + +/** + * @brief Output data group to contain the result of a given stat aggregator on the dataRepository. + * Attributes are public since the class is a POD. Can it be replaced by a wrapped-struct? + */ +class RegionStatistics : public dataRepository::Group +{ +public: + + /// Time of statistics computation + real64 m_time; + + /// average region pressure + real64 m_averagePressure; + /// minimum region pressure + real64 m_minPressure; + /// maximum region pressure + real64 m_maxPressure; + + /// minimum region delta pressure + real64 m_minDeltaPressure; + /// maximum region delta pressure + real64 m_maxDeltaPressure; + + /// average region temperature + real64 m_averageTemperature; + /// minimum region temperature + real64 m_minTemperature; + /// maximum region temperature + real64 m_maxTemperature; + + /// total region pore volume + real64 m_totalPoreVolume; + /// total region uncompacted pore volume + real64 m_totalUncompactedPoreVolume; + /// phase region phase pore volume + array1d< real64 > m_phasePoreVolume; + + /// region phase mass (trapped and non-trapped, immobile and mobile) + array1d< real64 > m_phaseMass; + /// trapped region phase mass + array1d< real64 > m_trappedPhaseMass; + /// non-trapped region phase mass + array1d< real64 > m_nonTrappedPhaseMass; + /// immobile region phase mass + array1d< real64 > m_immobilePhaseMass; + /// mobile region phase mass + array1d< real64 > m_mobilePhaseMass; + /// region component mass + array2d< real64 > m_componentMass; + + // TODO: -> split to struct PressureStats...MassStats: + // - VKS for struct name ("pressureStats"..."massStats") + // - current RegionStatistics struct bits + + /** + * @brief Construct a new Region Statistics object + * @param name instance name in data-repository + * @param parent the instance parent in data-repository + */ + RegionStatistics( const string & name, dataRepository::Group * const parent ); +}; + +/** + * @brief Output data group to contain the result of a given stat aggregator on the dataRepository. + * Attributes are public since the class is a POD. Can it be replaced by a wrapped-struct? + */ +class CFLStatistics : public dataRepository::Group +{ +public: + /// Time of statistics computation + real64 m_time; + + /// Maximum Courant Friedrichs Lewy number in the grid for each phase + real64 m_maxPhaseCFL; + + /// Maximum Courant-Friedrichs-Lewy number in the grid for each component + real64 m_maxCompCFL; + + /** + * @brief Construct a new CFLStatistics object + * @param name instance name in data-repository + * @param parent the instance parent in data-repository + */ + CFLStatistics( const string & name, dataRepository::Group * const parent ); +}; + +/** + * @brief Reponsible of computing physical statistics over the grid, registering the result in the + * data repository, but not storing / outputing it by itself. It does not have mutable state + * except the encountered issues. + */ +class StatsAggregator +{ +public: + + /** + * @brief the associated view keys + */ + struct VKStruct + { + /// String for the region statistics group + constexpr static char const * regionStatisticsString() { return "regionStatistics"; } + /// String for the cfl statistics group + constexpr static char const * cflStatisticsString() { return "cflStatistics"; } + }; + + using RegionFunctor = std::function< void (string_view, RegionStatistics const &) >; + + StatsAggregator(); + + /** + * @brief Set the reference flow solver object to retrieve: + - the simulated regions, + - fields for statistics computation. + * @param solver The reference flow solver + */ + void setFlowSolver( CompositionalMultiphaseBase & solver ) + { m_solver = &solver; } + + // void forDiscretizations( DomainPartition const &, + // std::function< void(MeshLevel const &, + // string_array const & regionNames) > functor ) const; + + void forRegionStatistics( MeshLevel const & mesh, + RegionFunctor functor ) const; + + /** + * @brief Enable the computation of region statistics, initialize data structure to collect them. + * Register the resulting data wrappers so they will be targeted by TimeHistory output + * @note Must be called in "registerDataOnMesh" initialization phase + * @param meshBodies The Group containing the MeshBody objects + */ + void enableRegionStatistics( dataRepository::Group & meshBodies ); + + /** + * @brief Register the results structs & wrappers so they will be targeted by TimeHistory output + * @note Must be called in "registerDataOnMesh" initialization phase + * @param meshBodies The Group containing the MeshBody objects + */ + void enableCFLStatistics( dataRepository::Group & meshBodies ); + + /** + * @brief Compute some statistics on a given mesh discretization (average field pressure, etc) + * Results are reduced on rank 0, and broadcasted over all ranks. + * @param[in] time current time + * @param[in] mesh the mesh level object + * @param[in] regionNames the array of target region names + * @return false if there was a problem that prevented the statistics to be computed correctly. + */ + bool computeRegionsStatistics( real64 const time, + MeshLevel & mesh, + string_array const & regionNames ); + + /** + * @brief Compute CFL numbers + * @param[in] time current time + * @param[in] dt the time step size + * @param[in] domain the domain partition + * @return false if there was a problem that prevented the statistics to be computed correctly. + */ + bool computeCFLNumbers( real64 const time, + real64 const dt, + DomainPartition & domain ); + + CFLStatistics * getCFLStatistics( DomainPartition & domain ) const + {return domain.getGroupPointer< CFLStatistics >( VKStruct::cflStatisticsString() ); } + + CompositionalMultiphaseBase const * getSolver() const + { return m_solver; } + + /** + * @return The encountered issues during the last computing method call. + */ + stdVector< string > const & getIssues() const + { return m_issues; } + +private: + + CompositionalMultiphaseBase * m_solver; + + AggregatorParameters m_params; + + stdVector< string > m_issues; + + bool m_isRegionStatsEnabled; + + bool m_isCFLNumberEnabled; + +}; + +} /* namespace compositionalMultiphaseStatistics */ + +} /* namespace geos */ + +#endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICSAGGREGATOR_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsTask.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsTask.cpp new file mode 100644 index 00000000000..f49a4ef4c33 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsTask.cpp @@ -0,0 +1,383 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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 CompositionalMultiphaseStatistics.cpp + */ + +#include "CompositionalMultiphaseStatisticsTask.hpp" + +#include "common/DataTypes.hpp" +#include "common/MpiWrapper.hpp" +#include "common/StdContainerWrappers.hpp" +#include "common/format/Format.hpp" +#include "mesh/DomainPartition.hpp" +#include "mesh/MeshLevel.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "physicsSolvers/LogLevelsInfo.hpp" +#include "physicsSolvers/fluidFlow/LogLevelsInfo.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "common/format/table/TableData.hpp" +#include "common/format/table/TableFormatter.hpp" +#include "common/format/table/TableLayout.hpp" +#include +#include + + +namespace geos +{ + +using namespace constitutive; +using namespace fields; +using namespace dataRepository; + +namespace compositionalMultiphaseStatistics +{ + +StatsTask::StatsTask( const string & name, Group * const parent ): + Base( name, parent ), + m_aggregator(), + m_computeCFLNumbers( 0 ), + m_computeRegionStatistics( 1 ) +{ + registerWrapper( viewKeyStruct::computeCFLNumbersString(), &m_computeCFLNumbers ). + setApplyDefaultValue( 0 ). + setInputFlag( InputFlags::OPTIONAL ). + setDescription( "Flag to decide whether CFL numbers are computed or not" ); + + registerWrapper( viewKeyStruct::computeRegionStatisticsString(), &m_computeRegionStatistics ). + setApplyDefaultValue( 1 ). + setInputFlag( InputFlags::OPTIONAL ). + setDescription( "Flag to decide whether region statistics are computed or not" ); + + registerWrapper( viewKeyStruct::relpermThresholdString(), &m_relpermThreshold ). + setApplyDefaultValue( 1e-6 ). + setInputFlag( InputFlags::OPTIONAL ). + setDescription( "Flag to decide whether a phase is considered mobile (when the relperm is above the threshold) or immobile (when the relperm is below the threshold) in metric 2" ); + + addLogLevel< logInfo::CFL >(); + addLogLevel< logInfo::Statistics >(); +} + +void StatsTask::postInputInitialization() +{ + Base::postInputInitialization(); + + m_aggregator.setFlowSolver( *m_solver ); + + if( dynamicCast< CompositionalMultiphaseHybridFVM * >( m_solver ) && m_computeCFLNumbers != 0 ) + { + GEOS_THROW( GEOS_FMT( "{} {}: the option to compute CFL numbers is incompatible with CompositionalMultiphaseHybridFVM", + catalogName(), getDataContext() ), + InputError ); + } +} + +void StatsTask::registerDataOnMesh( Group & meshBodies ) +{ + // for now, this guard is needed to avoid breaking the xml schema generation + if( m_solver == nullptr ) + { + return; + } + + getGroupByPath( "/" ).printDataHierarchy(); + + prepareFluidMetaData(); + + if( m_computeRegionStatistics ) + m_aggregator.enableRegionStatistics( meshBodies ); + + // if we have to compute CFL numbers later, we need to register additional variables + if( m_computeCFLNumbers ) + m_solver->registerDataForCFL( meshBodies ); + + m_solver->forDiscretizationOnMeshTargets( meshBodies, [&] ( string const &, + MeshLevel & mesh, + string_array const & ) + { + prepareLogTableLayouts( mesh.getName() ); + prepareCsvTableLayouts( mesh.getName() ); + } ); +} + +void StatsTask::prepareFluidMetaData() +{ + ConstitutiveManager const & constitutiveManager = this->getGroupByPath< ConstitutiveManager >( "/Problem/domain/Constitutive" ); + MultiFluidBase const & fluid = constitutiveManager.getGroup< MultiFluidBase >( m_solver->referenceFluidModelName() ); + + m_fluid.m_numPhases = fluid.numFluidPhases(); + m_fluid.m_numComps = fluid.numFluidComponents(); + + m_fluid.m_phaseNames = fluid.phaseNames(); + m_fluid.m_compNames = fluid.componentNames(); + + m_fluid.m_phaseCompNames.resize( + m_fluid.m_numPhases, + stdVector< string >( m_fluid.m_numComps, string() ) ); + + for( int ip = 0; ip < m_fluid.m_numPhases; ++ip ) + for( int ic = 0; ic < m_fluid.m_numComps; ++ic ) + m_fluid.m_phaseCompNames[ip][ic] = GEOS_FMT( "{}/{}", m_fluid.m_phaseNames[ip], m_fluid.m_compNames[ic] ); +} + +void StatsTask::prepareLogTableLayouts( string_view meshName ) +{ + // only output from rank 0 + if( MpiWrapper::commRank() != 0 ) + return; + + TableLayout const tableLayout = TableLayout() + .setTitle( GEOS_FMT( "{}: mesh {}", getName(), meshName ) ); + + m_logFormatters.emplace( meshName, std::make_unique< TableTextFormatter >( tableLayout ) ); +} + +void StatsTask::prepareCsvTableLayouts( string_view meshName ) +{ + // only output from rank 0 + if( MpiWrapper::commRank() != 0 || !m_writeCSV ) + return; + + integer const numPhases = m_solver->numFluidPhases(); + integer const numComps = m_solver->numFluidComponents(); + + auto addPhaseColumns = []( TableLayout & ptableLayout, string const & description, string_view punit, + integer pnumPhases ) + { + for( int ip = 0; ip < pnumPhases; ++ip ) + ptableLayout.addColumn( GEOS_FMT( "{} (phase {}) [{}]", + description, ip, punit ) ); + }; + auto addPhaseCompColumns = []( TableLayout & ptableLayout, string const & description, string_view punit, + integer pnumPhases, integer pnumComps ) + { + for( int ip = 0; ip < pnumPhases; ++ip ) + for( int ic = 0; ic < pnumComps; ++ic ) + ptableLayout.addColumn( GEOS_FMT( "{} (component {} / phase {}) [{}]", + description, ic, ip, punit ) ); + }; + + string_view massUnit = units::getSymbol( m_solver->getMassUnit() ); + + TableLayout tableLayout( { + TableLayout::Column( GEOS_FMT( "Time [{}]", units::getSymbol( units::Unit::Time ))), + TableLayout::Column( "Region" ), // TODO : mention this change in PR description + TableLayout::Column( GEOS_FMT( "Min pressure [{}]", units::getSymbol( units::Unit::Pressure ))), + TableLayout::Column( GEOS_FMT( "Average pressure [{}]", units::getSymbol( units::Unit::Pressure )) ), + TableLayout::Column( GEOS_FMT( "Max pressure [{}]", units::getSymbol( units::Unit::Pressure ) ) ), + TableLayout::Column( GEOS_FMT( "Min delta pressure [{}]", units::getSymbol( units::Unit::Pressure ))), + TableLayout::Column( GEOS_FMT( "Max delta pressure [{}]", units::getSymbol( units::Unit::Pressure ))), + TableLayout::Column( GEOS_FMT( "Min temperature [{}]", units::getSymbol( units::Unit::Temperature ) )), + TableLayout::Column( GEOS_FMT( "Average temperature [{}]", units::getSymbol( units::Unit::Temperature ) )), + TableLayout::Column( GEOS_FMT( "Max temperature [{}]", units::getSymbol( units::Unit::Temperature ) )), + TableLayout::Column( GEOS_FMT( "Total dynamic pore volume [{}]", units::getSymbol( units::Unit::ReservoirVolume ) )), + } ); + addPhaseColumns( tableLayout, "Phase dynamic pore volume", units::getSymbol( units::Unit::ReservoirVolume ), numPhases ); + addPhaseColumns( tableLayout, "Phase mass", massUnit, numPhases ); + addPhaseColumns( tableLayout, "Trapped phase mass (metric 1)", massUnit, numPhases ); + addPhaseColumns( tableLayout, "Non-trapped phase mass (metric 1)", massUnit, numPhases ); + addPhaseColumns( tableLayout, "Immobile phase mass (metric 2)", massUnit, numPhases ); + addPhaseColumns( tableLayout, "Mobile phase mass (metric 2)", massUnit, numPhases ); + addPhaseCompColumns( tableLayout, "Component mass", massUnit, numPhases, numComps ); + + auto & csvFormatter = m_csvFormatters.get_inserted( string( meshName ) ); + csvFormatter = std::move( std::make_unique< TableCSVFormatter >( tableLayout ) ); + + // output CSV header + std::ofstream outputFile( getCsvFileName( meshName ) ); + outputFile << csvFormatter->headerToString(); + GEOS_LOG( GEOS_FMT( "table {} : {}", meshName, csvFormatter->headerToString() ) ); // TODO : remove this log +} + +string StatsTask::getCsvFileName( string_view meshName ) const +{ return GEOS_FMT( "{}/{}.csv", m_outputDir, meshName ); } + +bool StatsTask::execute( real64 const time_n, + real64 const dt, + integer const GEOS_UNUSED_PARAM( cycleNumber ), + integer const GEOS_UNUSED_PARAM( eventCounter ), + real64 const GEOS_UNUSED_PARAM( eventProgress ), + DomainPartition & domain ) +{ + // current time is time_n + dt. TODO: verify implication of events ordering in 'time_n+dt' validity + real64 statsTime = time_n + dt; + + m_solver->forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, + MeshLevel & mesh, + string_array const & regionNames ) + { + if( m_computeRegionStatistics ) + { + m_aggregator.computeRegionsStatistics( statsTime, mesh, regionNames ); + outputLogStats( statsTime, mesh, regionNames ); + outputCsvStats( statsTime, mesh, regionNames ); + } + } ); + + if( m_computeCFLNumbers ) + m_aggregator.computeCFLNumbers( statsTime, dt, domain ); + + return false; +} + +void StatsTask::outputLogStats( real64 const statsTime, + MeshLevel & mesh, + string_array const & ) +{ + if( MpiWrapper::commRank() > 0 || !isLogLevelActive< logInfo::Statistics >( this->getLogLevel() ) ) + return; + + auto const formatterIter = m_logFormatters.find( mesh.getName() ); + if( formatterIter==m_logFormatters.end()) + return; + + TableTextFormatter const & formatter = *formatterIter->second; + TableData tableData; + static constexpr auto merge = CellType::MergeNext; + + string_view massUnit = units::getSymbol( m_aggregator.getSolver()->getMassUnit() ); + string_view pressureUnit = units::getSymbol( units::Pressure ); + string_view tempUnit = units::getSymbol( units::Temperature ); + string_view resVolUnit = units::getSymbol( units::ReservoirVolume ); + + tableData.addRow( "Statistics time", merge, merge, statsTime ); + m_aggregator.forRegionStatistics( mesh, + [&]( string_view regionName, RegionStatistics const & stats ) + { + + tableData.addRow( merge, merge, merge, "" ); + + tableData.addSeparator(); + tableData.addRow( merge, merge, merge, GEOS_FMT( "Region '{}'", regionName ) ); + tableData.addRow( "statistics", "min", "average", "max" ); + tableData.addSeparator(); + + tableData.addRow( GEOS_FMT( "Pressure [{}]", pressureUnit ), + stats.m_minPressure, stats.m_averagePressure, stats.m_maxPressure ); + tableData.addRow( GEOS_FMT( "Delta pressure [{}]", pressureUnit ), + stats.m_minDeltaPressure, "/", stats.m_maxDeltaPressure ); + tableData.addRow( GEOS_FMT( "Temperature [{}]", tempUnit ), + stats.m_minTemperature, stats.m_averageTemperature, stats.m_maxTemperature ); + + tableData.addSeparator(); + + tableData.addRow( GEOS_FMT( "Total dynamic pore volume [{}]", resVolUnit ), CellType::MergeNext, CellType::MergeNext, stats.m_totalPoreVolume ); + tableData.addRow( GEOS_FMT( "Phase dynamic pore volume [{}]", resVolUnit ), + stringutilities::joinLambda( m_fluid.m_phaseNames, "\n", []( auto data ) { return data[0]; } ), + CellType::MergeNext, + stringutilities::joinLambda( stats.m_phasePoreVolume, "\n", []( auto data ) { return data[0]; } ) ); + + tableData.addSeparator(); + + tableData.addRow( GEOS_FMT( "Phase mass [{}]", massUnit ), + stringutilities::joinLambda( m_fluid.m_phaseNames, "\n", []( auto data ) { return data[0]; } ), + CellType::MergeNext, + stringutilities::joinLambda( stats.m_phaseMass, "\n", []( auto data ) { return data[0]; } ) ); + + tableData.addSeparator(); + + tableData.addRow( GEOS_FMT( "Trapped phase mass (metric 1) [{}]", massUnit ), + stringutilities::joinLambda( m_fluid.m_phaseNames, "\n", []( auto value ) { return value[0]; } ), + CellType::MergeNext, + stringutilities::joinLambda( stats.m_trappedPhaseMass, "\n", []( auto value ) { return value[0]; } ) ); + tableData.addRow( GEOS_FMT( "Non-trapped phase mass (metric 1) [{}]", massUnit ), + stringutilities::joinLambda( m_fluid.m_phaseNames, "\n", []( auto value ) { return value[0]; } ), + CellType::MergeNext, + stringutilities::joinLambda( stats.m_nonTrappedPhaseMass, "\n", []( auto value ) { return value[0]; } ) ); + + tableData.addSeparator(); + + tableData.addRow( GEOS_FMT( "Immobile phase mass (metric 2) [{}]", massUnit ), + stringutilities::joinLambda( m_fluid.m_phaseNames, "\n", []( auto value ) { return value[0]; } ), + CellType::MergeNext, + stringutilities::joinLambda( stats.m_immobilePhaseMass, "\n", []( auto value ) { return value[0]; } ) ); + tableData.addRow( GEOS_FMT( "Mobile phase mass (metric 2) [{}]", massUnit ), + stringutilities::joinLambda( m_fluid.m_phaseNames, "\n", []( auto value ) { return value[0]; } ), + CellType::MergeNext, + stringutilities::joinLambda( stats.m_mobilePhaseMass, "\n", []( auto value ) { return value[0]; } ) ); + + tableData.addSeparator(); + + tableData.addRow( GEOS_FMT( "Component mass [{}]", massUnit ), + "TODO" /*stringutilities::join( m_fluid.m_phaseCompNames, '\n' )*/, + CellType::MergeNext, + stringutilities::join( stats.m_componentMass, '\n' ) ); + + tableData.addSeparator(); + } ); + + GEOS_LOG_RANK_0( formatter.toString( tableData ) ); +} + +void StatsTask::outputCsvStats( real64 statsTime, + MeshLevel & mesh, + string_array const & ) +{ + if( MpiWrapper::commRank() > 0 || m_writeCSV == 0 ) + return; + + m_aggregator.forRegionStatistics( mesh, + [&]( string_view meshName, RegionStatistics const & stats ) + { + TableData tableData; + stdVector< string > row; + row.reserve( m_csvFormatters.at( string( meshName ))->getLayout().getTotalLowermostColumnCount() ); + + auto addPhaseValues = []( auto & list, auto const & values ) + { + for( auto value : values ) + list.emplace_back( std::to_string( value ) ); + }; + + row.insert( row.begin(), + { std::to_string( statsTime ), + std::to_string( stats.m_minPressure ), + std::to_string( stats.m_averagePressure ), + std::to_string( stats.m_maxPressure ), + std::to_string( stats.m_minDeltaPressure ), + std::to_string( stats.m_maxDeltaPressure ), + std::to_string( stats.m_minTemperature ), + std::to_string( stats.m_averageTemperature ), + std::to_string( stats.m_maxTemperature ), + std::to_string( stats.m_totalPoreVolume ), + } ); + addPhaseValues( row, stats.m_phasePoreVolume ); + addPhaseValues( row, stats.m_phaseMass ); + addPhaseValues( row, stats.m_trappedPhaseMass ); + addPhaseValues( row, stats.m_nonTrappedPhaseMass ); + addPhaseValues( row, stats.m_immobilePhaseMass ); + addPhaseValues( row, stats.m_mobilePhaseMass ); + addPhaseValues( row, stats.m_componentMass ); // TODO verify phase / comp ordering + + std::ofstream outputFile( getCsvFileName( mesh.getName() ), std::ios_base::app ); + TableCSVFormatter const csvOutput; + outputFile << csvOutput.dataToString( tableData ); + outputFile.close(); + } ); +} + +REGISTER_CATALOG_ENTRY( TaskBase, + StatsTask, + string const &, dataRepository::Group * const ) + +} /* namespace compositionalMultiphaseStatistics */ + +} /* namespace geos */ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsTask.hpp similarity index 55% rename from src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsTask.hpp index dbe275b7b6f..81be4446537 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsTask.hpp @@ -14,25 +14,32 @@ */ /** - * @file CompositionalMultiphaseStatistics.hpp + * @file CompositionalMultiphaseStatisticsTask.hpp */ -#ifndef SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICS_HPP_ -#define SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICS_HPP_ +#ifndef SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICSTASK_HPP_ +#define SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICSTASK_HPP_ +#include "common/DataTypes.hpp" +#include "common/format/table/TableFormatter.hpp" +#include "common/format/table/TableLayout.hpp" #include "physicsSolvers/FieldStatisticsBase.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.hpp" namespace geos { class CompositionalMultiphaseBase; +namespace compositionalMultiphaseStatistics +{ + /** - * @class CompositionalMultiphaseStatistics + * @class CompositionalMultiphaseStatistics::Task * * Task class allowing for the computation of aggregate statistics in compositional multiphase simulations */ -class CompositionalMultiphaseStatistics : public FieldStatisticsBase< CompositionalMultiphaseBase > +class StatsTask : public FieldStatisticsBase< CompositionalMultiphaseBase > { public: @@ -41,16 +48,11 @@ class CompositionalMultiphaseStatistics : public FieldStatisticsBase< Compositio * @param[in] name the name of the task coming from the xml * @param[in] parent the parent group of the task */ - CompositionalMultiphaseStatistics( const string & name, - Group * const parent ); + StatsTask( const string & name, dataRepository::Group * const parent ); /// Accessor for the catalog name static string catalogName() { return "CompositionalMultiphaseStatistics"; } - /// Accessor for the region statistics catalog name - static string regionStatisticsName() { return "regionStatistics"; } - - /** * @defgroup Tasks Interface Functions * @@ -67,43 +69,6 @@ class CompositionalMultiphaseStatistics : public FieldStatisticsBase< Compositio /**@}*/ - struct RegionStatistics - { - /// average region pressure - real64 averagePressure; - /// minimum region pressure - real64 minPressure; - /// maximum region pressure - real64 maxPressure; - - /// minimum region delta pressure - real64 minDeltaPressure; - /// maximum region delta pressure - real64 maxDeltaPressure; - - /// average region temperature - real64 averageTemperature; - /// minimum region temperature - real64 minTemperature; - /// maximum region temperature - real64 maxTemperature; - - /// total region pore volume - real64 totalPoreVolume; - /// total region uncompacted pore volume - real64 totalUncompactedPoreVolume; - /// phase region phase pore volume - array1d< real64 > phasePoreVolume; - - /// region phase mass (trapped and non-trapped, immobile and mobile) - array1d< real64 > phaseMass; - /// trapped region phase mass - array1d< real64 > trappedPhaseMass; - /// immobile region phase mass - array1d< real64 > immobilePhaseMass; - /// region component mass - array2d< real64 > componentMass; - }; private: using Base = FieldStatisticsBase< CompositionalMultiphaseBase >; @@ -117,37 +82,38 @@ class CompositionalMultiphaseStatistics : public FieldStatisticsBase< Compositio constexpr static char const * computeCFLNumbersString() { return "computeCFLNumbers"; } /// String for the flag deciding the computation of the region statistics constexpr static char const * computeRegionStatisticsString() { return "computeRegionStatistics"; } - /// String for the region statistics - constexpr static char const * regionStatisticsString() { return "regionStatistics"; } /// String for the relperm threshold constexpr static char const * relpermThresholdString() { return "relpermThreshold"; } }; + void postInputInitialization() override; - /** - * @brief Compute some statistics on the reservoir (average field pressure, etc) - * @param[in] time current time - * @param[in] mesh the mesh level object - * @param[in] regionNames the array of target region names - */ - void computeRegionStatistics( real64 const time, - MeshLevel & mesh, - string_array const & regionNames ) const; + void registerDataOnMesh( Group & meshBodies ) override; - /** - * @brief Compute CFL numbers - * @param[in] time current time - * @param[in] dt the time step size - * @param[in] domain the domain partition - */ - void computeCFLNumbers( real64 const time, - real64 const dt, - DomainPartition & domain ) const; + void prepareFluidMetaData(); - void postInputInitialization() override; + void prepareLogTableLayouts( string_view tableName ); - void registerDataOnMesh( Group & meshBodies ) override; + void prepareCsvTableLayouts( string_view tableName ); + + string getCsvFileName( string_view meshName ) const; + + void outputLogStats( real64 statsTime, + MeshLevel & mesh, + string_array const & regionNames ); + + void outputCsvStats( real64 statsTime, + MeshLevel & mesh, + string_array const & regionNames ); + + /// For each discretization (MeshLevel name), table formatter for log output. + stdMap< string, std::unique_ptr< TableTextFormatter > > m_logFormatters; + + /// For each discretization (MeshLevel name), table formatter for csv output. + stdMap< string, std::unique_ptr< TableCSVFormatter > > m_csvFormatters; + + StatsAggregator m_aggregator; /// Flag to decide whether CFL numbers are computed or not integer m_computeCFLNumbers; @@ -158,9 +124,19 @@ class CompositionalMultiphaseStatistics : public FieldStatisticsBase< Compositio /// Threshold to decide whether a phase is considered "mobile" or not real64 m_relpermThreshold; + struct FluidMetaData + { + integer m_numPhases; + integer m_numComps; + stdVector< string > m_phaseNames; + stdVector< string > m_compNames; + stdVector< stdVector< string > > m_phaseCompNames; + } m_fluid; + }; +} /* namespace compositionalMultiphaseStatistics */ } /* namespace geos */ -#endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICS_HPP_ */ +#endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASESTATISTICSTASK_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 28def34e770..befc8a11e1f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -48,7 +48,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" @@ -729,21 +729,22 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana } else { - if( !wellControls.referenceReservoirRegion().empty() ) - { - ElementRegionBase const & region = elemManager.getRegion( wellControls.referenceReservoirRegion()); - GEOS_ERROR_IF ( !region.hasWrapper( CompositionalMultiphaseStatistics::regionStatisticsName() ), - GEOS_FMT( "{}: WellControl {} referenceReservoirRegion field requires CompositionalMultiphaseStatistics to be configured for region {} ", - getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() ) ); - - CompositionalMultiphaseStatistics::RegionStatistics const & stats = region.getReference< CompositionalMultiphaseStatistics::RegionStatistics >( - CompositionalMultiphaseStatistics::regionStatisticsName() ); - wellControls.setRegionAveragePressure( stats.averagePressure ); - wellControls.setRegionAverageTemperature( stats.averageTemperature ); - GEOS_ERROR_IF( stats.averagePressure <= 0.0, - GEOS_FMT( "{}: No region average quantities computed. WellControl {} referenceReservoirRegion field requires CompositionalMultiphaseStatistics to be configured for region {} ", - getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() )); - } + GEOS_UNUSED_VAR(elemManager); + // if( !wellControls.referenceReservoirRegion().empty() ) + // { + // ElementRegionBase const & region = elemManager.getRegion( wellControls.referenceReservoirRegion()); + // GEOS_ERROR_IF ( !region.hasWrapper( CompositionalMultiphaseStatistics::regionStatisticsName() ), + // GEOS_FMT( "{}: WellControl {} referenceReservoirRegion field requires CompositionalMultiphaseStatistics to be configured for region {} ", + // getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() ) ); + + // CompositionalMultiphaseStatistics::RegionStatistics const & stats = region.getReference< CompositionalMultiphaseStatistics::RegionStatistics >( + // CompositionalMultiphaseStatistics::regionStatisticsName() ); + // wellControls.setRegionAveragePressure( stats.averagePressure ); + // wellControls.setRegionAverageTemperature( stats.averageTemperature ); + // GEOS_ERROR_IF( stats.averagePressure <= 0.0, + // GEOS_FMT( "{}: No region average quantities computed. WellControl {} referenceReservoirRegion field requires CompositionalMultiphaseStatistics to be configured for region {} ", + // getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() )); + // } // If flashPressure is not set by region the value is defaulted to -1 and indicates to use top segment conditions flashPressure = wellControls.getRegionAveragePressure(); if( flashPressure < 0.0 )