diff --git a/.clangd b/.clangd new file mode 100644 index 00000000000..6e903480907 --- /dev/null +++ b/.clangd @@ -0,0 +1,23 @@ +CompileFlags: + Add: + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/GEOS/src/coreComponents + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/GEOS/src/coreComponents/linearAlgebra + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/GEOS/src/cmake/blt/thirdparty_builtin/googletest/googletest/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/GEOS/build-develop/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-raja-git.1d70abf171474d331f1409908bdf1b1c3fe19222_develop-dfj5hwwhvr4v32yxbduwrv2x4izvriez/spack-src/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/gcc-12.2.1/raja-git.1d70abf171474d331f1409908bdf1b1c3fe19222_develop-dfj5hwwhvr4v32yxbduwrv2x4izvriez/.spack/spack-build-dfj5hww/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-camp-git.ee0a3069a7ae72da8bcea63c06260fad34901d43_main-7wyhilu22frfttymb3dgrvaubocr3igk/spack-src/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-camp-git.ee0a3069a7ae72da8bcea63c06260fad34901d43_main-7wyhilu22frfttymb3dgrvaubocr3igk/spack-build-7wyhilu/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-fmt-10.0.0-2ckd7w7qbgdr2ysc2uybihnao6ngqtox/spack-src/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-umpire-git.1ed0669c57f041baa1f1070693991c3a7a43e7ee_develop-orylmsm4ynx3tffjsyablcrrb7xeqr75/spack-src/src + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-umpire-git.1ed0669c57f041baa1f1070693991c3a7a43e7ee_develop-orylmsm4ynx3tffjsyablcrrb7xeqr75/spack-build-orylmsm/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/gcc-12.2.1/umpire-git.1ed0669c57f041baa1f1070693991c3a7a43e7ee_develop-orylmsm4ynx3tffjsyablcrrb7xeqr75/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/gcc-12.2.1/chai-git.4b9060b18b9bec1167026cfb3132bd540c4bd56b_develop-kebrblc66x6zw5hvdcbh46kgnpua77n3/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/gcc-12.2.1/vtk-9.4.2-cyy6bpea5gfinatsqlbral2d6f5voaob/include/vtk-9.4 + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-vtk-9.4.2-cyy6bpea5gfinatsqlbral2d6f5voaob/spack-src/ThirdParty/pugixml/vtkpugixml/src + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-vtk-9.4.2-cyy6bpea5gfinatsqlbral2d6f5voaob/spack-build-cyy6bpe/ThirdParty/pugixml/vtkpugixml/src + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-caliper-git.287b7f3ad2d12f520aad04268d44f353cd05403c_2.12.0-f3wivxbfbxrtiz2siwdgvm2l27cqec4j/spack-src/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-conduit-git.ad86e316ad56a75c099d30ca5ce75cff275b5924_develop-zu4a2kq24d4vq6sx2iv2wxzjvw6gu6sv/spack-src/src/libs/conduit + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-conduit-git.ad86e316ad56a75c099d30ca5ce75cff275b5924_develop-zu4a2kq24d4vq6sx2iv2wxzjvw6gu6sv/spack-build-zu4a2kq/libs/conduit + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-parmetis-4.0.3-7mo5p53bnnfmnfiuivjt4guunnu35teh/spack-src/include + - -I/data/pau901/SIM_CS/04_WORKSPACE/USERS/MelvinRey/WorkEnv/GEOSX_repos/thirdPartyLibs/install-master/build_stage/l1092082/spack-stage-scotch-*/spack-build-*/src/include 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/common/format/table/TableTypes.hpp b/src/coreComponents/common/format/table/TableTypes.hpp index 4565ad92ff8..f81a368353e 100644 --- a/src/coreComponents/common/format/table/TableTypes.hpp +++ b/src/coreComponents/common/format/table/TableTypes.hpp @@ -80,7 +80,7 @@ class TableErrorListing * @brief Append a vector of string to the errors vector. * @param errors A vector of string to append */ - void appendErrors( std::vector< string > & errors ) + void appendErrors( std::vector< string > const & errors ) { m_errorList.insert( m_errorList.end(), errors.begin(), errors.end() );} /** diff --git a/src/coreComponents/dataRepository/DataContext.hpp b/src/coreComponents/dataRepository/DataContext.hpp index 63b855e24f2..b4f70ac510b 100644 --- a/src/coreComponents/dataRepository/DataContext.hpp +++ b/src/coreComponents/dataRepository/DataContext.hpp @@ -78,7 +78,7 @@ class DataContext /** * @return Get the target object name */ - string getTargetName() const + string const & getTargetName() const { return m_targetName; } /** * @brief Insert contextual information in the provided stream. @@ -179,13 +179,13 @@ class DataFileContext final : public DataContext /** * @return the type name in the source file (XML node tag name / attribute name). */ - string getTypeName() const + string const & getTypeName() const { return m_typeName; } /** * @return the source file path where the target object has been declared. */ - string getFilePath() const + string const & getFilePath() const { return m_filePath; } /** diff --git a/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp b/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp index af9efb7fefa..40a9f27f682 100644 --- a/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp +++ b/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp @@ -50,8 +50,7 @@ class FieldStatisticsBase : public TaskBase m_outputDir( joinPath( OutputBase::getOutputDirectory(), name ) ) { - string const key = SOLVER::coupledSolverAttributePrefix() + "SolverName"; - registerWrapper( key, &m_solverName ). + registerWrapper( getSolverWrapperKey(), &m_solverName ). setRTTypeName( rtTypes::CustomTypes::groupNameRef ). setInputFlag( dataRepository::InputFlags::REQUIRED ). setDescription( "Name of the " + SOLVER::coupledSolverAttributePrefix() + " solver" ); @@ -80,6 +79,20 @@ class FieldStatisticsBase : public TaskBase protected: + struct viewKeyStruct + { + static constexpr char const * writeCSVFlagString() { return "writeCSV"; } + }; + + /// Pointer to the physics solver + SOLVER * m_solver; + + // Output directory + string const m_outputDir; + + // Flag to enable writing CSV output + integer m_writeCSV; + void postInputInitialization() override { Group & problemManager = this->getGroupByPath( "/Problem" ); @@ -104,19 +117,8 @@ class FieldStatisticsBase : public TaskBase } } - struct viewKeyStruct - { - static constexpr char const * writeCSVFlagString() { return "writeCSV"; } - }; - - /// Pointer to the physics solver - SOLVER * m_solver; - - // Output directory - string const m_outputDir; - - // Flag to enable writing CSV output - integer m_writeCSV; + string getSolverWrapperKey() const + { return SOLVER::coupledSolverAttributePrefix() + "SolverName"; } private: diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 6eb55e9775a..5cd5d8d8e0f 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 @@ -142,7 +143,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..19f1c8aad03 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.cpp @@ -0,0 +1,577 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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 + * @details Region statistics data is stored as follow: + + * Problem : ProblemManager + * |-> domain : DomainPartition + * |-> MeshBodies : Group + * |-> cartesianMesh : MeshBody + * |-> meshLevels : Group + * |-> Level0 : MeshLevel + * | |-> nodeManager : NodeManager + * | | |-> sets : Group + * | | | * all : Wrapper< index array > + * | | | * xneg : Wrapper< index array > + * | | [...] (other element sets) + * | | + * | |-> ElementRegions : ElementRegionManager + * | | |-> Channel : CellElementRegion + * | | | |-> cb-0_0_0 : CellElementSubRegion + * | | | | | * pressure : Wrapper< real64 array > + * | | | | | * temperature : Wrapper< real64 array > + * | | | | [...] (other fields) + * | | | | + * | | | |-> cb-0_0_1 : CellElementSubRegion + * | | | | | * pressure : Wrapper< real64 array > + * | | | | | * temperature : Wrapper< real64 array > + * | | | | [...] (other fields) + * | | | | + * | | | [...] (other sub-regions) + * | | | + * | | |-> Barrier : CellElementRegion + * | | |-> cb-1_0_0 : CellElementSubRegion + * | | |-> cb-1_0_1 : CellElementSubRegion + * | | [...] (other sub-regions) + * | | + * | [...] (other element managers) + * ____ | | + * | | |-> statistics : Group (storage for all stats) + * | | |-> compFlowStats : Group (storage for this instance stats) + * | | | |-> cflStatistics : CFLStatistics + * | | | |-> regionsStatistics : RegionStatistics (aggregate) + * | | | |-> Channel : RegionStatistics (aggregate, mpi reduced) + * | | | | |-> cb-0_0_0 : RegionStatistics (compute read-back) + * stats | | | | |-> cb-0_0_1 : RegionStatistics (compute read-back) + * data -> | | | | [...] (other sub-regions stats) + * | | | | + * | | | |-> Barrier : RegionStatistics (aggregate, mpi reduced) + * | | | |-> cb-1_0_0 : RegionStatistics (compute read-back) + * | | | |-> cb-1_0_1 : RegionStatistics (compute read-back) + * | | | [...] (other sub-regions stats) + * | | | + * |___ | [...] (other stats storages) + * | + * [...] (other discretizations) + */ + +#include "CompositionalMultiphaseStatisticsAggregator.hpp" + +#include "LvArray/src/math.hpp" +#include "LvArray/src/system.hpp" +#include "common/DataTypes.hpp" +#include "common/format/Format.hpp" +#include "common/format/StringUtilities.hpp" +#include "common/logger/Logger.hpp" +#include "dataRepository/DataContext.hpp" +#include "dataRepository/Group.hpp" +#include "mesh/CellElementRegion.hpp" +#include "mesh/CellElementSubRegion.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "mesh/MeshLevel.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include + + +namespace geos +{ + +namespace compositionalMultiphaseStatistics +{ + +using namespace constitutive; +// using namespace fields; +using namespace dataRepository; + +RegionStatistics::RegionStatistics( string const & name, dataRepository::Group * const parent, + integer const numPhases, integer const numComponents ): + dataRepository::Group( name, parent ), + m_phaseDynamicPoreVolume( numPhases ), + m_phaseMass( numPhases ), + m_trappedPhaseMass( numPhases ), + m_nonTrappedPhaseMass( numPhases ), + m_immobilePhaseMass( numPhases ), + m_mobilePhaseMass( numPhases ), + m_componentMass( numPhases, numComponents ) +{ + // TODO : registerWrappers to store results in HDF5 (but need repairing of 1D HDF5 outputs) +} + +CFLStatistics::CFLStatistics( string const & name, dataRepository::Group * const parent ): + dataRepository::Group( name, parent ) +{ + // TODO : registerWrappers to store results in HDF5 (but need repairing of 1D HDF5 outputs) +} + +StatsAggregator::StatsAggregator( DataContext const & ownerDataContext ): + m_ownerDataContext( ownerDataContext ), + m_params() +{} + +void StatsAggregator::initStatisticsAggregation( dataRepository::Group & meshBodies, + CompositionalMultiphaseBase & solver ) +{ + m_solver = &solver; + m_meshBodies = &meshBodies; + + m_numPhases = m_solver->numFluidPhases(); + m_numComponents = m_solver->numFluidComponents(); + + m_solver->forDiscretizationOnMeshTargets( meshBodies, [&] ( string const &, + MeshLevel & mesh, + string_array const & ) + { + // getting the container of all requesters statistics groups (can be already initialized) + Group * meshStatsGroup = mesh.getGroupPointer( ViewKeys::statisticsString() ); + if( meshStatsGroup == nullptr ) + meshStatsGroup = &mesh.registerGroup( ViewKeys::statisticsString() ); + + // registering the container of instance statistics groups (must be unique for this instance) + string const & ownerName = getOwnerName(); + GEOS_ERROR_IF_NE_MSG( meshStatsGroup->hasGroup( ownerName ), false, + GEOS_FMT( "A statistics aggregator have already been requested for '{}'.", + ownerName ), + m_ownerDataContext ); + meshStatsGroup->registerGroup( ownerName ); + } ); +} + +void StatsAggregator::enableRegionStatisticsAggregation() +{ + if( m_solver == nullptr || m_meshBodies == nullptr ) + return; + + integer regionCount = 0; + integer subRegionCount = 0; + + auto const registerStats = [=] ( Group & parent, + string const & targetName ) -> RegionStatistics & + { + return parent.registerGroup( targetName, + std::make_unique< RegionStatistics >( targetName, &parent, + m_numPhases, + m_numComponents ) ); + }; + + m_solver->forDiscretizationOnMeshTargets( *m_meshBodies, [&] ( string const &, + MeshLevel & mesh, + string_array const & regionNames ) + { + ElementRegionManager & elemManager = mesh.getElemManager(); + Group & statisticsGroup = getInstanceStatisticsGroup( mesh ); + RegionStatistics & meshRegionsStats = registerStats( statisticsGroup, + ViewKeys::regionsStatisticsString() ); + + for( size_t i = 0; i < regionNames.size(); ++i ) + { + CellElementRegion & region = elemManager.getRegion< CellElementRegion >( regionNames[i] ); + RegionStatistics & regionStats = registerStats( meshRegionsStats, + region.getName() ); + + region.forElementSubRegions< CellElementSubRegion >( [&] ( CellElementSubRegion & subRegion ) + { + registerStats( regionStats, + subRegion.getName() ); + ++subRegionCount; + } ); + ++regionCount; + } + } ); + + GEOS_ERROR_IF( regionCount == 0 || subRegionCount == 0, + GEOS_FMT( "Missing region for computing statistics:\n- {} regions,\n- {} sub-regions.", + getOwnerName(), regionCount, subRegionCount ), + m_ownerDataContext ); + + m_regionStatsState.m_isEnabled = true; + m_regionStatsState.m_isDirty = true; +} + +void StatsAggregator::enableCFLStatistics() +{ + if( m_solver == nullptr ) + return; + + m_solver->registerDataForCFL( *m_meshBodies ); + m_solver->forDiscretizationOnMeshTargets( *m_meshBodies, [&] ( string const &, + MeshLevel & mesh, + string_array const & ) + { + Group & statisticsGroup = getInstanceStatisticsGroup( mesh ); + statisticsGroup.registerGroup< CFLStatistics >( ViewKeys::cflStatisticsString() ); + } ); + + m_cflStatsState.m_isEnabled = true; + m_cflStatsState.m_isDirty = true; +} + +Group & StatsAggregator::getInstanceStatisticsGroup( MeshLevel & mesh ) const +{ + // considering everything is initialized, or else, crash gracefully + Group & meshStatsGroup = mesh.getGroup( ViewKeys::statisticsString() ); + Group & instanceStatisticsGroup = meshStatsGroup.getGroup( getOwnerName() ); + return instanceStatisticsGroup; +} + +RegionStatistics & StatsAggregator::getMeshRegionsStatistics( MeshLevel & mesh ) const +{ + // considering everything is initialized, or else, crash gracefully + Group & instanceStatisticsGroup = getInstanceStatisticsGroup( mesh ); + return instanceStatisticsGroup.getGroup< RegionStatistics >( ViewKeys::regionsStatisticsString() ); +} + +RegionStatistics & StatsAggregator::getRegionStatistics( MeshLevel & mesh, + string_view regionName ) const +{ + RegionStatistics & meshRegionsStats = getMeshRegionsStatistics( mesh ); + RegionStatistics * const stats = meshRegionsStats.getGroupPointer< RegionStatistics >( string( regionName ) ); + GEOS_THROW_IF( stats == nullptr, + GEOS_FMT( "Region '{}' not found to get region statistics, is it a target of the reservoir solver?\n" + "Available target regions:\n- {}", + regionName, stringutilities::join( meshRegionsStats.getSubGroupsNames(), "\n- " ) ), + InputError, m_ownerDataContext ); + return *stats; +} + +CFLStatistics & StatsAggregator::getCflStatisticsGroup( MeshLevel & mesh ) const +{ + // considering everything is initialized, or else, crash gracefully + Group & statisticsGroup = getInstanceStatisticsGroup( mesh ); + return statisticsGroup.getGroup< CFLStatistics >( ViewKeys::cflStatisticsString() ); +} + +void StatsAggregator::forRegionStatistics( RegionStatisticsFunctor< MeshLevel > const & func ) const +{ + m_solver->forDiscretizationOnMeshTargets( *m_meshBodies, [&] ( string const &, + MeshLevel & mesh, + string_array const & ) + { + RegionStatistics & meshRegionsStats = getMeshRegionsStatistics( mesh ); + + func( mesh, meshRegionsStats ); + } ); +} + +void StatsAggregator::forRegionStatistics( MeshLevel & mesh, + RegionStatistics & meshRegionsStatistics, + RegionStatisticsFunctor< CellElementRegion > const & func ) const +{ + ElementRegionManager & elemManager = mesh.getElemManager(); + meshRegionsStatistics.forSubGroups< RegionStatistics >( [&] ( RegionStatistics & regionStatistics ) + { + string_view targetName = regionStatistics.getTargetName(); + CellElementRegion & region = elemManager.getRegion< CellElementRegion >( string( targetName ) ); + + func( region, regionStatistics ); + } ); +} + +void StatsAggregator::forRegionStatistics( CellElementRegion & region, + RegionStatistics & regionStatistics, + RegionStatisticsFunctor< CellElementSubRegion > const & func ) const +{ + regionStatistics.forSubGroups< RegionStatistics >( [&] ( RegionStatistics & subRegionStatistics ) + { + string_view targetName = subRegionStatistics.getTargetName(); + CellElementSubRegion & subRegion = region.getSubRegion< CellElementSubRegion >( string( targetName ) ); + func( subRegion, subRegionStatistics ); + } ); +} + +bool StatsAggregator::isComputed( real64 const timeRequest, RegionStatistics const & stats ) +{ + real64 const timePrecisionScale = LvArray::math::max( LvArray::math::abs( timeRequest ), + LvArray::math::abs( stats.m_time ) ); + static constexpr real64 timeRelTol = 1.0e-12; + + return + !m_regionStatsState.m_isDirty && + LvArray::math::abs( timeRequest - stats.m_time ) < timeRelTol * timePrecisionScale; +} + +bool StatsAggregator::computeRegionsStatistics( real64 const timeRequest ) +{ + GEOS_MARK_FUNCTION; + + GEOS_LOG_RANK_0( GEOS_FMT( "Computing for {} at stack:{}", m_ownerDataContext.toString(), LvArray::system::stackTrace( true ) )); + // computation of sub region stats + forRegionStatistics( [&, timeRequest] ( MeshLevel & mesh, RegionStatistics & meshRegionsStats ) + { + forRegionStatistics( mesh, + meshRegionsStats, + [&, timeRequest] ( CellElementRegion & region, RegionStatistics & regionStats ) + { + forRegionStatistics( region, + regionStats, + [&, timeRequest] ( CellElementSubRegion & subRegion, RegionStatistics & subRegionStats ) + { + initStats( subRegionStats, timeRequest ); + computeSubRegionRankStats( subRegion, subRegionStats ); + GEOS_LOG_RANK_0( GEOS_FMT( "Computed {}: {} Pa / {} Pa / {} Pa", subRegionStats.getPath(), subRegionStats.m_minPressure, subRegionStats.m_averagePressure, subRegionStats.m_maxPressure )); + } ); + } ); + } ); + + // aggregation of computations from the sub regions + forRegionStatistics( [&, timeRequest] ( MeshLevel & mesh, RegionStatistics & meshRegionsStats ) + { + initStats( meshRegionsStats, timeRequest ); + + forRegionStatistics( mesh, + meshRegionsStats, + [&, timeRequest] ( CellElementRegion & region, RegionStatistics & regionStats ) + { + initStats( regionStats, timeRequest ); + + forRegionStatistics( region, + regionStats, + [&, timeRequest] ( CellElementSubRegion &, RegionStatistics & subRegionStats ) + { + aggregateStats( regionStats, subRegionStats ); + + mpiAggregateStats( subRegionStats ); + postAggregateStats( subRegionStats ); + GEOS_LOG_RANK_0( GEOS_FMT( "Aggregated {}: {} Pa / {} Pa / {} Pa", subRegionStats.getPath(), subRegionStats.m_minPressure, subRegionStats.m_averagePressure, subRegionStats.m_maxPressure )); + } ); + + aggregateStats( meshRegionsStats, regionStats ); + + mpiAggregateStats( regionStats ); + postAggregateStats( regionStats ); + GEOS_LOG_RANK_0( GEOS_FMT( "Aggregated {}: {} Pa / {} Pa / {} Pa", regionStats.getPath(), regionStats.m_minPressure, regionStats.m_averagePressure, regionStats.m_maxPressure )); + } ); + + mpiAggregateStats( meshRegionsStats ); + postAggregateStats( meshRegionsStats ); + GEOS_LOG_RANK_0( GEOS_FMT( "Aggregated {}: {} Pa / {} Pa / {} Pa", + meshRegionsStats.getPath(), meshRegionsStats.m_minPressure, meshRegionsStats.m_averagePressure, meshRegionsStats.m_maxPressure )); + } ); + + m_regionStatsState.m_isDirty = false; + + return true; +} + +void StatsAggregator::initStats( RegionStatistics & stats, real64 const time ) const +{ + 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_phaseDynamicPoreVolume.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 ); +} + +void StatsAggregator::computeSubRegionRankStats( CellElementSubRegion & subRegion, RegionStatistics & subRegionStats ) const +{ + 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(); + + isothermalCompositionalMultiphaseBaseKernels:: + StatisticsKernel:: + launch< parallelDevicePolicy<> >( subRegion.size(), + m_numComponents, + m_numPhases, + m_params.m_relpermThreshold, + elemGhostRank, + volume, + pres, + deltaPres, + temp, + refPorosity, + porosity, + phaseDensity, + phaseCompFraction, + phaseVolFrac, + phaseTrappedVolFrac, + phaseRelperm, + subRegionStats.m_minPressure, + subRegionStats.m_averagePressure, + subRegionStats.m_maxPressure, + subRegionStats.m_minDeltaPressure, + subRegionStats.m_maxDeltaPressure, + subRegionStats.m_minTemperature, + subRegionStats.m_averageTemperature, + subRegionStats.m_maxTemperature, + subRegionStats.m_totalUncompactedPoreVolume, + subRegionStats.m_phaseDynamicPoreVolume.toView(), + subRegionStats.m_phaseMass.toView(), + subRegionStats.m_trappedPhaseMass.toView(), + subRegionStats.m_immobilePhaseMass.toView(), + subRegionStats.m_componentMass.toView() ); +} + + +void StatsAggregator::aggregateStats( RegionStatistics & stats, RegionStatistics const & other ) const +{ + stats.m_averagePressure += other.m_averagePressure; + stats.m_minPressure = LvArray::math::min( stats.m_minPressure, other.m_minPressure ); + stats.m_maxPressure = LvArray::math::max( stats.m_maxPressure, other.m_maxPressure ); + + stats.m_minDeltaPressure = LvArray::math::min( stats.m_minDeltaPressure, other.m_minDeltaPressure ); + stats.m_maxDeltaPressure = LvArray::math::max( stats.m_maxDeltaPressure, other.m_maxDeltaPressure ); + + stats.m_averageTemperature += other.m_averageTemperature; + stats.m_minTemperature = LvArray::math::min( stats.m_minTemperature, other.m_minTemperature ); + stats.m_maxTemperature = LvArray::math::max( stats.m_maxTemperature, other.m_maxTemperature ); + + stats.m_totalUncompactedPoreVolume += other.m_totalUncompactedPoreVolume; + + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + stats.m_phaseDynamicPoreVolume[ip] += other.m_phaseDynamicPoreVolume[ip]; + stats.m_phaseMass[ip] += other.m_phaseMass[ip]; + stats.m_trappedPhaseMass[ip] += other.m_trappedPhaseMass[ip]; + stats.m_immobilePhaseMass[ip] += other.m_immobilePhaseMass[ip]; + + for( integer ic = 0; ic < m_numComponents; ++ic ) + { + stats.m_componentMass[ip][ic] += other.m_componentMass[ip][ic]; + } + } +} + +void StatsAggregator::mpiAggregateStats( RegionStatistics & stats ) const +{ + stats.m_averagePressure = MpiWrapper::sum( stats.m_averagePressure ); + 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_averageTemperature = MpiWrapper::sum( stats.m_averageTemperature ); + stats.m_minTemperature = MpiWrapper::min( stats.m_minTemperature ); + stats.m_maxTemperature = MpiWrapper::max( stats.m_maxTemperature ); + + stats.m_totalUncompactedPoreVolume = MpiWrapper::sum( stats.m_totalUncompactedPoreVolume ); + + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + stats.m_phaseDynamicPoreVolume[ip] = MpiWrapper::sum( stats.m_phaseDynamicPoreVolume[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] ); + + for( integer ic = 0; ic < m_numComponents; ++ic ) + { + stats.m_componentMass[ip][ic] = MpiWrapper::sum( stats.m_componentMass[ip][ic] ); + } + } +} + +void StatsAggregator::postAggregateStats( RegionStatistics & stats ) +{ + 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_warnings.emplace_back( GEOS_FMT( "Cannot compute average pressure for '{}' because pore volume is zero in '{}'.", + getOwnerName(), stats.getTargetName() ) ); + } + + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + stats.m_totalPoreVolume += stats.m_phaseDynamicPoreVolume[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]; + } +} + +bool StatsAggregator::computeCFLNumbers( real64 const time, + real64 const dt, + DomainPartition & domain ) +{ + GEOS_MARK_FUNCTION; + real64 maxPhaseCFL, maxCompCFL; + CFLStatistics * stats = getCFLStatistics( domain ); + + m_warnings.clear(); + + if( !m_cflStatsState.m_isEnabled ) + { + m_warnings.emplace_back( "CFL numbers computation is not enabled." ); + return false; + } + if( stats == nullptr ) + { + m_warnings.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; + + m_cflStatsState.m_isDirty = false; + + 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..9eba40f250d --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.hpp @@ -0,0 +1,349 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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/DataTypes.hpp" +#include "common/StdContainerWrappers.hpp" +#include "dataRepository/DataContext.hpp" +#include "dataRepository/Group.hpp" +#include "mesh/CellElementRegion.hpp" +#include "mesh/DomainPartition.hpp" +#include "mesh/MeshBody.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 (numerator value before postAggregateCompute()) + 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 (numerator value before postAggregateCompute()) + 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 dynamic pore volume + array1d< real64 > const m_phaseDynamicPoreVolume; + + /// region phase mass (trapped and non-trapped, immobile and mobile) + array1d< real64 > const m_phaseMass; + /// trapped region phase mass + array1d< real64 > const m_trappedPhaseMass; + /// non-trapped region phase mass (available after postAggregateCompute()) + array1d< real64 > const m_nonTrappedPhaseMass; + /// immobile region phase mass + array1d< real64 > const m_immobilePhaseMass; + /// mobile region phase mass (available after postAggregateCompute()) + array1d< real64 > const m_mobilePhaseMass; + /// region component mass + array2d< real64 > const 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 targetName name of the data-repository object that is targeted by the statistics + * (mesh level / region / sub-region). + * @param parent the instance parent in data-repository + * @param numPhases Fluid phase count + * @param numComponents Fluid component count + */ + RegionStatistics( string const & targetName, dataRepository::Group * const parent, + integer numPhases, integer numComponents ); + + RegionStatistics( RegionStatistics && ) = default; + + /** + * @return the name of the data-repository object that is targeted by the statistics + * (mesh level / region / sub-region). + */ + string_view getTargetName() const + { return getName(); } + +}; + +/** + * @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. + * @todo repair 1D HDF5 outputs to enable stats HDF5 outputs + */ +class StatsAggregator +{ +public: + + /** + * @brief the associated view keys + */ + struct ViewKeys + { + /// String for the discretization statistics group + constexpr static char const * statisticsString() { return "statistics"; } + /// String for the region statistics group + constexpr static char const * regionsStatisticsString() { return "regionsStatistics"; } + /// String for the cfl statistics group + constexpr static char const * cflStatisticsString() { return "cflStatistics"; } + }; + + /** + * @brief Standard function signature for any functor that applies on RegionStatistics instances + * param 0: TODO document + * param 1: TODO document + * @tparam OWNER_T + */ + template< typename OWNER_T > + using RegionStatisticsFunctor = std::function< void ( OWNER_T &, RegionStatistics & ) >; + + /** + * @brief Construct a new Stats Aggregator object + * @param ownerName the unique name of the entity requesting the statistics. + * An error is thrown if not unique in this context. + */ + StatsAggregator( dataRepository::DataContext const & ownerDataContext ); + + /** + * @brief Enable the computation of any statistics, initialize data structure to collect them. + * Register the resulting data wrappers so they will be targeted by TimeHistory output + * @param solver flow solver object to retrieve: + - the simulated regions, + - fields for statistics computation. + * @param meshBodies The Group containing the MeshBody objects + */ + void initStatisticsAggregation( dataRepository::Group & meshBodies, + CompositionalMultiphaseBase & solver ); + + /** + * @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 or after the "registerDataOnMesh" initialization phase + * @param meshBodies The Group containing the MeshBody objects + */ + void enableRegionStatisticsAggregation(); + + /** + * @brief Register the results structs & wrappers so they will be targeted by TimeHistory output + * @note Must be called in or after the "registerDataOnMesh" initialization phase + * @param meshBodies The Group containing the MeshBody objects + */ + void enableCFLStatistics(); + + void forRegionStatistics( RegionStatisticsFunctor< MeshLevel > const & functor ) const; + + void forRegionStatistics( MeshLevel & mesh, + RegionStatistics & meshRegionsStatistics, + RegionStatisticsFunctor< CellElementRegion > const & functor ) const; + + void forRegionStatistics( CellElementRegion & region, + RegionStatistics & regionStatistics, + RegionStatisticsFunctor< CellElementSubRegion > const & functor ) const; + + /** + * @param[in] timeRequest The time for which we want to know if the statistics are computed. + * @param[in] stats the statistics data structure we want to know if it has been computed + * @return true if the statistics have been computed. + */ + bool isComputed( real64 const timeRequest, RegionStatistics const & stats ); + + /** + * @brief Compute statistics on the mesh discretizations (average field pressure, etc) + * Results are reduced on rank 0, and broadcasted over all ranks. + * @param[in] timeRequest The time for which we want to compute the statistics. + * @return false if there was a problem that prevented the statistics to be computed correctly. + */ + bool computeRegionsStatistics( real64 const timeRequest ); + + /** + * @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 >( ViewKeys::cflStatisticsString() ); } + + CompositionalMultiphaseBase const * getSolver() const + { return m_solver; } + + /** + * @return The encountered issues during the last computing method call. + */ + stdVector< string > const & getWarnings() const + { return m_warnings; } + + /** + * @return the name of the entity that needs the statistics. + */ + string const & getOwnerName() const + { return m_ownerDataContext.getTargetName(); } + + integer getNumPhases() const + { return m_numPhases; } + + integer getNumComponents() const + { return m_numComponents; } + + dataRepository::Group & getInstanceStatisticsGroup( MeshLevel & mesh ) const; + + RegionStatistics & getMeshRegionsStatistics( MeshLevel & mesh ) const; + + /** + * @brief TODO + * @throw InputError if no statistics data is found for the given region name. + * @param mesh TODO + * @param regionNname TODO + * @return TODO + */ + RegionStatistics & getRegionStatistics( MeshLevel & mesh, string_view regionName ) const; + + CFLStatistics & getCflStatisticsGroup( MeshLevel & mesh ) const; + +private: + + struct StatsState { + bool m_isEnabled = false; + bool m_isDirty = false; + }; + + /// @see getOwnerName() + dataRepository::DataContext const & m_ownerDataContext; + + CompositionalMultiphaseBase * m_solver = nullptr; + + dataRepository::Group * m_meshBodies = nullptr; + + AggregatorParameters m_params; + + stdVector< string > m_warnings; + + StatsState m_regionStatsState; + + StatsState m_cflStatsState; + + integer m_numPhases; + + integer m_numComponents; + + /** + * @brief Initialize all statistics values to aggregable default values, + * before any computation / reduction for the current timestep. + * @param stats the statistics instance + * @param time start time of the current timestep (s) + */ + void initStats( RegionStatistics & stats, real64 time ) const; + + void computeSubRegionRankStats( CellElementSubRegion & subRegion, RegionStatistics & subRegionStats ) const; + + /** + * @brief Aggregate all instance statistics with those of another instance on the current rank. + * @param stats the statistics instance + * @param other the other instance to aggregate with. + */ + void aggregateStats( RegionStatistics & stats, RegionStatistics const & other ) const; + + /** + * @brief Aggregate all instance statistics with those of other ranks. + * @param stats the statistics instance + */ + void mpiAggregateStats( RegionStatistics & stats ) const; + + /** + * @brief Do the final computations for the statistics. Must be called after computations & aggregations. + * @param stats the statistics instance + */ + void postAggregateStats( RegionStatistics & stats ); + +}; + +} /* 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..7bf2d2de9f0 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsTask.cpp @@ -0,0 +1,440 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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 "common/logger/Logger.hpp" +#include "dataRepository/Group.hpp" +#include "mesh/CellElementRegion.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/CompositionalMultiphaseStatisticsAggregator.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( string const & 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(); + + GEOS_THROW_IF_EQ_MSG( m_solver, nullptr, + "To identify simulated regions, a solver must be provided.", + InputError /*, getWrapperDataContext( getSolverWrapperName() )*/ ); + + if( !dynamicCast< CompositionalMultiphaseBase * >( m_solver ) ) + { + GEOS_THROW( GEOS_FMT( "{} {}: incompatible solver selected, a compositional multiphase solver is expected", + catalogName(), getDataContext() ), + InputError ); + } + else 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 ); + } + + m_aggregator = std::make_unique< StatsAggregator >( getDataContext() ); +} + +void StatsTask::registerDataOnMesh( Group & meshBodies ) +{ + // for now, this guard is needed to avoid breaking the xml schema generation + if( m_solver == nullptr || m_aggregator == nullptr ) + return; + + prepareFluidMetaData(); + + if( m_computeRegionStatistics || m_computeCFLNumbers ) + { + // expected to work as check is done in postInputInitialization() + CompositionalMultiphaseBase * castedSolver = dynamicCast< CompositionalMultiphaseBase * >( m_solver ); + GEOS_ERROR_IF_EQ_MSG( castedSolver, nullptr, + GEOS_FMT( "{} {}: Unexpected error (solver pointer changed?)", catalogName(), getDataContext() ) ); + m_aggregator->initStatisticsAggregation( meshBodies, *castedSolver ); + } + else + { + GEOS_WARNING( GEOS_FMT( "{} {}: No computing option enabled, no output is scheduled.", + catalogName(), getDataContext() ) ); + } + + if( m_computeRegionStatistics ) + m_aggregator->enableRegionStatisticsAggregation(); + + // if we have to compute CFL numbers later, we need to register additional variables + if( m_computeCFLNumbers ) + m_aggregator->enableCFLStatistics(); + + m_aggregator->forRegionStatistics( [&] ( MeshLevel & mesh, RegionStatistics & ) + { + prepareLogTableLayouts( mesh.getName() ); + prepareCsvTableLayouts( mesh.getName() ); + } ); + // if( MpiWrapper::commRank() == 0 ) + // getGroupByPath( "/" ).printDataHierarchy(); +} + +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; + + GEOS_ERROR_IF( !m_aggregator, + "No statistics aggregator initialized!", getDataContext() ); + + m_aggregator->computeRegionsStatistics( statsTime ); + + m_aggregator->forRegionStatistics( [&] ( MeshLevel & mesh, RegionStatistics & meshRegionsStatistics ) + { + if( m_computeRegionStatistics ) + { + outputLogStats( statsTime, mesh, meshRegionsStatistics ); + outputCsvStats( statsTime, mesh, meshRegionsStatistics ); + } + } ); + + if( m_computeCFLNumbers ) + m_aggregator->computeCFLNumbers( statsTime, dt, domain ); + + return false; +} + +void StatsTask::outputLogStats( real64 const statsTime, + MeshLevel & mesh, + RegionStatistics & meshRegionsStatistics ) +{ + 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.getErrorsList().appendErrors( m_aggregator->getWarnings() ); + + tableData.addRow( "Statistics time", merge, merge, statsTime ); + + // lamda to apply for each region statistics + auto const outputRegionStats = [&] ( string_view targetName, RegionStatistics & stats ) + { + tableData.addSeparator(); + tableData.addRow( merge, merge, merge, "" ); + + tableData.addSeparator(); + tableData.addRow( merge, merge, merge, GEOS_FMT( "Region '{}'", targetName ) ); + tableData.addSeparator(); + 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 ), + "all", + 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_phaseDynamicPoreVolume, "\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' ) ); + }; + + // apply the lambda for each region and, finally, the mesh summary + m_aggregator->forRegionStatistics( mesh, meshRegionsStatistics, + [&] ( CellElementRegion & region, RegionStatistics & stats ) + { + outputRegionStats( region.getName(), stats ); + } ); + outputRegionStats( mesh.getName(), meshRegionsStatistics ); + + // output to log + GEOS_LOG_RANK_0( formatter.toString( tableData ) ); +} + +void StatsTask::outputCsvStats( real64 statsTime, + MeshLevel & mesh, + RegionStatistics & meshRegionsStatistics ) +{ + if( MpiWrapper::commRank() > 0 || m_writeCSV == 0 ) + return; + + auto const formatterIter = m_csvFormatters.find( mesh.getName() ); + if( formatterIter==m_csvFormatters.end()) + return; + + TableCSVFormatter const & formatter = *formatterIter->second; + TableData tableData; + + // lamda to apply for each region statistics + auto const outputRegionStats = [&] ( string_view targetName, RegionStatistics & stats ) + { + stdVector< string > row; + row.reserve( formatter.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 ), + string( targetName ), + 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_phaseDynamicPoreVolume ); + 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 + + tableData.addRow( row ); + }; + + // apply the lambda for each region and, finally, the mesh summary + m_aggregator->forRegionStatistics( mesh, meshRegionsStatistics, + [&] ( CellElementRegion & region, RegionStatistics & stats ) + { + outputRegionStats( region.getName(), stats ); + } ); + outputRegionStats( mesh.getName(), meshRegionsStatistics ); + + // append to csv file + std::ofstream outputFile( getCsvFileName( mesh.getName() ), std::ios_base::app ); + outputFile << formatter.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..9ebc7951224 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 "physicsSolvers/FieldStatisticsBase.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseStatisticsAggregator.hpp" +#include 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; + void registerDataOnMesh( Group & meshBodies ) 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 prepareFluidMetaData(); - /** - * @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 prepareLogTableLayouts( string_view tableName ); - void postInputInitialization() override; + void prepareCsvTableLayouts( string_view tableName ); - void registerDataOnMesh( Group & meshBodies ) override; + string getCsvFileName( string_view meshName ) const; + + void outputLogStats( real64 statsTime, + MeshLevel & mesh, + RegionStatistics & meshRegionsStatistics ); + + void outputCsvStats( real64 statsTime, + MeshLevel & mesh, + RegionStatistics & meshRegionsStatistics ); + + /// 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; + + // mesh statistics aggregator + std::unique_ptr< 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..3bc8543e5bb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -19,19 +19,23 @@ #include "CompositionalMultiphaseWell.hpp" +#include "LvArray/src/system.hpp" #include "codingUtilities/Utilities.hpp" #include "common/DataTypes.hpp" #include "common/TimingMacros.hpp" +#include "common/logger/Logger.hpp" #include "constitutive/ConstitutiveManager.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" #include "dataRepository/Group.hpp" #include "mesh/DomainPartition.hpp" +#include "mesh/MeshBody.hpp" #include "mesh/PerforationFields.hpp" #include "mesh/WellElementSubRegion.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/LogLevelsInfo.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp" #include "physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellFields.hpp" @@ -48,7 +52,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" @@ -60,6 +64,19 @@ namespace geos using namespace dataRepository; using namespace constitutive; using namespace fields; +using namespace compositionalMultiphaseStatistics; + +CompositionalMultiphaseBase & getFlowSolver( CompositionalMultiphaseWell & wellSolver ) +{ + // TODO: change the way we access the flowSolver here + return wellSolver.getParent().getGroup< CompositionalMultiphaseBase >( wellSolver.getFlowSolverName() ); +} + +CompositionalMultiphaseBase const & getFlowSolver( CompositionalMultiphaseWell const & wellSolver ) +{ + // TODO: change the way we access the flowSolver here + return wellSolver.getParent().getGroup< CompositionalMultiphaseBase >( wellSolver.getFlowSolverName() ); +} CompositionalMultiphaseWell::CompositionalMultiphaseWell( const string & name, Group * const parent ) @@ -140,6 +157,7 @@ void CompositionalMultiphaseWell::postInputInitialization() void CompositionalMultiphaseWell::registerDataOnMesh( Group & meshBodies ) { WellSolverBase::registerDataOnMesh( meshBodies ); + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::registerDataOnMesh" ); DomainPartition const & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" ); ConstitutiveManager const & cm = domain.getConstitutiveManager(); @@ -343,6 +361,7 @@ void compareMulticomponentModels( MODEL1_TYPE const & lhs, MODEL2_TYPE const & r void CompositionalMultiphaseWell::validateWellControlsForFluid( WellControls const & wellControls, MultiFluidBase const & fluid ) const { + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::validateWellControlsForFluid" ); if( wellControls.useSurfaceConditions() ) { try @@ -364,9 +383,10 @@ void CompositionalMultiphaseWell::validateWellControlsForFluid( WellControls con void CompositionalMultiphaseWell::validateConstitutiveModels( DomainPartition const & domain ) const { GEOS_MARK_FUNCTION; + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::validateConstitutiveModels" ); ConstitutiveManager const & cm = domain.getConstitutiveManager(); - CompositionalMultiphaseBase const & flowSolver = getParent().getGroup< CompositionalMultiphaseBase >( getFlowSolverName() ); + CompositionalMultiphaseBase const & flowSolver = getFlowSolver( *this ); string const referenceFluidName = flowSolver.referenceFluidModelName(); MultiFluidBase const & referenceFluid = cm.getConstitutiveRelation< MultiFluidBase >( m_referenceFluidModelName ); @@ -393,6 +413,7 @@ void CompositionalMultiphaseWell::validateConstitutiveModels( DomainPartition co void CompositionalMultiphaseWell::validateInjectionStreams( WellElementSubRegion const & subRegion ) const { WellControls const & wellControls = getWellControls( subRegion ); + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::validateInjectionStreams" ); // check well injection stream for injectors if( wellControls.isInjector()) @@ -430,34 +451,21 @@ void CompositionalMultiphaseWell::validateInjectionStreams( WellElementSubRegion void CompositionalMultiphaseWell::validateWellConstraints( real64 const & time_n, real64 const & GEOS_UNUSED_PARAM( dt ), + Group &, // TODO: remove ? + MeshBody &, // TODO: remove ? WellElementSubRegion const & subRegion ) { + GEOS_LOG_RANK_0( GEOS_FMT( " ---------------------> CompositionalMultiphaseWell::validateWellConstraints\n{}", LvArray::system::stackTrace( true ) ) ); WellControls & wellControls = getWellControls( subRegion ); - if( !wellControls.useSurfaceConditions() ) - { - bool const useSeg =wellControls.referenceReservoirRegion().empty(); - GEOS_WARNING_IF( useSeg, - "WellControls " <( getFlowSolverName() ); - string_array const & targetRegionsNames = flowSolver.getTargetRegionNames(); - auto const pos = std::find( targetRegionsNames.begin(), targetRegionsNames.end(), regionName ); - GEOS_ERROR_IF( pos == targetRegionsNames.end(), - GEOS_FMT( "{}: Region {} is not a target of the reservoir solver and cannot be used for referenceReservoirRegion in WellControl {}.", - getDataContext(), regionName, wellControls.getName() ) ); - - } + string_view refRegionName = wellControls.referenceReservoirRegion(); + bool const useSegmentValues = refRegionName.empty(); + if( useSegmentValues ) + { + GEOS_WARNING( "WellControls " << WellControls::viewKeyStruct::referenceReservoirRegionString() << + " not set and well constraint fluid property calculations will use top segement pressure and temp " ); } + string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString()); MultiFluidBase const & fluid = subRegion.getConstitutiveModel< MultiFluidBase >( fluidName ); @@ -524,6 +532,7 @@ void CompositionalMultiphaseWell::initializePostSubGroups() { WellSolverBase::initializePostSubGroups(); + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::initializePostSubGroups" ); DomainPartition & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" ); validateConstitutiveModels( domain ); @@ -542,12 +551,14 @@ void CompositionalMultiphaseWell::initializePostSubGroups() void CompositionalMultiphaseWell::initializePostInitialConditionsPreSubGroups() { + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::mmSIMULAParavie" ); WellSolverBase::initializePostInitialConditionsPreSubGroups(); createSeparator(); } void CompositionalMultiphaseWell::postRestartInitialization() { + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::postRestartInitialization" ); DomainPartition & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" ); forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, @@ -674,10 +685,11 @@ void CompositionalMultiphaseWell::updateBHPForConstraint( WellElementSubRegion & } -void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionManager const & elemManager, WellElementSubRegion const & subRegion ) +void CompositionalMultiphaseWell::updateVolRatesForConstraint( WellElementSubRegion const & subRegion ) { GEOS_MARK_FUNCTION; + GEOS_LOG_RANK_0( GEOS_FMT( " ---------------------> CompositionalMultiphaseWell::updateVolRatesForConstraint\n{}", LvArray::system::stackTrace( true ) ) ); // the rank that owns the reference well element is responsible for the calculations below. if( !subRegion.isLocallyOwned() ) { @@ -692,9 +704,6 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana WellControls & wellControls = getWellControls( subRegion ); // subRegion data - - arrayView1d< real64 const > const & pres = subRegion.getField< well::pressure >(); - arrayView1d< real64 const > const & temp = subRegion.getField< well::temperature >(); arrayView1d< real64 const > const & connRate = subRegion.getField< well::mixtureConnectionRate >(); arrayView2d< real64 const, compflow::USD_COMP > const & compFrac = subRegion.getField< well::globalCompFraction >(); @@ -719,45 +728,8 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana string const massUnit = m_useMass ? "kg" : "mol"; integer const useSurfaceConditions = wellControls.useSurfaceConditions(); - real64 flashPressure; - real64 flashTemperature; - if( useSurfaceConditions ) - { - // use surface conditions - flashPressure = wellControls.getSurfacePressure(); - flashTemperature = wellControls.getSurfaceTemperature(); - } - 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() )); - } - // 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 ) - { - // region name not set, use segment conditions - flashPressure = pres[iwelemRef]; - flashTemperature = temp[iwelemRef]; - } - else - { - // use reservoir region averages - flashTemperature = wellControls.getRegionAverageTemperature(); - } - } + FlashConditions const flashConditions = getFlashConditions( subRegion ); + arrayView1d< real64 > const & currentPhaseVolRate = wellControls.getReference< array1d< real64 > >( CompositionalMultiphaseWell::viewKeyStruct::currentPhaseVolRateString() ); arrayView2d< real64 > const & dCurrentPhaseVolRate = @@ -787,8 +759,6 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana forAll< serialPolicy >( 1, [&numComp, &numPhase, fluidSeparatorWrapper, - pres, - temp, compFrac, dCompFrac_dCompDens, connRate, @@ -800,8 +770,7 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana dPhaseFrac, logSurfaceCondition, &useSurfaceConditions, - &flashPressure, - &flashTemperature, + &flashConditions, ¤tTotalVolRate, dCurrentTotalVolRate, currentPhaseVolRate, @@ -824,11 +793,13 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana if( useSurfaceConditions ) { // we need to compute the surface density - fluidSeparatorWrapper.update( iwelemRef, 0, flashPressure, flashTemperature, compFrac[iwelemRef] ); + fluidSeparatorWrapper.update( iwelemRef, 0, + flashConditions.pressure, flashConditions.temperature, + compFrac[iwelemRef] ); if( logSurfaceCondition ) { GEOS_LOG_RANK( GEOS_FMT( "{}: surface density computed with P_surface = {} Pa and T_surface = {} K", - wellControlsName, flashPressure, flashTemperature ) ); + wellControlsName, flashConditions.pressure, flashConditions.temperature ) ); } #ifdef GEOS_USE_HIP GEOS_UNUSED_VAR( wellControlsName ); @@ -837,7 +808,9 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana } else { - fluidSeparatorWrapper.update( iwelemRef, 0, flashPressure, flashTemperature, compFrac[iwelemRef] ); + fluidSeparatorWrapper.update( iwelemRef, 0, + flashConditions.pressure, flashConditions.temperature, + compFrac[iwelemRef] ); } // Step 2: update the total volume rate @@ -926,7 +899,91 @@ void CompositionalMultiphaseWell::updateVolRatesForConstraint( ElementRegionMana } ); } +void CompositionalMultiphaseWell::precomputeFlashConditions( real64 const time_n, + Group & meshBodies, + MeshBody & meshBody, + WellElementSubRegion const & subRegion ) +{ + WellControls & wellControls = getWellControls( subRegion ); + integer const useSurfaceConditions = wellControls.useSurfaceConditions(); + if( !useSurfaceConditions ) + { + string_view refRegionName = wellControls.referenceReservoirRegion(); + bool const useSegmentValues = refRegionName.empty(); + if( useSegmentValues ) + { + wellControls.setRegionAveragePressure( -1 ); + wellControls.setRegionAverageTemperature( -1 ); + } + else + { + auto & flowSolver = getParent().getGroup< CompositionalMultiphaseBase >( getFlowSolverName() ); + MeshLevel & flowMeshLevel = meshBody.getMeshLevel( flowSolver.getDiscretizationName() ); + + if( !m_reservoirStatsAggregator ) + { // lazily initialize the region statistics aggregator + m_reservoirStatsAggregator = std::make_unique< StatsAggregator >( wellControls.getDataContext() ); + m_reservoirStatsAggregator->initStatisticsAggregation( meshBodies, flowSolver ); + m_reservoirStatsAggregator->enableRegionStatisticsAggregation(); + } + + RegionStatistics & stats = m_reservoirStatsAggregator->getRegionStatistics( flowMeshLevel, refRegionName ); + + // compute region stats only if needed (could have already been done for another subRegion) + if( !m_reservoirStatsAggregator->isComputed( time_n, stats ) ) + m_reservoirStatsAggregator->computeRegionsStatistics( time_n ); + GEOS_LOG( GEOS_FMT( "Accessing {}: {} Pa / {} Pa / {} Pa", stats.getPath(), stats.m_minPressure, stats.m_averagePressure, stats.m_maxPressure )); + + GEOS_WARNING_IF( stats.m_averagePressure <= 0.0, + GEOS_FMT( "No region average quantities computed in reference region '{}'.", + wellControls.referenceReservoirRegion() ), + wellControls.getWrapperDataContext( WellControls::viewKeyStruct::referenceReservoirRegionString() ), + getDataContext() ); + + wellControls.setRegionAveragePressure( stats.m_averagePressure ); + wellControls.setRegionAverageTemperature( stats.m_averageTemperature ); + } + } +} + +CompositionalMultiphaseWell::FlashConditions +CompositionalMultiphaseWell::getFlashConditions( WellElementSubRegion const & subRegion ) +{ + WellControls & wellControls = getWellControls( subRegion ); + integer const useSurfaceConditions = wellControls.useSurfaceConditions(); + if( useSurfaceConditions ) + { + // use surface conditions + return { + /* .pressure = */ wellControls.getSurfacePressure(), + /* .temperature = */ wellControls.getSurfaceTemperature(), + }; + } + else + { + if( wellControls.getRegionAveragePressure() > 0.0 && wellControls.getRegionAverageTemperature() > 0.0 ) + { // reference region condition properly computed, we can return them + return { + /* .pressure = */ wellControls.getRegionAveragePressure(), + /* .temperature = */ wellControls.getRegionAverageTemperature(), + }; + } + else + { // region average stats not initialized or initialized, fallback to top segment values + GEOS_WARNING( "CompositionalMultiphaseWell: region average stats not initialized," + " fallback to top segment values" ); // TODO: re-redact + + arrayView1d< real64 const > const & pres = subRegion.getField< well::pressure >(); + arrayView1d< real64 const > const & temp = subRegion.getField< well::temperature >(); + localIndex const iwelemRef = subRegion.getTopWellElementIndex(); + return { + /* .pressure = */ pres[iwelemRef], + /* .temperature = */ temp[iwelemRef], + }; + } + } +} void CompositionalMultiphaseWell::updateFluidModel( WellElementSubRegion & subRegion ) { @@ -1018,7 +1075,7 @@ void CompositionalMultiphaseWell::updateState( DomainPartition & domain ) WellControls & wellControls = getWellControls( subRegion ); if( wellControls.getWellStatus() == WellControls::Status::OPEN ) { - real64 const maxRegionPhaseVolFrac = updateSubRegionState( elemManager, subRegion ); + real64 const maxRegionPhaseVolFrac = updateSubRegionState( subRegion ); maxPhaseVolFrac = LvArray::math::max( maxRegionPhaseVolFrac, maxPhaseVolFrac ); } } ); @@ -1031,14 +1088,14 @@ void CompositionalMultiphaseWell::updateState( DomainPartition & domain ) } -real64 CompositionalMultiphaseWell::updateSubRegionState( ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ) +real64 CompositionalMultiphaseWell::updateSubRegionState( WellElementSubRegion & subRegion ) { // update properties updateGlobalComponentFraction( subRegion ); // update volumetric rates for the well constraints // note: this must be called before updateFluidModel - updateVolRatesForConstraint( elemManager, subRegion ); + updateVolRatesForConstraint( subRegion ); // update densities, phase fractions, phase volume fractions @@ -1053,20 +1110,22 @@ real64 CompositionalMultiphaseWell::updateSubRegionState( ElementRegionManager c void CompositionalMultiphaseWell::initializeWells( DomainPartition & domain, real64 const & time_n ) { GEOS_MARK_FUNCTION; + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::initializeWells" ); integer const numComp = m_numComponents; integer const numPhase = m_numPhases; - // TODO: change the way we access the flowSolver here - CompositionalMultiphaseBase const & flowSolver = getParent().getGroup< CompositionalMultiphaseBase >( getFlowSolverName() ); + Group & meshBodies = domain.getMeshBodies(); + CompositionalMultiphaseBase const & flowSolver = getFlowSolver( *this ); // loop over the wells - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, + forDiscretizationOnMeshTargets( meshBodies, [&] ( string const & meshBodyName, MeshLevel & mesh, string_array const & regionNames ) { - + MeshBody & meshBody = domain.getMeshBody(meshBodyName); ElementRegionManager & elemManager = mesh.getElemManager(); + compositionalMultiphaseWellKernels::PresTempCompFracInitializationKernel::CompFlowAccessors resCompFlowAccessors( mesh.getElemManager(), flowSolver.getName() ); compositionalMultiphaseWellKernels::PresTempCompFracInitializationKernel::MultiFluidAccessors @@ -1156,7 +1215,8 @@ void CompositionalMultiphaseWell::initializeWells( DomainPartition & domain, rea wellElemCompDens ); // 5) Recompute the pressure-dependent properties - updateSubRegionState( elemManager, subRegion ); + precomputeFlashConditions(time_n, meshBodies, meshBody, subRegion); + updateSubRegionState( subRegion ); // 6) Estimate the well rates // TODO: initialize rates using perforation rates @@ -1736,7 +1796,7 @@ void CompositionalMultiphaseWell::computePerforationRates( real64 const & time_n { // TODO: change the way we access the flowSolver here - CompositionalMultiphaseBase const & flowSolver = getParent().getGroup< CompositionalMultiphaseBase >( getFlowSolverName() ); + CompositionalMultiphaseBase const & flowSolver = getFlowSolver( *this ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< WellElementSubRegion >( regionNames, [&]( localIndex const, @@ -1962,7 +2022,7 @@ void CompositionalMultiphaseWell::resetStateToBeginningOfStep( DomainPartition & if( wellControls.isWellOpen( ) ) { - updateSubRegionState( elemManager, subRegion ); + updateSubRegionState( subRegion ); } } ); } ); @@ -2098,13 +2158,15 @@ void CompositionalMultiphaseWell::implicitStepSetup( real64 const & time_n, real64 const & dt, DomainPartition & domain ) { + GEOS_LOG_RANK_0( " --------> CompositionalMultiphaseWell::implicitStepSetup" ); WellSolverBase::implicitStepSetup( time_n, dt, domain ); - forDiscretizationOnMeshTargets ( domain.getMeshBodies(), [&] ( string const &, - MeshLevel & mesh, - string_array const & regionNames ) + Group & meshBodies = domain.getMeshBodies(); + forDiscretizationOnMeshTargets ( meshBodies, [&] ( string const & meshBodyName, + MeshLevel & mesh, + string_array const & regionNames ) { - + MeshBody & meshBody = domain.getMeshBody( meshBodyName ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< WellElementSubRegion >( regionNames, @@ -2154,9 +2216,9 @@ void CompositionalMultiphaseWell::implicitStepSetup( real64 const & time_n, MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); fluid.saveConvergedState(); - validateWellConstraints( time_n, dt, subRegion ); + validateWellConstraints( time_n, dt, meshBodies, meshBody, subRegion ); - updateSubRegionState( elemManager, subRegion ); + updateSubRegionState( subRegion ); } } ) ; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.hpp index cb8ed9f1a6f..6e8d6d10cff 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.hpp @@ -20,8 +20,10 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_COMPOSITIONALMULTIPHASEWELL_HPP_ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_COMPOSITIONALMULTIPHASEWELL_HPP_ +#include "common/DataTypes.hpp" #include "constitutive/fluid/multifluid/Layouts.hpp" #include "constitutive/relativePermeability/Layouts.hpp" +#include "mesh/MeshLevel.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBase.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp" @@ -34,6 +36,11 @@ class ConstitutiveManager; class MultiFluidBase; } +namespace compositionalMultiphaseStatistics +{ +class StatsAggregator; +} + /** * @class CompositionalMultiphaseWell * @@ -143,7 +150,7 @@ class CompositionalMultiphaseWell : public WellSolverBase * @param elemManager the well region manager containing the well * @param subRegion the well subregion containing all the primary and dependent fields */ - void updateVolRatesForConstraint( ElementRegionManager const & elemManager, WellElementSubRegion const & subRegion ); + void updateVolRatesForConstraint( WellElementSubRegion const & subRegion ); /** * @brief Recompute the current BHP pressure @@ -185,7 +192,7 @@ class CompositionalMultiphaseWell : public WellSolverBase */ virtual void updateState( DomainPartition & domain ) override; - virtual real64 updateSubRegionState( ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ) override; + virtual real64 updateSubRegionState( WellElementSubRegion & subRegion ) override; virtual string wellElementDofName() const override { return viewKeyStruct::dofFieldString(); } @@ -345,6 +352,8 @@ class CompositionalMultiphaseWell : public WellSolverBase */ virtual void validateWellConstraints( real64 const & time_n, real64 const & dt, + Group & meshBodies, + MeshBody & meshBody, WellElementSubRegion const & subRegion ) override; /** @@ -358,6 +367,12 @@ class CompositionalMultiphaseWell : public WellSolverBase private: + struct FlashConditions + { + real64 pressure; + real64 temperature; + }; + /** * @brief Initialize all the primary and secondary variables in all the wells * @param domain the domain containing the well manager to access individual wells @@ -366,7 +381,12 @@ class CompositionalMultiphaseWell : public WellSolverBase virtual void setConstitutiveNames( ElementSubRegionBase & subRegion ) const override; + void precomputeFlashConditions( real64 time_n, + Group & meshBodies, + MeshBody & meshBody, + WellElementSubRegion const & subRegion ); + FlashConditions getFlashConditions( WellElementSubRegion const & subRegion ); /// flag indicating whether mass or molar formulation should be used integer m_useMass; @@ -398,6 +418,8 @@ class CompositionalMultiphaseWell : public WellSolverBase /// index of the target phase, used to impose the phase rate constraint localIndex m_targetPhaseIndex; + /// optional statistics aggregator to get the average pressure of simulated region + std::unique_ptr< compositionalMultiphaseStatistics::StatsAggregator > m_reservoirStatsAggregator; }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index 54716e387d4..4e99fbf9145 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -27,6 +27,7 @@ #include "constitutive/fluid/singlefluid/SingleFluidSelector.hpp" #include "dataRepository/Group.hpp" #include "mesh/DomainPartition.hpp" +#include "mesh/ElementRegionManager.hpp" #include "mesh/WellElementSubRegion.hpp" #include "mesh/PerforationFields.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" @@ -53,6 +54,18 @@ using namespace constitutive; using namespace fields; using namespace singlePhaseWellKernels; +SinglePhaseBase & getFlowSolver( SinglePhaseWell & wellSolver ) +{ + // TODO: change the way we access the flowSolver here + return wellSolver.getParent().getGroup< SinglePhaseBase >( wellSolver.getFlowSolverName() ); +} + +SinglePhaseBase const & getFlowSolver( SinglePhaseWell const & wellSolver ) +{ + // TODO: change the way we access the flowSolver here + return wellSolver.getParent().getGroup< SinglePhaseBase >( wellSolver.getFlowSolverName() ); +} + SinglePhaseWell::SinglePhaseWell( const string & name, Group * const parent ): WellSolverBase( name, parent ) @@ -140,6 +153,8 @@ string SinglePhaseWell::resElementDofName() const void SinglePhaseWell::validateWellConstraints( real64 const & time_n, real64 const & GEOS_UNUSED_PARAM( dt ), + Group & GEOS_UNUSED_PARAM( meshBodies ), + MeshBody & GEOS_UNUSED_PARAM( meshBody ), WellElementSubRegion const & subRegion ) { WellControls & wellControls = getWellControls( subRegion ); @@ -156,7 +171,7 @@ void SinglePhaseWell::validateWellConstraints( real64 const & time_n, { // Check if region name exists in list of Reservoir's target regions string const regionName = wellControls.referenceReservoirRegion(); - SinglePhaseBase const & flowSolver = getParent().getGroup< SinglePhaseBase >( getFlowSolverName() ); + SinglePhaseBase const & flowSolver = getFlowSolver( *this ); string_array const & targetRegionsNames = flowSolver.getTargetRegionNames(); auto const pos = std::find( targetRegionsNames.begin(), targetRegionsNames.end(), regionName ); GEOS_ERROR_IF( pos == targetRegionsNames.end(), @@ -251,7 +266,7 @@ void SinglePhaseWell::updateBHPForConstraint( WellElementSubRegion & subRegion ) } -void SinglePhaseWell::updateVolRateForConstraint( ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ) +void SinglePhaseWell::updateVolRateForConstraint( WellElementSubRegion & subRegion ) { GEOS_MARK_FUNCTION; @@ -294,18 +309,19 @@ void SinglePhaseWell::updateVolRateForConstraint( ElementRegionManager const & e { if( !wellControls.referenceReservoirRegion().empty() ) { - ElementRegionBase const & region = elemManager.getRegion( wellControls.referenceReservoirRegion() ); - GEOS_ERROR_IF ( !region.hasWrapper( SinglePhaseStatistics::regionStatisticsName()), - GEOS_FMT( "{}: WellControl {} referenceReservoirRegion field requires SinglePhaseStatistics to be configured for region {} ", - getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() ) ); - - SinglePhaseStatistics::RegionStatistics const & stats = region.getReference< SinglePhaseStatistics::RegionStatistics >( SinglePhaseStatistics::regionStatisticsName() ); - GEOS_ERROR_IF( stats.averagePressure <= 0.0, - GEOS_FMT( - "{}: No region average quantities computed. WellControl {} referenceReservoirRegion field requires SinglePhaseStatistics to be configured for region {} ", - getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() )); - wellControls.setRegionAveragePressure( stats.averagePressure ); - wellControls.setRegionAverageTemperature( stats.averageTemperature ); + // ElementRegionManager const & elemManager = mesh.getElemManager(); + // ElementRegionBase const & region = elemManager.getRegion( wellControls.referenceReservoirRegion() ); + // GEOS_ERROR_IF ( !region.hasWrapper( SinglePhaseStatistics::regionStatisticsName()), + // GEOS_FMT( "{}: WellControl {} referenceReservoirRegion field requires SinglePhaseStatistics to be configured for region {} ", + // getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() ) ); + + // SinglePhaseStatistics::RegionStatistics const & stats = region.getReference< SinglePhaseStatistics::RegionStatistics >( SinglePhaseStatistics::regionStatisticsName() ); + // GEOS_ERROR_IF( stats.averagePressure <= 0.0, + // GEOS_FMT( + // "{}: No region average quantities computed. WellControl {} referenceReservoirRegion field requires SinglePhaseStatistics to be configured for region {} ", + // getDataContext(), wellControls.getName(), wellControls.referenceReservoirRegion() )); + // wellControls.setRegionAveragePressure( stats.averagePressure ); + // wellControls.setRegionAverageTemperature( stats.averageTemperature ); } // use region conditions flashPressure = wellControls.getRegionAveragePressure(); @@ -405,11 +421,11 @@ void SinglePhaseWell::updateFluidModel( WellElementSubRegion & subRegion ) const } ); } -real64 SinglePhaseWell::updateSubRegionState( ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ) +real64 SinglePhaseWell::updateSubRegionState( WellElementSubRegion & subRegion ) { // update volumetric rates for the well constraints // Warning! This must be called before updating the fluid model - updateVolRateForConstraint( elemManager, subRegion ); + updateVolRateForConstraint( subRegion ); // update density in the well elements updateFluidModel( subRegion ); @@ -467,7 +483,7 @@ void SinglePhaseWell::initializeWells( DomainPartition & domain, real64 const & if( wellControls.isWellOpen() && !hasNonZeroRate ) { // TODO: change the way we access the flowSolver here - SinglePhaseBase const & flowSolver = getParent().getGroup< SinglePhaseBase >( getFlowSolverName() ); + SinglePhaseBase const & flowSolver = getFlowSolver( *this ); PresTempInitializationKernel::SinglePhaseFlowAccessors resSinglePhaseFlowAccessors( meshLevel.getElemManager(), flowSolver.getName() ); PresTempInitializationKernel::SingleFluidAccessors resSingleFluidAccessors( meshLevel.getElemManager(), flowSolver.getName() ); @@ -495,7 +511,7 @@ void SinglePhaseWell::initializeWells( DomainPartition & domain, real64 const & // 4) Recompute the pressure-dependent properties // Note: I am leaving that here because I would like to use the perforationRates (computed in UpdateState) // to better initialize the rates - updateSubRegionState( elemManager, subRegion ); + updateSubRegionState( subRegion ); string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); SingleFluidBase & fluid = subRegion.getConstitutiveModel< SingleFluidBase >( fluidName ); @@ -839,7 +855,7 @@ void SinglePhaseWell::computePerforationRates( real64 const & time_n, { // TODO: change the way we access the flowSolver here - SinglePhaseBase const & flowSolver = getParent().getGroup< SinglePhaseBase >( getFlowSolverName() ); + SinglePhaseBase const & flowSolver = getFlowSolver( *this ); PerforationKernel::SinglePhaseFlowAccessors resSinglePhaseFlowAccessors( mesh.getElemManager(), flowSolver.getName() ); PerforationKernel::SingleFluidAccessors resSingleFluidAccessors( mesh.getElemManager(), flowSolver.getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); @@ -1156,7 +1172,7 @@ void SinglePhaseWell::resetStateToBeginningOfStep( DomainPartition & domain ) subRegion.getField< well::connectionRate_n >(); connRate.setValues< parallelDevicePolicy<> >( connRate_n ); - updateSubRegionState( elemManager, subRegion ); + updateSubRegionState( subRegion ); } ); } ); } @@ -1168,11 +1184,12 @@ void SinglePhaseWell::implicitStepSetup( real64 const & time, { WellSolverBase::implicitStepSetup( time, dt, domain ); - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, - MeshLevel & mesh, - string_array const & regionNames ) + Group & meshBodies = domain.getMeshBodies(); + forDiscretizationOnMeshTargets( meshBodies, [&] ( string const & meshBodyName, + MeshLevel & mesh, + string_array const & regionNames ) { - + MeshBody & meshBody = domain.getMeshBody( meshBodyName ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< WellElementSubRegion >( regionNames, [&]( localIndex const, @@ -1196,9 +1213,9 @@ void SinglePhaseWell::implicitStepSetup( real64 const & time, getConstitutiveModel< SingleFluidBase >( subRegion, subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ) ); fluid.saveConvergedState(); - validateWellConstraints( time, dt, subRegion ); + validateWellConstraints( time, dt, meshBodies, meshBody, subRegion ); - updateSubRegionState( elemManager, subRegion ); + updateSubRegionState( subRegion ); } ); } ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp index 8c07e223fb7..5c4fffe466b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp @@ -143,7 +143,7 @@ class SinglePhaseWell : public WellSolverBase * @param elemManager the well region manager * @param subRegion the well subregion containing all the primary and dependent fields */ - virtual void updateVolRateForConstraint( ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ); + virtual void updateVolRateForConstraint( WellElementSubRegion & subRegion ); /** * @brief Recompute the BHP pressure that is used in the well constraints @@ -169,7 +169,7 @@ class SinglePhaseWell : public WellSolverBase * @param elemManager the elemManager containing the well * @param subRegion the well subRegion containing the well elements and their associated fields */ - virtual real64 updateSubRegionState( ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ) override; + virtual real64 updateSubRegionState( WellElementSubRegion & subRegion ) override; /** * @brief function to assemble the linear system matrix and rhs @@ -295,6 +295,8 @@ class SinglePhaseWell : public WellSolverBase */ virtual void validateWellConstraints( real64 const & time_n, real64 const & dt, + Group & meshBodies, + MeshBody & meshBody, WellElementSubRegion const & subRegion ) override; }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellControls.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellControls.hpp index 301c3c42f7c..a85e2868941 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellControls.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellControls.hpp @@ -252,7 +252,7 @@ class WellControls : public dataRepository::Group * @brief Getter for the reservoir region associated with reservoir volume constraint * @return name of reservoir region */ - string referenceReservoirRegion() const { return m_referenceReservoirRegion; } + string const & referenceReservoirRegion() const { return m_referenceReservoirRegion; } /** * @brief Getter for the surface pressure when m_useSurfaceConditions == 1 @@ -316,12 +316,14 @@ class WellControls : public dataRepository::Group /** * @brief Getter for the reservoir average pressure when m_useSurfaceConditions == 0 + * @note When not available, value is less or equal to 0.0. * @return the pressure */ real64 getRegionAveragePressure() const { return m_regionAveragePressure; } /** * @brief Set the reservoir average pressure when m_useSurfaceConditions == 0 + * @note When not available, value is less or equal to 0.0. * @param[in] regionAveragePressure value for pressure */ void setRegionAveragePressure( real64 regionAveragePressure ) { m_regionAveragePressure = regionAveragePressure; } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp index a76a66c2c72..dacc4420bd4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp @@ -19,7 +19,9 @@ #include "WellSolverBase.hpp" +#include "dataRepository/Group.hpp" #include "mesh/DomainPartition.hpp" +#include "mesh/MeshBody.hpp" #include "mesh/PerforationFields.hpp" #include "mesh/WellElementRegion.hpp" #include "mesh/WellElementSubRegion.hpp" @@ -151,16 +153,18 @@ void WellSolverBase::initializePostSubGroups() { DomainPartition & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" ); FunctionManager & functionManager = FunctionManager::getInstance(); - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, - MeshLevel & mesh, - string_array const & regionNames ) + Group & meshBodies = domain.getMeshBodies(); + forDiscretizationOnMeshTargets( meshBodies, [&] ( string const & meshBodyName, + MeshLevel & mesh, + string_array const & regionNames ) { + MeshBody & meshBody = domain.getMeshBody( meshBodyName ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< WellElementSubRegion >( regionNames, [&]( localIndex const, WellElementSubRegion & subRegion ) { - validateWellConstraints( 0, 0, subRegion ); + validateWellConstraints( 0, 0, meshBodies, meshBody, subRegion ); // validate perforation status table PerforationData & perforationData = *subRegion.getPerforationData(); @@ -309,7 +313,7 @@ void WellSolverBase::updateState( DomainPartition & domain ) ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< WellElementSubRegion >( regionNames, [&]( localIndex const, WellElementSubRegion & subRegion ) - { updateSubRegionState( elemManager, subRegion ); } ); + { updateSubRegionState( subRegion ); } ); } ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.hpp index 04fe58112b4..d92e00eded7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.hpp @@ -253,7 +253,7 @@ class WellSolverBase : public PhysicsSolverBase * @param elemManager the elemManager containing the well * @param subRegion the well subRegion containing the well elements and their associated fields */ - virtual real64 updateSubRegionState( ElementRegionManager const & elemManager, WellElementSubRegion & subRegion ) = 0; + virtual real64 updateSubRegionState( WellElementSubRegion & subRegion ) = 0; /** * @brief Recompute the perforation rates for all the wells @@ -321,6 +321,8 @@ class WellSolverBase : public PhysicsSolverBase */ virtual void validateWellConstraints( real64 const & time_n, real64 const & dt, + Group & meshBodies, + MeshBody & meshBody, WellElementSubRegion const & subRegion ) = 0; virtual void printRates( real64 const & time_n, diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index 4a2f9c949c6..6ed1f71381f 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -526,7 +526,7 @@ A field can represent a physical variable. (pressure, temperature, global compos - + @@ -1562,7 +1562,7 @@ A field can represent a physical variable. (pressure, temperature, global compos - +