From d83a6096072dc67481dd98c47d8d5236d4ba3abe Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Wed, 25 Sep 2024 11:41:44 -0500 Subject: [PATCH 01/47] move into folder and clean up includes --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 52 +++++++++---------- .../fluidFlow/CompositionalMultiphaseBase.cpp | 6 +-- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 14 ++--- .../CompositionalMultiphaseHybridFVM.cpp | 7 ++- .../CompositionalMultiphaseStatistics.cpp | 4 +- .../fluidFlow/FlowSolverBase.cpp | 4 +- .../ReactiveCompositionalMultiphaseOBL.cpp | 4 +- .../fluidFlow/SinglePhaseBase.cpp | 4 +- .../fluidFlow/SinglePhaseBase.hpp | 4 +- .../fluidFlow/SinglePhaseFVM.cpp | 13 +++-- .../fluidFlow/SinglePhaseHybridFVM.cpp | 2 +- .../fluidFlow/SinglePhaseProppantBase.cpp | 2 +- .../fluidFlow/SinglePhaseStatistics.cpp | 4 +- ...ompositionalMultiphaseHybridFVMKernels.cpp | 4 +- ...ompositionalMultiphaseHybridFVMKernels.hpp | 2 +- ...ationCompositionalMultiphaseFVMKernels.hpp | 0 .../{ => kernels}/FlowSolverBaseKernels.hpp | 0 .../{ => kernels}/FluxKernelsHelper.hpp | 1 + .../{ => kernels}/HybridFVMHelperKernels.hpp | 0 ...rmalCompositionalMultiphaseBaseKernels.hpp | 0 ...positionalMultiphaseFVMKernelUtilities.hpp | 0 ...ermalCompositionalMultiphaseFVMKernels.cpp | 2 +- ...ermalCompositionalMultiphaseFVMKernels.hpp | 6 +-- ...ctiveCompositionalMultiphaseOBLKernels.hpp | 0 .../{ => kernels}/SinglePhaseBaseKernels.hpp | 0 .../{ => kernels}/SinglePhaseFVMKernels.hpp | 4 +- .../SinglePhaseHybridFVMKernels.hpp | 4 +- .../SinglePhaseProppantBaseKernels.hpp | 0 .../SinglePhaseProppantFluxKernels.cpp | 4 +- .../SinglePhaseProppantFluxKernels.hpp | 8 +-- ...lizedCompositionalMultiphaseFVMKernels.hpp | 2 +- .../StabilizedSinglePhaseFVMKernels.hpp | 2 +- ...rmalCompositionalMultiphaseBaseKernels.hpp | 4 +- ...ermalCompositionalMultiphaseFVMKernels.hpp | 3 +- .../ThermalSinglePhaseBaseKernels.hpp | 2 +- .../ThermalSinglePhaseFVMKernels.hpp | 3 +- .../wells/CompositionalMultiphaseWell.cpp | 10 ++-- .../fluidFlow/wells/SinglePhaseWell.cpp | 3 +- .../fluidFlow/wells/SinglePhaseWell.hpp | 2 - .../CompositionalMultiphaseWellKernels.cpp | 0 .../CompositionalMultiphaseWellKernels.hpp | 2 +- .../{ => kernels}/SinglePhaseWellKernels.cpp | 2 +- .../{ => kernels}/SinglePhaseWellKernels.hpp | 0 ...mpositionalMultiphaseReservoirAndWells.cpp | 4 +- ...mpositionalMultiphaseReservoirAndWells.hpp | 1 + .../SinglePhaseReservoirAndWells.cpp | 3 +- .../SinglePhaseReservoirAndWells.hpp | 1 + ...ePhasePoromechanicsConformingFractures.hpp | 4 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 4 +- .../testSinglePhaseBaseKernels.cpp | 2 +- ...eservoirCompositionalMultiphaseMSWells.cpp | 2 +- .../testReservoirSinglePhaseMSWells.cpp | 2 +- 52 files changed, 102 insertions(+), 111 deletions(-) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/CompositionalMultiphaseHybridFVMKernels.cpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/CompositionalMultiphaseHybridFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/DissipationCompositionalMultiphaseFVMKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/FlowSolverBaseKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/FluxKernelsHelper.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/HybridFVMHelperKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/IsothermalCompositionalMultiphaseBaseKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/IsothermalCompositionalMultiphaseFVMKernels.cpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/IsothermalCompositionalMultiphaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/ReactiveCompositionalMultiphaseOBLKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/SinglePhaseBaseKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/SinglePhaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/SinglePhaseHybridFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/SinglePhaseProppantBaseKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/SinglePhaseProppantFluxKernels.cpp (98%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/SinglePhaseProppantFluxKernels.hpp (95%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/StabilizedCompositionalMultiphaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/StabilizedSinglePhaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/ThermalCompositionalMultiphaseBaseKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/ThermalCompositionalMultiphaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/ThermalSinglePhaseBaseKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/{ => kernels}/ThermalSinglePhaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/wells/{ => kernels}/CompositionalMultiphaseWellKernels.cpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/wells/{ => kernels}/CompositionalMultiphaseWellKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/wells/{ => kernels}/SinglePhaseWellKernels.cpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/wells/{ => kernels}/SinglePhaseWellKernels.hpp (100%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 37b41360330..1b2280f04fb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -4,50 +4,50 @@ set( physicsSolvers_headers fluidFlow/CompositionalMultiphaseBase.hpp fluidFlow/CompositionalMultiphaseBaseFields.hpp fluidFlow/CompositionalMultiphaseStatistics.hpp - fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp - fluidFlow/ThermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp fluidFlow/CompositionalMultiphaseFVM.hpp - fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp - fluidFlow/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp - fluidFlow/ThermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp + fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp fluidFlow/CompositionalMultiphaseHybridFVM.hpp - fluidFlow/CompositionalMultiphaseHybridFVMKernels.hpp + fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp fluidFlow/CompositionalMultiphaseUtilities.hpp fluidFlow/ReactiveCompositionalMultiphaseOBL.hpp fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp - fluidFlow/ReactiveCompositionalMultiphaseOBLKernels.hpp + fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp fluidFlow/FlowSolverBase.hpp fluidFlow/FlowSolverBaseFields.hpp - fluidFlow/FlowSolverBaseKernels.hpp - fluidFlow/FluxKernelsHelper.hpp - fluidFlow/HybridFVMHelperKernels.hpp + fluidFlow/kernels/FlowSolverBaseKernels.hpp + fluidFlow/kernels/FluxKernelsHelper.hpp + fluidFlow/kernels/HybridFVMHelperKernels.hpp fluidFlow/SourceFluxStatistics.hpp fluidFlow/proppantTransport/ProppantTransport.hpp fluidFlow/proppantTransport/ProppantTransportFields.hpp fluidFlow/proppantTransport/ProppantTransportKernels.hpp fluidFlow/SinglePhaseBase.hpp fluidFlow/SinglePhaseBaseFields.hpp - fluidFlow/SinglePhaseBaseKernels.hpp + fluidFlow/kernels/SinglePhaseBaseKernels.hpp fluidFlow/SinglePhaseStatistics.hpp fluidFlow/SinglePhaseFVM.hpp - fluidFlow/SinglePhaseFVMKernels.hpp + fluidFlow/kernels/SinglePhaseFVMKernels.hpp fluidFlow/SinglePhaseHybridFVM.hpp - fluidFlow/SinglePhaseHybridFVMKernels.hpp + fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp fluidFlow/SinglePhaseProppantBase.hpp - fluidFlow/SinglePhaseProppantBaseKernels.hpp - fluidFlow/SinglePhaseProppantFluxKernels.hpp - fluidFlow/StabilizedCompositionalMultiphaseFVMKernels.hpp - fluidFlow/StabilizedSinglePhaseFVMKernels.hpp + fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp + fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp + fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp fluidFlow/StencilAccessors.hpp fluidFlow/StencilDataCollection.hpp - fluidFlow/ThermalSinglePhaseBaseKernels.hpp - fluidFlow/ThermalSinglePhaseFVMKernels.hpp + fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp + fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp fluidFlow/wells/CompositionalMultiphaseWell.hpp fluidFlow/wells/CompositionalMultiphaseWellFields.hpp - fluidFlow/wells/CompositionalMultiphaseWellKernels.hpp + fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp fluidFlow/wells/SinglePhaseWell.hpp fluidFlow/wells/SinglePhaseWellFields.hpp - fluidFlow/wells/SinglePhaseWellKernels.hpp + fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp fluidFlow/wells/WellConstants.hpp fluidFlow/wells/WellControls.hpp fluidFlow/wells/WellSolverBase.hpp @@ -60,9 +60,9 @@ set( physicsSolvers_sources fluidFlow/CompositionalMultiphaseBase.cpp fluidFlow/CompositionalMultiphaseFVM.cpp fluidFlow/CompositionalMultiphaseStatistics.cpp - fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.cpp + fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.cpp fluidFlow/CompositionalMultiphaseHybridFVM.cpp - fluidFlow/CompositionalMultiphaseHybridFVMKernels.cpp + fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.cpp fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp fluidFlow/FlowSolverBase.cpp fluidFlow/proppantTransport/ProppantTransport.cpp @@ -72,13 +72,13 @@ set( physicsSolvers_sources fluidFlow/SinglePhaseFVM.cpp fluidFlow/SinglePhaseHybridFVM.cpp fluidFlow/SinglePhaseProppantBase.cpp - fluidFlow/SinglePhaseProppantFluxKernels.cpp + fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp fluidFlow/SourceFluxStatistics.cpp fluidFlow/StencilDataCollection.cpp fluidFlow/wells/CompositionalMultiphaseWell.cpp - fluidFlow/wells/CompositionalMultiphaseWellKernels.cpp + fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.cpp fluidFlow/wells/SinglePhaseWell.cpp - fluidFlow/wells/SinglePhaseWellKernels.cpp + fluidFlow/wells/kernels/SinglePhaseWellKernels.cpp fluidFlow/wells/WellControls.cpp fluidFlow/wells/WellSolverBase.cpp PARENT_SCOPE ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index a8d6f99ecec..53de4296d92 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -41,9 +41,9 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" // TODO this should not be here +#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 3df15307e80..b7289badafa 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -32,14 +32,14 @@ #include "finiteVolume/FluxApproximationBase.hpp" #include "mesh/DomainPartition.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/StabilizedCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/DissipationCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/DissipationCompositionalMultiphaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index 3eb04d7636b..ff8158383db 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -28,11 +28,10 @@ #include "finiteVolume/HybridMimeticDiscretization.hpp" #include "finiteVolume/MimeticInnerProductDispatch.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" /** * @namespace the geos namespace that encapsulates the majority of the code diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp index 8240c9b3eaf..bfc4cefa93d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp @@ -30,8 +30,8 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index 5c54deae9b5..7015a508e78 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -31,9 +31,9 @@ #include "finiteVolume/FiniteVolumeManager.hpp" #include "finiteVolume/FluxApproximationBase.hpp" #include "mesh/DomainPartition.hpp" -#include "physicsSolvers/fluidFlow/FluxKernelsHelper.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp index 9442496dc2c..0fd45d9292d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp @@ -29,9 +29,9 @@ #include "finiteVolume/FluxApproximationBase.hpp" #include "mesh/DomainPartition.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" -#include "physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLKernels.hpp" +#include "physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp" +#include "physicsSolvers/fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index 05dbc006843..a488db0048d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -40,8 +40,8 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp index 59ad25124b4..36fff6b6f1d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp @@ -21,8 +21,8 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASE_HPP_ #include "physicsSolvers/fluidFlow/FlowSolverBase.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" #include "constitutive/solid/CoupledSolidBase.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index d76de134fd8..a6364cdad9c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -33,13 +33,12 @@ #include "fieldSpecification/AquiferBoundaryCondition.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalSinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalSinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/StabilizedSinglePhaseFVMKernels.hpp" - -#include "physicsSolvers/fluidFlow/SinglePhaseProppantFluxKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp index 6cbabf723f7..6a9b10e18c4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp @@ -28,7 +28,7 @@ #include "mainInterface/ProblemManager.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseHybridFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp" /** diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp index 38d95f212e5..aa391fffe2f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp @@ -27,7 +27,7 @@ #include "constitutive/solid/ProppantSolid.hpp" #include "constitutive/solid/porosity/ProppantPorosity.hpp" #include "physicsSolvers/fluidFlow/proppantTransport/ProppantTransportFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseProppantBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp index 4a54f7f3ab1..dc397416321 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp @@ -22,9 +22,9 @@ #include "mainInterface/ProblemManager.hpp" #include "physicsSolvers/PhysicsSolverManager.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.cpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.cpp index 5ad239a5a1b..4e698041b4c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.cpp @@ -18,14 +18,14 @@ */ #include "CompositionalMultiphaseHybridFVMKernels.hpp" -#include "CompositionalMultiphaseUtilities.hpp" #include "finiteVolume/mimeticInnerProducts/MimeticInnerProductBase.hpp" #include "finiteVolume/mimeticInnerProducts/BdVLMInnerProduct.hpp" #include "finiteVolume/mimeticInnerProducts/TPFAInnerProduct.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/HybridFVMHelperKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp index 6953bfb7be2..c4b5abbcd7b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp @@ -31,8 +31,8 @@ #include "mesh/ElementRegionManager.hpp" #include "mesh/ObjectManagerBase.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/DissipationCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/DissipationCompositionalMultiphaseFVMKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/DissipationCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/DissipationCompositionalMultiphaseFVMKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FluxKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/FluxKernelsHelper.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp index 5a61816e13c..0e4ae5ba2b4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FluxKernelsHelper.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp @@ -25,6 +25,7 @@ #include "finiteVolume/BoundaryStencil.hpp" #include "linearAlgebra/interfaces/InterfaceTypes.hpp" #include "mesh/ElementRegionManager.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/HybridFVMHelperKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/HybridFVMHelperKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.cpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.cpp index 6670a649a03..0f878628377 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.cpp @@ -18,7 +18,7 @@ */ #include "IsothermalCompositionalMultiphaseFVMKernels.hpp" -#include "CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "finiteVolume/CellElementStencilTPFA.hpp" #include "finiteVolume/SurfaceElementStencil.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp index 08359bc0d6a..a4c30ca1f43 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp @@ -39,16 +39,16 @@ #include "constitutive/solid/porosity/PorosityBase.hpp" #include "constitutive/solid/porosity/PorosityFields.hpp" #include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" #include "finiteVolume/BoundaryStencil.hpp" #include "mesh/ElementRegionManager.hpp" #include "mesh/utilities/MeshMapUtilities.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp index 0a04b330ae9..aedfd20f7a7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp @@ -35,9 +35,9 @@ #include "linearAlgebra/interfaces/InterfaceTypes.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp index 2d05cc82c43..2e950b3226c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp @@ -35,10 +35,10 @@ #include "denseLinearAlgebra/interfaces/blaslapack/BlasLapackLA.hpp" #include "mesh/MeshLevel.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/HybridFVMHelperKernels.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantFluxKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp similarity index 98% rename from src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantFluxKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp index 63f3f538b8e..193fc117989 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantFluxKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp @@ -17,10 +17,10 @@ * @file singlePhaseProppantFluxKernels.cpp */ -#include "physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/FluxKernelsHelper.hpp" #include "SinglePhaseProppantFluxKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" + namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantFluxKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp similarity index 95% rename from src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantFluxKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp index d64e374f9d2..69b50bb2f82 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantFluxKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp @@ -21,12 +21,8 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEPROPPANTFLUXKERNELS_HPP #include "common/DataTypes.hpp" -#include "finiteVolume/BoundaryStencil.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "linearAlgebra/interfaces/InterfaceTypes.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp" - +#include "mesh/ElementRegionManager.hpp" +#include "finiteVolume/SurfaceElementStencil.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/StabilizedCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/StabilizedCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp index 7da02f8d6e2..7e249ed0ab7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/StabilizedCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/StabilizedSinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/StabilizedSinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp index 23dcfafea9d..98963a98ea2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/StabilizedSinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDSINGLEPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDSINGLEPHASEFVMKERNELS_HPP -#include "physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp index 8f1881d41c2..39b6759c56f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp @@ -20,9 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" - -#include "common/Units.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp index 98d4be4d813..1ac47cb3ba6 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp @@ -20,10 +20,11 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" + #include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" #include "constitutive/thermalConductivity/MultiPhaseThermalConductivityFields.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ThermalSinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/ThermalSinglePhaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp index d3d678d6239..5c31e222af9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ThermalSinglePhaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ThermalSinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/ThermalSinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp index b108ae79339..ec28bf14e5b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ThermalSinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp @@ -20,10 +20,11 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEFVMKERNELS_HPP +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" + #include "constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" #include "constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 2ad8b918fd7..1f240917e52 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -19,7 +19,6 @@ #include "CompositionalMultiphaseWell.hpp" - #include "codingUtilities/Utilities.hpp" #include "common/DataTypes.hpp" #include "common/FieldSpecificationOps.hpp" @@ -35,13 +34,12 @@ #include "mesh/PerforationFields.hpp" #include "mesh/WellElementSubRegion.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/ThermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" -#include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.hpp" -#include "physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" +#include "physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index 59c73f57eb9..73ea1fc34ac 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -30,11 +30,12 @@ #include "mesh/WellElementSubRegion.hpp" #include "mesh/PerforationFields.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" +#include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/wells/SinglePhaseWellFields.hpp" -#include "physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" +#include "physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp index 57dc1d9feff..7b674d83a74 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp @@ -21,8 +21,6 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_WELLS_SINGLEPHASEWELL_HPP_ #include "WellSolverBase.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.cpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.cpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index f06b27ac202..463c8d7bbcd 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -31,8 +31,8 @@ #include "mesh/ObjectManagerBase.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/IsothermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.cpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.cpp index f006802654c..a2446c60b6a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.cpp @@ -20,7 +20,7 @@ #include "SinglePhaseWellKernels.hpp" // TODO: move keys to WellControls -#include "SinglePhaseWell.hpp" +#include "physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp diff --git a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.cpp b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.cpp index c01984e2908..29d7dc1abac 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.cpp @@ -23,13 +23,11 @@ #include "common/TimingMacros.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "mesh/PerforationFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" -#include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" +#include "physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp" #include "physicsSolvers/multiphysics/MultiphasePoromechanics.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp index 4904148cef4..48edba2328e 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp @@ -22,6 +22,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_COMPOSITIONALMULTIPHASERESERVOIRANDWELLS_HPP_ #include "physicsSolvers/multiphysics/CoupledReservoirAndWellsBase.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.cpp index 34932b61aba..cabd0f237fe 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.cpp @@ -22,10 +22,9 @@ #include "common/TimingMacros.hpp" #include "mesh/PerforationFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseFVM.hpp" #include "physicsSolvers/fluidFlow/wells/SinglePhaseWellFields.hpp" -#include "physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" +#include "physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp" #include "physicsSolvers/multiphysics/SinglePhasePoromechanics.hpp" #include "physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.hpp" diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp index 3ad673bbb21..6d8fa3583e3 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp @@ -22,6 +22,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_SINGLEPHASERESERVOIRANDWELLS_HPP_ #include "physicsSolvers/multiphysics/CoupledReservoirAndWellsBase.hpp" +#include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index d7e85611e44..ee3a42f03ba 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -20,8 +20,8 @@ #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP -#include "physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index 4597b737554..cbede85d1d3 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -20,8 +20,8 @@ #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP -#include "physicsSolvers/fluidFlow/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" namespace geos { diff --git a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp index 03f0b903e14..cb4c3c98944 100644 --- a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp +++ b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp @@ -15,7 +15,7 @@ // Source includes #include "mainInterface/initialization.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" // TPL includes #include diff --git a/src/coreComponents/unitTests/wellsTests/testReservoirCompositionalMultiphaseMSWells.cpp b/src/coreComponents/unitTests/wellsTests/testReservoirCompositionalMultiphaseMSWells.cpp index 4d3b4e775ba..a72a6027086 100644 --- a/src/coreComponents/unitTests/wellsTests/testReservoirCompositionalMultiphaseMSWells.cpp +++ b/src/coreComponents/unitTests/wellsTests/testReservoirCompositionalMultiphaseMSWells.cpp @@ -26,7 +26,7 @@ #include "physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.hpp" -#include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellKernels.hpp" +#include "physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" diff --git a/src/coreComponents/unitTests/wellsTests/testReservoirSinglePhaseMSWells.cpp b/src/coreComponents/unitTests/wellsTests/testReservoirSinglePhaseMSWells.cpp index 3401166c3ae..d5bab6b6b7e 100644 --- a/src/coreComponents/unitTests/wellsTests/testReservoirSinglePhaseMSWells.cpp +++ b/src/coreComponents/unitTests/wellsTests/testReservoirSinglePhaseMSWells.cpp @@ -27,7 +27,7 @@ #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseFVM.hpp" #include "physicsSolvers/fluidFlow/wells/SinglePhaseWell.hpp" -#include "physicsSolvers/fluidFlow/wells/SinglePhaseWellKernels.hpp" +#include "physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/wells/SinglePhaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" From 9d9915c4424dc6e246defab9621f97fcfe43ffb1 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Wed, 25 Sep 2024 14:33:28 -0500 Subject: [PATCH 02/47] Remove duplicates of NoOpFunc --- .../kernels/SinglePhaseBaseKernels.hpp | 14 +------------- .../kernels/SinglePhaseFVMKernels.hpp | 17 +++++++++-------- .../kernels/SinglePhaseHybridFVMKernels.hpp | 5 +++-- .../MultiphasePoromechanics.hpp | 6 +++--- ...ePhasePoromechanicsConformingFractures.hpp | 9 +++++---- .../SinglePhasePoromechanicsEFEM.hpp | 19 +++---------------- ...glePhasePoromechanicsEmbeddedFractures.hpp | 4 ++-- 7 files changed, 26 insertions(+), 48 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp index ddbf08c4080..31840f49d1f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp @@ -28,6 +28,7 @@ #include "linearAlgebra/interfaces/InterfaceTypes.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { @@ -100,19 +101,6 @@ struct MobilityKernel /******************************** ElementBasedAssemblyKernel ********************************/ -/** - * @brief Internal struct to provide no-op defaults used in the inclusion - * of lambda functions into kernel component functions. - * @struct NoOpFunc - */ -struct NoOpFunc -{ - template< typename ... Ts > - GEOS_HOST_DEVICE - constexpr void - operator()( Ts && ... ) const {} -}; - /** * @class ElementBasedAssemblyKernel * @brief Define the interface for the assembly kernel in charge of accumulation diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp index aedfd20f7a7..cd1e04516c1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp @@ -38,6 +38,7 @@ #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" #include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { @@ -326,11 +327,11 @@ class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase * @param[inout] stack the stack variables * @param[in] NoOpFunc the function used to customize the computation of the flux */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void computeFlux( localIndex const iconn, StackVariables & stack, - FUNC && kernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && kernelOp = NoOpFunc{} ) const { // first, compute the transmissibilities at this face m_stencilWrapper.computeWeights( iconn, @@ -398,11 +399,11 @@ class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase * @param[in] iconn the connection index * @param[inout] stack the stack variables */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void complete( localIndex const iconn, StackVariables & stack, - FUNC && kernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && kernelOp = NoOpFunc{} ) const { // add contribution to residual and jacobian into: // - the mass balance equation @@ -658,11 +659,11 @@ class DirichletFaceBasedAssemblyKernel : public FaceBasedAssemblyKernel< NUM_EQN * @param[inout] stack the stack variables * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void computeFlux( localIndex const iconn, StackVariables & stack, - FUNC && compFluxKernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && compFluxKernelOp = NoOpFunc{} ) const { using Order = BoundaryStencil::Order; localIndex constexpr numElems = BoundaryStencil::maxNumPointsInFlux; @@ -724,11 +725,11 @@ class DirichletFaceBasedAssemblyKernel : public FaceBasedAssemblyKernel< NUM_EQN * @param[in] iconn the connection index * @param[inout] stack the stack variables */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void complete( localIndex const iconn, StackVariables & stack, - FUNC && assemblyKernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && assemblyKernelOp = NoOpFunc{} ) const { using Order = BoundaryStencil::Order; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp index 2e950b3226c..05653379595 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp @@ -40,6 +40,7 @@ #include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { @@ -479,11 +480,11 @@ class ElementBasedAssemblyKernel * @param[inout] stack the stack variables * @param[in] kernelOp the function used to customize the kernel */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void compute( localIndex const ei, StackVariables & stack, - FUNC && kernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && kernelOp = NoOpFunc{} ) const { GEOS_UNUSED_VAR( ei, stack, kernelOp ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/MultiphasePoromechanics.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/MultiphasePoromechanics.hpp index a0f81fce935..b3079a9e8c5 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/MultiphasePoromechanics.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/MultiphasePoromechanics.hpp @@ -20,10 +20,10 @@ #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_MULTIPHASEPOROMECHANICS_HPP_ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_MULTIPHASEPOROMECHANICS_HPP_ -#include "codingUtilities/Utilities.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/multiphysics/PoromechanicsFields.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/PoromechanicsBase.hpp" +#include "physicsSolvers/multiphysics/PoromechanicsFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index ee3a42f03ba..84e68734d4a 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -22,6 +22,7 @@ #include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { @@ -155,11 +156,11 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse * @param[inout] stack the stack variables * @param[in] NoOpFunc the function used to customize the computation of the flux */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void computeFlux( localIndex const iconn, StackVariables & stack, - FUNC && kernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && kernelOp = NoOpFunc{} ) const { @@ -235,11 +236,11 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse * @param[in] iconn the connection index * @param[inout] stack the stack variables */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void complete( localIndex const iconn, StackVariables & stack, - FUNC && kernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && kernelOp = NoOpFunc{} ) const { // Call Base::complete to assemble the mass balance equations // In the lambda, fill the dR_dAper matrix diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEFEM.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEFEM.hpp index 3f614829d9a..5f8fcdac2a5 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEFEM.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEFEM.hpp @@ -21,6 +21,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEFEM_HPP_ #include "finiteElement/kernelInterface/ImplicitKernelBase.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { @@ -28,20 +29,6 @@ namespace geos namespace poromechanicsEFEMKernels { -/** - * @brief Internal struct to provide no-op defaults used in the inclusion - * of lambda functions into kernel component functions. - * @struct NoOpFunc - */ -struct NoOpFunc -{ - template< typename ... Ts > - GEOS_HOST_DEVICE - constexpr void - operator()( Ts && ... ) const {} -}; - - template< typename SUBREGION_TYPE, typename CONSTITUTIVE_TYPE, typename FE_TYPE > @@ -220,12 +207,12 @@ class SinglePhasePoromechanicsEFEM : void setup( localIndex const k, StackVariables & stack ) const; - template< typename FUNC = poromechanicsEFEMKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void quadraturePointKernel( localIndex const k, localIndex const q, StackVariables & stack, - FUNC && kernelOp = poromechanicsEFEMKernels::NoOpFunc{} ) const; + FUNC && kernelOp = NoOpFunc{} ) const; /** * @copydoc geos::finiteElement::ImplicitKernelBase::complete diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index cbede85d1d3..0b9bcb2108e 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -150,11 +150,11 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse * @param[inout] stack the stack variables * @param[in] NoOpFunc the function used to customize the computation of the flux */ - template< typename FUNC = singlePhaseBaseKernels::NoOpFunc > + template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void computeFlux( localIndex const iconn, StackVariables & stack, - FUNC && kernelOp = singlePhaseBaseKernels::NoOpFunc{} ) const + FUNC && kernelOp = NoOpFunc{} ) const { From fde7cab8260bc2f8849b1b9a2191adeffafa1c1c Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Wed, 25 Sep 2024 15:08:21 -0500 Subject: [PATCH 03/47] Update SinglePhasePoromechanicsEmbeddedFractures.hpp --- .../SinglePhasePoromechanicsEmbeddedFractures.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index 0b9bcb2108e..5092012e423 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -22,6 +22,7 @@ #include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { From d2c590b35325ede211660779d37bd37e1b2e123b Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Wed, 25 Sep 2024 15:33:21 -0500 Subject: [PATCH 04/47] more move into subfolders --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 40 +++++++++---------- .../fluidFlow/CompositionalMultiphaseBase.cpp | 6 +-- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 12 +++--- .../CompositionalMultiphaseHybridFVM.cpp | 4 +- .../CompositionalMultiphaseStatistics.cpp | 4 +- .../fluidFlow/FlowSolverBase.cpp | 2 +- .../ReactiveCompositionalMultiphaseOBL.cpp | 2 +- .../fluidFlow/SinglePhaseBase.cpp | 4 +- .../fluidFlow/SinglePhaseBase.hpp | 4 +- .../fluidFlow/SinglePhaseFVM.cpp | 12 +++--- .../fluidFlow/SinglePhaseHybridFVM.cpp | 2 +- .../fluidFlow/SinglePhaseProppantBase.cpp | 2 +- .../fluidFlow/SinglePhaseStatistics.cpp | 2 +- ...ompositionalMultiphaseHybridFVMKernels.cpp | 0 ...ompositionalMultiphaseHybridFVMKernels.hpp | 2 +- ...ationCompositionalMultiphaseFVMKernels.hpp | 0 ...rmalCompositionalMultiphaseBaseKernels.hpp | 0 ...positionalMultiphaseFVMKernelUtilities.hpp | 0 ...ermalCompositionalMultiphaseFVMKernels.cpp | 0 ...ermalCompositionalMultiphaseFVMKernels.hpp | 4 +- ...ctiveCompositionalMultiphaseOBLKernels.hpp | 0 ...lizedCompositionalMultiphaseFVMKernels.hpp | 2 +- ...rmalCompositionalMultiphaseBaseKernels.hpp | 2 +- ...ermalCompositionalMultiphaseFVMKernels.hpp | 2 +- .../{ => singlePhase}/FluxKernelsHelper.hpp | 0 .../SinglePhaseBaseKernels.hpp | 0 .../SinglePhaseFVMKernels.hpp | 4 +- .../SinglePhaseHybridFVMKernels.hpp | 2 +- .../SinglePhaseProppantBaseKernels.hpp | 0 .../SinglePhaseProppantFluxKernels.cpp | 2 +- .../SinglePhaseProppantFluxKernels.hpp | 0 .../StabilizedSinglePhaseFVMKernels.hpp | 2 +- .../ThermalSinglePhaseBaseKernels.hpp | 2 +- .../ThermalSinglePhaseFVMKernels.hpp | 2 +- .../wells/CompositionalMultiphaseWell.cpp | 4 +- .../CompositionalMultiphaseWellKernels.hpp | 2 +- ...ePhasePoromechanicsConformingFractures.hpp | 4 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 5 ++- .../testSinglePhaseBaseKernels.cpp | 2 +- 39 files changed, 70 insertions(+), 69 deletions(-) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/CompositionalMultiphaseHybridFVMKernels.cpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/CompositionalMultiphaseHybridFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/DissipationCompositionalMultiphaseFVMKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/IsothermalCompositionalMultiphaseBaseKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/IsothermalCompositionalMultiphaseFVMKernels.cpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/IsothermalCompositionalMultiphaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/ReactiveCompositionalMultiphaseOBLKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/StabilizedCompositionalMultiphaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/ThermalCompositionalMultiphaseBaseKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => compositional}/ThermalCompositionalMultiphaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/FluxKernelsHelper.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/SinglePhaseBaseKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/SinglePhaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/SinglePhaseHybridFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/SinglePhaseProppantBaseKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/SinglePhaseProppantFluxKernels.cpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/SinglePhaseProppantFluxKernels.hpp (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/StabilizedSinglePhaseFVMKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/ThermalSinglePhaseBaseKernels.hpp (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{ => singlePhase}/ThermalSinglePhaseFVMKernels.hpp (99%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 1b2280f04fb..4ef9392f9ef 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -4,22 +4,22 @@ set( physicsSolvers_headers fluidFlow/CompositionalMultiphaseBase.hpp fluidFlow/CompositionalMultiphaseBaseFields.hpp fluidFlow/CompositionalMultiphaseStatistics.hpp - fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp - fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp fluidFlow/CompositionalMultiphaseFVM.hpp - fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp - fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp - fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp + fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp fluidFlow/CompositionalMultiphaseHybridFVM.hpp - fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp + fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp fluidFlow/CompositionalMultiphaseUtilities.hpp fluidFlow/ReactiveCompositionalMultiphaseOBL.hpp fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp - fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp + fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp fluidFlow/FlowSolverBase.hpp fluidFlow/FlowSolverBaseFields.hpp fluidFlow/kernels/FlowSolverBaseKernels.hpp - fluidFlow/kernels/FluxKernelsHelper.hpp + fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp fluidFlow/kernels/HybridFVMHelperKernels.hpp fluidFlow/SourceFluxStatistics.hpp fluidFlow/proppantTransport/ProppantTransport.hpp @@ -27,21 +27,21 @@ set( physicsSolvers_headers fluidFlow/proppantTransport/ProppantTransportKernels.hpp fluidFlow/SinglePhaseBase.hpp fluidFlow/SinglePhaseBaseFields.hpp - fluidFlow/kernels/SinglePhaseBaseKernels.hpp + fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp fluidFlow/SinglePhaseStatistics.hpp fluidFlow/SinglePhaseFVM.hpp - fluidFlow/kernels/SinglePhaseFVMKernels.hpp + fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp fluidFlow/SinglePhaseHybridFVM.hpp - fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp + fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp fluidFlow/SinglePhaseProppantBase.hpp - fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp - fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp - fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp - fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp + fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp + fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp + fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp fluidFlow/StencilAccessors.hpp fluidFlow/StencilDataCollection.hpp - fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp - fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp + fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp + fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp fluidFlow/wells/CompositionalMultiphaseWell.hpp fluidFlow/wells/CompositionalMultiphaseWellFields.hpp fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -60,9 +60,9 @@ set( physicsSolvers_sources fluidFlow/CompositionalMultiphaseBase.cpp fluidFlow/CompositionalMultiphaseFVM.cpp fluidFlow/CompositionalMultiphaseStatistics.cpp - fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.cpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp fluidFlow/CompositionalMultiphaseHybridFVM.cpp - fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.cpp + fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.cpp fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp fluidFlow/FlowSolverBase.cpp fluidFlow/proppantTransport/ProppantTransport.cpp @@ -72,7 +72,7 @@ set( physicsSolvers_sources fluidFlow/SinglePhaseFVM.cpp fluidFlow/SinglePhaseHybridFVM.cpp fluidFlow/SinglePhaseProppantBase.cpp - fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp + fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp fluidFlow/SourceFluxStatistics.cpp fluidFlow/StencilDataCollection.cpp fluidFlow/wells/CompositionalMultiphaseWell.cpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 53de4296d92..613f662eef6 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -41,9 +41,9 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" // TODO this should not be here -#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" // TODO this should not be here +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index b7289badafa..3afb697fd11 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -34,12 +34,12 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/DissipationCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index ff8158383db..d085adaf4f2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -30,8 +30,8 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" /** * @namespace the geos namespace that encapsulates the majority of the code diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp index bfc4cefa93d..2cd57096c5f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp @@ -30,8 +30,8 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index 7015a508e78..6a2f4222a3d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -33,7 +33,7 @@ #include "mesh/DomainPartition.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" // TODO should not be here namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp index 0fd45d9292d..3a3e2276582 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp @@ -31,7 +31,7 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index a488db0048d..98e2f6aa0eb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -40,8 +40,8 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp index 36fff6b6f1d..88088c1170e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp @@ -21,8 +21,8 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASE_HPP_ #include "physicsSolvers/fluidFlow/FlowSolverBase.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" #include "constitutive/solid/CoupledSolidBase.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index a6364cdad9c..ec19438134b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -33,12 +33,12 @@ #include "fieldSpecification/AquiferBoundaryCondition.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp index 6a9b10e18c4..e35dfc9173c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp @@ -28,7 +28,7 @@ #include "mainInterface/ProblemManager.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp" /** diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp index aa391fffe2f..5988c145d1d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp @@ -27,7 +27,7 @@ #include "constitutive/solid/ProppantSolid.hpp" #include "constitutive/solid/porosity/ProppantPorosity.hpp" #include "physicsSolvers/fluidFlow/proppantTransport/ProppantTransportFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp index dc397416321..6d7da35b3ef 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp @@ -24,7 +24,7 @@ #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.cpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.cpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp index c4b5abbcd7b..89996316dac 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/CompositionalMultiphaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp @@ -32,7 +32,7 @@ #include "mesh/ObjectManagerBase.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/DissipationCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/DissipationCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp index a4c30ca1f43..16bca0cc8cf 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp @@ -47,8 +47,8 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/ReactiveCompositionalMultiphaseOBLKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp index 7e249ed0ab7..62bab9f3a23 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp index 39b6759c56f..7eb095cc2b6 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp index 1ac47cb3ba6..e7d049e43a9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" #include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp index cd1e04516c1..d545b2a04cd 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp @@ -36,8 +36,8 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp index 05653379595..05d203538b5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp @@ -37,7 +37,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" #include "codingUtilities/Utilities.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp index 193fc117989..06c815d1ddf 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp @@ -19,7 +19,7 @@ #include "SinglePhaseProppantFluxKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/SinglePhaseProppantFluxKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp index 98963a98ea2..df0c3c0f3cc 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/StabilizedSinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDSINGLEPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDSINGLEPHASEFVMKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp index 5c31e222af9..271b7e51ac0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp index ec28bf14e5b..7bc7c1653a7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/ThermalSinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEFVMKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEFVMKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" #include "constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 1f240917e52..990b328a422 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -38,8 +38,8 @@ #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index 463c8d7bbcd..ca5c95ab26b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -32,7 +32,7 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index 84e68734d4a..728f08b5860 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -20,8 +20,8 @@ #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index 0b9bcb2108e..70091c1aea8 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -20,8 +20,9 @@ #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "codingUtilities/Utilities.hpp" namespace geos { diff --git a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp index cb4c3c98944..86b2518cb23 100644 --- a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp +++ b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp @@ -15,7 +15,7 @@ // Source includes #include "mainInterface/initialization.hpp" -#include "physicsSolvers/fluidFlow/kernels/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" // TPL includes #include From ffc24fe2660a1024f46564259344c6647a9b10f8 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 08:39:30 -0500 Subject: [PATCH 05/47] split FlowSolverBaseKernels.hpp --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 3 +- .../fluidFlow/FlowSolverBase.cpp | 61 ++++++++++++++--- .../fluidFlow/FlowSolverBase.hpp | 13 ++++ ...hpp => MinPoreVolumeMaxPorosityKernel.hpp} | 42 ------------ .../kernels/singlePhase/FluxKernelsHelper.hpp | 67 ++----------------- 5 files changed, 73 insertions(+), 113 deletions(-) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/{FlowSolverBaseKernels.hpp => MinPoreVolumeMaxPorosityKernel.hpp} (78%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 4ef9392f9ef..50be7c96bc1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -18,7 +18,8 @@ set( physicsSolvers_headers fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp fluidFlow/FlowSolverBase.hpp fluidFlow/FlowSolverBaseFields.hpp - fluidFlow/kernels/FlowSolverBaseKernels.hpp + fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp + fluidFlow/kernels/StencilWeightsUpdateKernel.hpp fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp fluidFlow/kernels/HybridFVMHelperKernels.hpp fluidFlow/SourceFluxStatistics.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index 6a2f4222a3d..9fe1155d21f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -32,7 +32,8 @@ #include "finiteVolume/FluxApproximationBase.hpp" #include "mesh/DomainPartition.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" // TODO should not be here namespace geos @@ -709,14 +710,13 @@ void FlowSolverBase::saveAquiferConvergedState( real64 const & time, elemManager.constructFieldAccessor< fields::flow::gravityCoefficient >(); gravCoef.setName( getName() + "/accessors/" + fields::flow::gravityCoefficient::key() ); - real64 const targetSetSumFluxes = - fluxKernelsHelper::AquiferBCKernel::sumFluxes( stencil, - aquiferBCWrapper, - pressure.toNestedViewConst(), - pressure_n.toNestedViewConst(), - gravCoef.toNestedViewConst(), - time, - dt ); + real64 const targetSetSumFluxes = sumAquiferFluxes( stencil, + aquiferBCWrapper, + pressure.toNestedViewConst(), + pressure_n.toNestedViewConst(), + gravCoef.toNestedViewConst(), + time, + dt ); localIndex const aquiferIndex = aquiferNameToAquiferId.at( bc.getName() ); localSumFluxes[aquiferIndex] += targetSetSumFluxes; @@ -744,6 +744,49 @@ void FlowSolverBase::saveAquiferConvergedState( real64 const & time, } ); } +/** + * @brief Function to sum the aquiferBC fluxes (as later save them) at the end of the time step + * This function is applicable for both single-phase and multiphase flow + */ +real64 +FlowSolverBase::sumAquiferFluxes( BoundaryStencil const & stencil, + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & presOld, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + real64 const & timeAtBeginningOfStep, + real64 const & dt ) +{ + using Order = BoundaryStencil::Order; + + BoundaryStencil::IndexContainerViewConstType const & seri = stencil.getElementRegionIndices(); + BoundaryStencil::IndexContainerViewConstType const & sesri = stencil.getElementSubRegionIndices(); + BoundaryStencil::IndexContainerViewConstType const & sefi = stencil.getElementIndices(); + BoundaryStencil::WeightContainerViewConstType const & weight = stencil.getWeights(); + + RAJA::ReduceSum< parallelDeviceReduce, real64 > targetSetSumFluxes( 0.0 ); + + forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + localIndex const er = seri( iconn, Order::ELEM ); + localIndex const esr = sesri( iconn, Order::ELEM ); + localIndex const ei = sefi( iconn, Order::ELEM ); + real64 const areaFraction = weight( iconn, Order::ELEM ); + + // compute the aquifer influx rate using the pressure influence function and the aquifer props + real64 dAquiferVolFlux_dPres = 0.0; + real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep, + dt, + pres[er][esr][ei], + presOld[er][esr][ei], + gravCoef[er][esr][ei], + areaFraction, + dAquiferVolFlux_dPres ); + targetSetSumFluxes += aquiferVolFlux; + } ); + return targetSetSumFluxes.get(); +} + void FlowSolverBase::prepareStencilWeights( DomainPartition & domain ) const { forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp index 883661f25a0..e9536c8c494 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp @@ -22,6 +22,8 @@ #include "physicsSolvers/SolverBase.hpp" #include "common/Units.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" namespace geos { @@ -34,6 +36,9 @@ namespace geos */ class FlowSolverBase : public SolverBase { +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + public: /// String used to form the solverName used to register single-physics solvers in CoupledSolver @@ -196,6 +201,14 @@ class FlowSolverBase : public SolverBase virtual void setConstitutiveNamesCallSuper( ElementSubRegionBase & subRegion ) const override; +real64 sumAquiferFluxes( BoundaryStencil const & stencil, + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & presOld, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + real64 const & timeAtBeginningOfStep, + real64 const & dt ); + /// the number of Degrees of Freedom per cell integer m_numDofPerCell; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp similarity index 78% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp index 4c3b0f0df36..9d9edf47d72 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/FlowSolverBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp @@ -33,9 +33,6 @@ namespace flowSolverBaseKernels /// Threshold for the min pore volume (below, a warning is issued) static constexpr real64 poreVolumeThreshold = 1e-4; -template< typename VIEWTYPE > -using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - /** * @struct MinPoreVolumeMaxPorosityKernel * @brief Kernel to compute the min pore volume and the max porosity in a subRegion @@ -106,45 +103,6 @@ struct MinPoreVolumeMaxPorosityKernel } }; -/** - * @brief - * - * @tparam STENCILWRAPPER - */ -template< typename STENCILWRAPPER > -struct stencilWeightsUpdateKernel -{ - /** - * @brief - * - * @param stencilWrappper - * @param hydraulicAperture - */ - inline static void prepareStencilWeights( STENCILWRAPPER & stencilWrapper, - ElementViewConst< arrayView1d< real64 const > > const hydraulicAperture ) - { - forAll< parallelDevicePolicy<> >( stencilWrapper.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - stencilWrapper.removeHydraulicApertureContribution( iconn, hydraulicAperture ); - } ); - } - - /** - * @brief - * - * @param stencilWrappper - * @param hydraulicAperture - */ - inline static void updateStencilWeights( STENCILWRAPPER & stencilWrapper, - ElementViewConst< arrayView1d< real64 const > > const hydraulicAperture ) - { - forAll< parallelDevicePolicy<> >( stencilWrapper.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - stencilWrapper.addHydraulicApertureContribution( iconn, hydraulicAperture ); - } ); - } -}; - } // namespace flowSolverBaseKernels } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp index 0e4ae5ba2b4..d381c58195a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp @@ -33,6 +33,12 @@ namespace geos namespace fluxKernelsHelper { +/** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; @@ -283,67 +289,6 @@ void computeConductiveFlux( localIndex const ( &seri )[2], } } -/******************************** AquiferBCKernel ********************************/ - -/** - * @brief Function to sum the aquiferBC fluxes (as later save them) at the end of the time step - * This function is applicable for both single-phase and multiphase flow - */ -struct AquiferBCKernel -{ - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - - static real64 - sumFluxes( BoundaryStencil const & stencil, - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & presOld, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - real64 const & timeAtBeginningOfStep, - real64 const & dt ) - { - using Order = BoundaryStencil::Order; - - BoundaryStencil::IndexContainerViewConstType const & seri = stencil.getElementRegionIndices(); - BoundaryStencil::IndexContainerViewConstType const & sesri = stencil.getElementSubRegionIndices(); - BoundaryStencil::IndexContainerViewConstType const & sefi = stencil.getElementIndices(); - BoundaryStencil::WeightContainerViewConstType const & weight = stencil.getWeights(); - - RAJA::ReduceSum< parallelDeviceReduce, real64 > targetSetSumFluxes( 0.0 ); - - forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - localIndex const er = seri( iconn, Order::ELEM ); - localIndex const esr = sesri( iconn, Order::ELEM ); - localIndex const ei = sefi( iconn, Order::ELEM ); - real64 const areaFraction = weight( iconn, Order::ELEM ); - - // compute the aquifer influx rate using the pressure influence function and the aquifer props - real64 dAquiferVolFlux_dPres = 0.0; - real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep, - dt, - pres[er][esr][ei], - presOld[er][esr][ei], - gravCoef[er][esr][ei], - areaFraction, - dAquiferVolFlux_dPres ); - targetSetSumFluxes += aquiferVolFlux; - } ); - return targetSetSumFluxes.get(); - } - -}; - - } // namespace fluxKernelsHelper } // namespace geos From 451b40a2b680682dd5723f0fcfb9779e08aa7eca Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 09:08:02 -0500 Subject: [PATCH 06/47] rename --- .../physicsSolvers/fluidFlow/FlowSolverBase.cpp | 2 +- .../kernels/singlePhase/SinglePhaseFVMKernels.hpp | 2 +- ...KernelsHelper.hpp => SinglePhaseFluxKernelsHelper.hpp} | 8 ++++---- .../singlePhase/SinglePhaseProppantFluxKernels.cpp | 2 +- .../SinglePhasePoromechanicsConformingFractures.hpp | 2 +- .../SinglePhasePoromechanicsEmbeddedFractures.hpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{FluxKernelsHelper.hpp => SinglePhaseFluxKernelsHelper.hpp} (97%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index 9fe1155d21f..c095c79df49 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -34,7 +34,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" // TODO should not be here +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" // TODO should not be here namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp index d545b2a04cd..222fe94041f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp @@ -37,7 +37,7 @@ #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp similarity index 97% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp index d381c58195a..e555c771db0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp @@ -14,11 +14,11 @@ */ /** - * @file FluxKernelsHelper.hpp + * @file SinglePhaseFluxKernelsHelper.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_FLUXKERNELSHELPER_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_FLUXKERNELSHELPER_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUXKERNELSHELPER_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUXKERNELSHELPER_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -293,4 +293,4 @@ void computeConductiveFlux( localIndex const ( &seri )[2], } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_FLUXKERNELSHELPER_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUXKERNELSHELPER_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp index 06c815d1ddf..89e396c0990 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp @@ -19,7 +19,7 @@ #include "SinglePhaseProppantFluxKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index 728f08b5860..2e8893fc9a9 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index 70091c1aea8..dd820e257d3 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos From 2ce059c07a1611ae8708c50b8c444a29026ae561 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 11:53:48 -0500 Subject: [PATCH 07/47] split SinglePhaseBaseKernels.hpp --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 10 +- .../fluidFlow/FlowSolverBase.cpp | 24 +- .../fluidFlow/FlowSolverBase.hpp | 18 +- .../fluidFlow/SinglePhaseBase.cpp | 29 +- .../fluidFlow/SinglePhaseBase.hpp | 4 +- .../fluidFlow/SinglePhaseFVM.cpp | 3 +- .../fluidFlow/SinglePhaseHybridFVM.cpp | 4 + .../fluidFlow/SinglePhaseProppantBase.cpp | 1 + .../fluidFlow/SinglePhaseStatistics.cpp | 3 +- ...rmalCompositionalMultiphaseBaseKernels.hpp | 2 +- .../SinglePhaseAccumulationKernels.hpp | 360 +++++++ .../singlePhase/SinglePhaseBaseKernels.hpp | 897 ------------------ .../singlePhase/SinglePhaseFVMKernels.hpp | 33 +- .../SinglePhaseFluxKernelsHelper.hpp | 8 +- .../SinglePhaseHybridFVMKernels.hpp | 2 +- .../SinglePhaseHydrostaticPressureKernel.hpp | 214 +++++ .../singlePhase/SinglePhaseMobilityKernel.hpp | 149 +++ .../SinglePhaseProppantFluxKernels.cpp | 2 +- .../SinglePhaseResidualNormKernel.hpp | 140 +++ .../SinglePhaseSolutionCheckKernel.hpp | 73 ++ .../SinglePhaseSolutionScalingKernel.hpp | 76 ++ .../SinglePhaseStatisticsKernel.hpp | 134 +++ .../ThermalSinglePhaseBaseKernels.hpp | 79 +- .../multiphysics/HydrofractureSolver.cpp | 3 +- ...ePhasePoromechanicsConformingFractures.cpp | 3 +- ...glePhasePoromechanicsEmbeddedFractures.cpp | 1 + ...ePhasePoromechanicsConformingFractures.hpp | 30 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 30 +- ...ePhasePoromechanicsConformingFractures.hpp | 40 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 40 +- .../unitTests/fluidFlowTests/CMakeLists.txt | 2 +- ....cpp => testSinglePhaseMobilityKernel.cpp} | 2 +- 32 files changed, 1305 insertions(+), 1111 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp rename src/coreComponents/unitTests/fluidFlowTests/{testSinglePhaseBaseKernels.cpp => testSinglePhaseMobilityKernel.cpp} (98%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 50be7c96bc1..e36299701e7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -20,7 +20,7 @@ set( physicsSolvers_headers fluidFlow/FlowSolverBaseFields.hpp fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp fluidFlow/kernels/StencilWeightsUpdateKernel.hpp - fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp + fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp fluidFlow/kernels/HybridFVMHelperKernels.hpp fluidFlow/SourceFluxStatistics.hpp fluidFlow/proppantTransport/ProppantTransport.hpp @@ -28,7 +28,13 @@ set( physicsSolvers_headers fluidFlow/proppantTransport/ProppantTransportKernels.hpp fluidFlow/SinglePhaseBase.hpp fluidFlow/SinglePhaseBaseFields.hpp - fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp + fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp + fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp + fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp + fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp + fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp + fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp + fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp fluidFlow/SinglePhaseStatistics.hpp fluidFlow/SinglePhaseFVM.hpp fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index c095c79df49..ea89bb6786b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -711,12 +711,12 @@ void FlowSolverBase::saveAquiferConvergedState( real64 const & time, gravCoef.setName( getName() + "/accessors/" + fields::flow::gravityCoefficient::key() ); real64 const targetSetSumFluxes = sumAquiferFluxes( stencil, - aquiferBCWrapper, - pressure.toNestedViewConst(), - pressure_n.toNestedViewConst(), - gravCoef.toNestedViewConst(), - time, - dt ); + aquiferBCWrapper, + pressure.toNestedViewConst(), + pressure_n.toNestedViewConst(), + gravCoef.toNestedViewConst(), + time, + dt ); localIndex const aquiferIndex = aquiferNameToAquiferId.at( bc.getName() ); localSumFluxes[aquiferIndex] += targetSetSumFluxes; @@ -750,12 +750,12 @@ void FlowSolverBase::saveAquiferConvergedState( real64 const & time, */ real64 FlowSolverBase::sumAquiferFluxes( BoundaryStencil const & stencil, - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & presOld, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - real64 const & timeAtBeginningOfStep, - real64 const & dt ) + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & presOld, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + real64 const & timeAtBeginningOfStep, + real64 const & dt ) { using Order = BoundaryStencil::Order; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp index e9536c8c494..bfe3fd5ef60 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp @@ -36,8 +36,8 @@ namespace geos */ class FlowSolverBase : public SolverBase { -template< typename VIEWTYPE > -using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; public: @@ -201,13 +201,13 @@ using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; virtual void setConstitutiveNamesCallSuper( ElementSubRegionBase & subRegion ) const override; -real64 sumAquiferFluxes( BoundaryStencil const & stencil, - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & presOld, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - real64 const & timeAtBeginningOfStep, - real64 const & dt ); + real64 sumAquiferFluxes( BoundaryStencil const & stencil, + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & presOld, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + real64 const & timeAtBeginningOfStep, + real64 const & dt ); /// the number of Degrees of Freedom per cell integer m_numDofPerCell; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index 98e2f6aa0eb..0ff9dcfb0fe 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -40,8 +40,13 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp" namespace geos @@ -368,16 +373,16 @@ void SinglePhaseBase::updateMobility( ObjectManagerBase & dataGroup ) const ThermalFluidPropViews thermalFluidProps = getThermalFluidProperties( fluid ); - thermalSinglePhaseBaseKernels::MobilityKernel::launch< parallelDevicePolicy<> >( dataGroup.size(), - fluidProps.dens, - fluidProps.dDens_dPres, - thermalFluidProps.dDens_dTemp, - fluidProps.visc, - fluidProps.dVisc_dPres, - thermalFluidProps.dVisc_dTemp, - mob, - dMob_dPres, - dMob_dTemp ); + singlePhaseBaseKernels::MobilityKernel::launch< parallelDevicePolicy<> >( dataGroup.size(), + fluidProps.dens, + fluidProps.dDens_dPres, + thermalFluidProps.dDens_dTemp, + fluidProps.visc, + fluidProps.dVisc_dPres, + thermalFluidProps.dVisc_dTemp, + mob, + dMob_dPres, + dMob_dTemp ); } else { @@ -1328,7 +1333,7 @@ real64 SinglePhaseBase::scalingForSystemSolution( DomainPartition & domain, arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); auto const subRegionData = - singlePhaseBaseKernels::ScalingForSystemSolutionKernel:: + singlePhaseBaseKernels::SolutionScalingKernel:: launch< parallelDevicePolicy<> >( localSolution, rankOffset, dofNumber, ghostRank, m_maxAbsolutePresChange ); scalingFactor = std::min( scalingFactor, subRegionData.first ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp index 88088c1170e..c7065526cf1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASE_HPP_ #include "physicsSolvers/fluidFlow/FlowSolverBase.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" #include "constitutive/solid/CoupledSolidBase.hpp" @@ -458,7 +458,7 @@ void SinglePhaseBase::accumulationAssemblyLaunch( DofManager const & dofManager, else { singlePhaseBaseKernels:: - ElementBasedAssemblyKernelFactory:: + AccumulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, subRegion, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index ec19438134b..3fd96fddfb2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -33,8 +33,9 @@ #include "fieldSpecification/AquiferBoundaryCondition.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp index e35dfc9173c..f6ac3527e2f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp @@ -23,12 +23,16 @@ #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" #include "fieldSpecification/AquiferBoundaryCondition.hpp" #include "fieldSpecification/FieldSpecificationManager.hpp" +#include "discretizationMethods/NumericalMethodsManager.hpp" +#include "finiteVolume/FiniteVolumeManager.hpp" #include "finiteVolume/HybridMimeticDiscretization.hpp" #include "finiteVolume/MimeticInnerProductDispatch.hpp" #include "mainInterface/ProblemManager.hpp" +#include "mesh/DomainPartition.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp" /** diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp index 5988c145d1d..0e936987446 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp @@ -20,6 +20,7 @@ #include "SinglePhaseProppantBase.hpp" +#include "mesh/DomainPartition.hpp" #include "constitutive/ConstitutivePassThru.hpp" #include "constitutive/fluid/singlefluid/SlurryFluidSelector.hpp" #include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp index 6d7da35b3ef..c5cf2097191 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp @@ -19,12 +19,13 @@ #include "SinglePhaseStatistics.hpp" +#include "mesh/DomainPartition.hpp" #include "mainInterface/ProblemManager.hpp" #include "physicsSolvers/PhysicsSolverManager.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp index 0128341058f..951a58fcbba 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp @@ -988,7 +988,7 @@ class ElementBasedAssemblyKernelFactory }; -/******************************** ScalingForSystemSolutionKernel ********************************/ +/******************************** SolutionScalingKernelKernel ********************************/ /** * @class ScalingAndCheckingSystemSolutionKernelBase diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp new file mode 100644 index 00000000000..80380cb8259 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp @@ -0,0 +1,360 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SinglePhaseAccumulationKernels.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEACCUMULATIONKERNELS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEACCUMULATIONKERNELS_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** AccumulationKernel ********************************/ + +/** + * @class AccumulationKernel + * @brief Define the interface for the assembly kernel in charge of accumulation + */ +template< typename SUBREGION_TYPE, integer NUM_DOF > +class AccumulationKernel +{ + +public: + + /// Compute time value for the number of degrees of freedom + static constexpr integer numDof = NUM_DOF; + + /// Compute time value for the number of equations + static constexpr integer numEqn = NUM_DOF; + + /** + * @brief Constructor + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + AccumulationKernel( globalIndex const rankOffset, + string const dofKey, + SUBREGION_TYPE const & subRegion, + constitutive::SingleFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + : + m_rankOffset( rankOffset ), + m_dofNumber( subRegion.template getReference< array1d< globalIndex > >( dofKey ) ), + m_elemGhostRank( subRegion.ghostRank() ), + m_volume( subRegion.getElementVolume() ), + m_deltaVolume( subRegion.template getField< fields::flow::deltaVolume >() ), + m_porosity( solid.getPorosity() ), + m_dPoro_dPres( solid.getDporosity_dPressure() ), + m_density( fluid.density() ), + m_dDensity_dPres( fluid.dDensity_dPressure() ), + m_mass_n( subRegion.template getField< fields::flow::mass_n >() ), + m_localMatrix( localMatrix ), + m_localRhs( localRhs ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + // Pore volume information + + /// Pore volume at time n+1 + real64 poreVolume = 0.0; + + /// Derivative of pore volume with respect to pressure + real64 dPoreVolume_dPres = 0.0; + + // Residual information + + /// Index of the local row corresponding to this element + localIndex localRow = -1; + + /// Index of the matrix row/column corresponding to the dof in this element + globalIndex dofIndices[numDof]{}; + + /// Storage for the element local residual vector + real64 localResidual[numEqn]{}; + + /// Storage for the element local Jacobian matrix + real64 localJacobian[numEqn][numDof]{}; + + }; + + /** + * @brief Getter for the ghost rank of an element + * @param[in] ei the element index + * @return the ghost rank of the element + */ + GEOS_HOST_DEVICE + integer elemGhostRank( localIndex const ei ) const + { return m_elemGhostRank( ei ); } + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] ei the element index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + // initialize the pore volume + stack.poreVolume = ( m_volume[ei] + m_deltaVolume[ei] ) * m_porosity[ei][0]; + stack.dPoreVolume_dPres = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dPres[ei][0]; + + // set row index and degrees of freedom indices for this element + stack.localRow = m_dofNumber[ei] - m_rankOffset; + for( integer idof = 0; idof < numDof; ++idof ) + { + stack.dofIndices[idof] = m_dofNumber[ei] + idof; + } + } + + /** + * @brief Compute the local accumulation contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + * @param[in] kernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeAccumulation( localIndex const ei, + StackVariables & stack, + FUNC && kernelOp = NoOpFunc{} ) const + { + // Residual contribution is mass conservation in the cell + stack.localResidual[0] = stack.poreVolume * m_density[ei][0] - m_mass_n[ei]; + + // Derivative of residual wrt to pressure in the cell + stack.localJacobian[0][0] = stack.dPoreVolume_dPres * m_density[ei][0] + m_dDensity_dPres[ei][0] * stack.poreVolume; + + // Customize the kernel with this lambda + kernelOp(); + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void complete( localIndex const GEOS_UNUSED_PARAM( ei ), + StackVariables & stack ) const + { + // add contribution to global residual and jacobian (no need for atomics here) + m_localMatrix.template addToRow< serialAtomic >( stack.localRow, + stack.dofIndices, + stack.localJacobian[0], + numDof ); + m_localRhs[stack.localRow] += stack.localResidual[0]; + + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + GEOS_MARK_FUNCTION; + + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( kernelComponent.elemGhostRank( ei ) >= 0 ) + { + return; + } + + typename KERNEL_TYPE::StackVariables stack; + + kernelComponent.setup( ei, stack ); + kernelComponent.computeAccumulation( ei, stack ); + kernelComponent.complete( ei, stack ); + } ); + } + +protected: + + /// Offset for my MPI rank + globalIndex const m_rankOffset; + + /// View on the dof numbers + arrayView1d< globalIndex const > const m_dofNumber; + + /// View on the ghost ranks + arrayView1d< integer const > const m_elemGhostRank; + + /// View on the element volumes + arrayView1d< real64 const > const m_volume; + arrayView1d< real64 const > const m_deltaVolume; + + /// Views on the porosity + arrayView2d< real64 const > const m_porosity; + arrayView2d< real64 const > const m_dPoro_dPres; + + /// Views on density + arrayView2d< real64 const > const m_density; + arrayView2d< real64 const > const m_dDensity_dPres; + + /// View on mass + arrayView1d< real64 const > const m_mass_n; + + /// View on the local CRS matrix + CRSMatrixView< real64, globalIndex const > const m_localMatrix; + /// View on the local RHS + arrayView1d< real64 > const m_localRhs; + +}; + +/** + * @class SurfaceElementAccumulationKernel + * @brief Define the interface for the assembly kernel in charge of accumulation in SurfaceElementSubRegion + */ +class SurfaceElementAccumulationKernel : public AccumulationKernel< SurfaceElementSubRegion, 1 > +{ + +public: + + using Base = AccumulationKernel< SurfaceElementSubRegion, 1 >; + + /** + * @brief Constructor + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + SurfaceElementAccumulationKernel( globalIndex const rankOffset, + string const dofKey, + SurfaceElementSubRegion const & subRegion, + constitutive::SingleFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + : Base( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ) + , m_creationMass( subRegion.getField< fields::flow::massCreated >() ) + {} + + /** + * @brief Compute the local accumulation contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void computeAccumulation( localIndex const ei, + Base::StackVariables & stack ) const + { + Base::computeAccumulation( ei, stack, [&] () + { + if( Base::m_mass_n[ei] > 1.1 * m_creationMass[ei] ) + { + stack.localResidual[0] += m_creationMass[ei] * 0.25; + } + } ); + } + +protected: + + arrayView1d< real64 const > const m_creationMass; + +}; + +/** + * @class AccumulationKernelFactory + */ +class AccumulationKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename SUBREGION_TYPE > + static void + createAndLaunch( globalIndex const rankOffset, + string const dofKey, + SUBREGION_TYPE const & subRegion, + constitutive::SingleFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + if constexpr ( std::is_same_v< SUBREGION_TYPE, CellElementSubRegion > ) + { + integer constexpr NUM_DOF = 1; + AccumulationKernel< CellElementSubRegion, NUM_DOF > kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); + AccumulationKernel< CellElementSubRegion, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); + } + else if constexpr ( std::is_same_v< SUBREGION_TYPE, SurfaceElementSubRegion > ) + { + SurfaceElementAccumulationKernel kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); + SurfaceElementAccumulationKernel::launch< POLICY >( subRegion.size(), kernel ); + } + else + { + GEOS_ERROR( "Unsupported subregion type: " << typeid(SUBREGION_TYPE).name() ); + } + } + +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASEKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp deleted file mode 100644 index 31840f49d1f..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp +++ /dev/null @@ -1,897 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 SinglePhaseBaseKernels.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASEKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASEKERNELS_HPP - -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "linearAlgebra/interfaces/InterfaceTypes.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "codingUtilities/Utilities.hpp" - -namespace geos -{ - -namespace singlePhaseBaseKernels -{ - -/******************************** MobilityKernel ********************************/ - -struct MobilityKernel -{ - GEOS_HOST_DEVICE - inline - static void - compute( real64 const & dens, - real64 const & dDens_dPres, - real64 const & visc, - real64 const & dVisc_dPres, - real64 & mob, - real64 & dMob_dPres ) - { - mob = dens / visc; - dMob_dPres = dDens_dPres / visc - mob / visc * dVisc_dPres; - } - - GEOS_HOST_DEVICE - inline - static void - compute( real64 const & dens, - real64 const & visc, - real64 & mob ) - { - mob = dens / visc; - } - - template< typename POLICY > - static void launch( localIndex const size, - arrayView2d< real64 const > const & dens, - arrayView2d< real64 const > const & dDens_dPres, - arrayView2d< real64 const > const & visc, - arrayView2d< real64 const > const & dVisc_dPres, - arrayView1d< real64 > const & mob, - arrayView1d< real64 > const & dMob_dPres ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const a ) - { - compute( dens[a][0], - dDens_dPres[a][0], - visc[a][0], - dVisc_dPres[a][0], - mob[a], - dMob_dPres[a] ); - } ); - } - - template< typename POLICY > - static void launch( localIndex const size, - arrayView2d< real64 const > const & dens, - arrayView2d< real64 const > const & visc, - arrayView1d< real64 > const & mob ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const a ) - { - compute( dens[a][0], - visc[a][0], - mob[a] ); - } ); - } -}; - -/******************************** ElementBasedAssemblyKernel ********************************/ - -/** - * @class ElementBasedAssemblyKernel - * @brief Define the interface for the assembly kernel in charge of accumulation - */ -template< typename SUBREGION_TYPE, integer NUM_DOF > -class ElementBasedAssemblyKernel -{ - -public: - - /// Compute time value for the number of degrees of freedom - static constexpr integer numDof = NUM_DOF; - - /// Compute time value for the number of equations - static constexpr integer numEqn = NUM_DOF; - - /** - * @brief Constructor - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - ElementBasedAssemblyKernel( globalIndex const rankOffset, - string const dofKey, - SUBREGION_TYPE const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - : - m_rankOffset( rankOffset ), - m_dofNumber( subRegion.template getReference< array1d< globalIndex > >( dofKey ) ), - m_elemGhostRank( subRegion.ghostRank() ), - m_volume( subRegion.getElementVolume() ), - m_deltaVolume( subRegion.template getField< fields::flow::deltaVolume >() ), - m_porosity( solid.getPorosity() ), - m_dPoro_dPres( solid.getDporosity_dPressure() ), - m_density( fluid.density() ), - m_dDensity_dPres( fluid.dDensity_dPressure() ), - m_mass_n( subRegion.template getField< fields::flow::mass_n >() ), - m_localMatrix( localMatrix ), - m_localRhs( localRhs ) - {} - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables - { -public: - - // Pore volume information - - /// Pore volume at time n+1 - real64 poreVolume = 0.0; - - /// Derivative of pore volume with respect to pressure - real64 dPoreVolume_dPres = 0.0; - - // Residual information - - /// Index of the local row corresponding to this element - localIndex localRow = -1; - - /// Index of the matrix row/column corresponding to the dof in this element - globalIndex dofIndices[numDof]{}; - - /// Storage for the element local residual vector - real64 localResidual[numEqn]{}; - - /// Storage for the element local Jacobian matrix - real64 localJacobian[numEqn][numDof]{}; - - }; - - /** - * @brief Getter for the ghost rank of an element - * @param[in] ei the element index - * @return the ghost rank of the element - */ - GEOS_HOST_DEVICE - integer elemGhostRank( localIndex const ei ) const - { return m_elemGhostRank( ei ); } - - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] ei the element index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - void setup( localIndex const ei, - StackVariables & stack ) const - { - // initialize the pore volume - stack.poreVolume = ( m_volume[ei] + m_deltaVolume[ei] ) * m_porosity[ei][0]; - stack.dPoreVolume_dPres = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dPres[ei][0]; - - // set row index and degrees of freedom indices for this element - stack.localRow = m_dofNumber[ei] - m_rankOffset; - for( integer idof = 0; idof < numDof; ++idof ) - { - stack.dofIndices[idof] = m_dofNumber[ei] + idof; - } - } - - /** - * @brief Compute the local accumulation contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[inout] stack the stack variables - * @param[in] kernelOp the function used to customize the kernel - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void computeAccumulation( localIndex const ei, - StackVariables & stack, - FUNC && kernelOp = NoOpFunc{} ) const - { - // Residual contribution is mass conservation in the cell - stack.localResidual[0] = stack.poreVolume * m_density[ei][0] - m_mass_n[ei]; - - // Derivative of residual wrt to pressure in the cell - stack.localJacobian[0][0] = stack.dPoreVolume_dPres * m_density[ei][0] + m_dDensity_dPres[ei][0] * stack.poreVolume; - - // Customize the kernel with this lambda - kernelOp(); - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void complete( localIndex const GEOS_UNUSED_PARAM( ei ), - StackVariables & stack ) const - { - // add contribution to global residual and jacobian (no need for atomics here) - m_localMatrix.template addToRow< serialAtomic >( stack.localRow, - stack.dofIndices, - stack.localJacobian[0], - numDof ); - m_localRhs[stack.localRow] += stack.localResidual[0]; - - } - - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numElems the number of elements - * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables - */ - template< typename POLICY, typename KERNEL_TYPE > - static void - launch( localIndex const numElems, - KERNEL_TYPE const & kernelComponent ) - { - GEOS_MARK_FUNCTION; - - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( kernelComponent.elemGhostRank( ei ) >= 0 ) - { - return; - } - - typename KERNEL_TYPE::StackVariables stack; - - kernelComponent.setup( ei, stack ); - kernelComponent.computeAccumulation( ei, stack ); - kernelComponent.complete( ei, stack ); - } ); - } - -protected: - - /// Offset for my MPI rank - globalIndex const m_rankOffset; - - /// View on the dof numbers - arrayView1d< globalIndex const > const m_dofNumber; - - /// View on the ghost ranks - arrayView1d< integer const > const m_elemGhostRank; - - /// View on the element volumes - arrayView1d< real64 const > const m_volume; - arrayView1d< real64 const > const m_deltaVolume; - - /// Views on the porosity - arrayView2d< real64 const > const m_porosity; - arrayView2d< real64 const > const m_dPoro_dPres; - - /// Views on density - arrayView2d< real64 const > const m_density; - arrayView2d< real64 const > const m_dDensity_dPres; - - /// View on mass - arrayView1d< real64 const > const m_mass_n; - - /// View on the local CRS matrix - CRSMatrixView< real64, globalIndex const > const m_localMatrix; - /// View on the local RHS - arrayView1d< real64 > const m_localRhs; - -}; - -/** - * @class SurfaceElementBasedAssemblyKernel - * @brief Define the interface for the assembly kernel in charge of accumulation in SurfaceElementSubRegion - */ -class SurfaceElementBasedAssemblyKernel : public ElementBasedAssemblyKernel< SurfaceElementSubRegion, 1 > -{ - -public: - - using Base = ElementBasedAssemblyKernel< SurfaceElementSubRegion, 1 >; - - /** - * @brief Constructor - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - SurfaceElementBasedAssemblyKernel( globalIndex const rankOffset, - string const dofKey, - SurfaceElementSubRegion const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - : Base( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ) - , m_creationMass( subRegion.getField< fields::flow::massCreated >() ) - {} - - /** - * @brief Compute the local accumulation contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void computeAccumulation( localIndex const ei, - Base::StackVariables & stack ) const - { - Base::computeAccumulation( ei, stack, [&] () - { - if( Base::m_mass_n[ei] > 1.1 * m_creationMass[ei] ) - { - stack.localResidual[0] += m_creationMass[ei] * 0.25; - } - } ); - } - -protected: - - arrayView1d< real64 const > const m_creationMass; - -}; - -/** - * @class ElementBasedAssemblyKernelFactory - */ -class ElementBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( globalIndex const rankOffset, - string const dofKey, - CellElementSubRegion const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - integer constexpr NUM_DOF = 1; - - ElementBasedAssemblyKernel< CellElementSubRegion, NUM_DOF > - kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); - ElementBasedAssemblyKernel< CellElementSubRegion, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); - } - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( globalIndex const rankOffset, - string const dofKey, - SurfaceElementSubRegion const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - SurfaceElementBasedAssemblyKernel - kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); - SurfaceElementBasedAssemblyKernel::launch< POLICY >( subRegion.size(), kernel ); - } - -}; - -/******************************** ResidualNormKernel ********************************/ - -/** - * @class ResidualNormKernel - */ -class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > -{ -public: - - using Base = solverBaseKernels::ResidualNormKernelBase< 1 >; - using Base::m_minNormalizer; - using Base::m_rankOffset; - using Base::m_localResidual; - using Base::m_dofNumber; - - ResidualNormKernel( globalIndex const rankOffset, - arrayView1d< real64 const > const & localResidual, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< localIndex const > const & ghostRank, - ElementSubRegionBase const & subRegion, - real64 const minNormalizer ) - : Base( rankOffset, - localResidual, - dofNumber, - ghostRank, - minNormalizer ), - m_mass_n( subRegion.template getField< fields::flow::mass_n >() ) - {} - - GEOS_HOST_DEVICE - virtual void computeLinf( localIndex const ei, - LinfStackVariables & stack ) const override - { - real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_mass_n[ei] ); - real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow] ) / massNormalizer; - if( valMass > stack.localValue[0] ) - { - stack.localValue[0] = valMass; - } - } - - GEOS_HOST_DEVICE - virtual void computeL2( localIndex const ei, - L2StackVariables & stack ) const override - { - real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_mass_n[ei] ); - stack.localValue[0] += m_localResidual[stack.localRow] * m_localResidual[stack.localRow]; - stack.localNormalizer[0] += massNormalizer; - } - - -protected: - - /// View on mass at the previous converged time step - arrayView1d< real64 const > const m_mass_n; - -}; - -/** - * @class ResidualNormKernelFactory - */ -class ResidualNormKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] normType the type of norm used (Linf or L2) - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] localResidual the residual vector on my MPI rank - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[out] residualNorm the residual norm on the subRegion - * @param[out] residualNormalizer the residual normalizer on the subRegion - */ - template< typename POLICY > - static void - createAndLaunch( solverBaseKernels::NormType const normType, - globalIndex const rankOffset, - string const dofKey, - arrayView1d< real64 const > const & localResidual, - ElementSubRegionBase const & subRegion, - real64 const minNormalizer, - real64 (& residualNorm)[1], - real64 (& residualNormalizer)[1] ) - { - arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); - arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - - ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, subRegion, minNormalizer ); - if( normType == solverBaseKernels::NormType::Linf ) - { - ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); - } - else // L2 norm - { - ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); - } - } - -}; - -/******************************** SolutionCheckKernel ********************************/ - -struct SolutionCheckKernel -{ - template< typename POLICY > - static std::pair< integer, real64 > launch( arrayView1d< real64 const > const & localSolution, - globalIndex const rankOffset, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< integer const > const & ghostRank, - arrayView1d< real64 const > const & pres, - real64 const scalingFactor ) - { - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegativePressures( 0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPres( 0.0 ); - - forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( ghostRank[ei] < 0 && dofNumber[ei] >= 0 ) - { - localIndex const lid = dofNumber[ei] - rankOffset; - real64 const newPres = pres[ei] + scalingFactor * localSolution[lid]; - - if( newPres < 0.0 ) - { - numNegativePressures += 1; - minPres.min( newPres ); - } - } - - } ); - - return { numNegativePressures.get(), minPres.get() }; - } - -}; - -/******************************** ScalingForSystemSolutionKernel ********************************/ - -struct ScalingForSystemSolutionKernel -{ - template< typename POLICY > - static std::pair< real64, real64 > launch( arrayView1d< real64 const > const & localSolution, - globalIndex const rankOffset, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< integer const > const & ghostRank, - real64 const maxAbsolutePresChange ) - { - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > scalingFactor( 1.0 ); - RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 ); - - forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) mutable - { - if( ghostRank[ei] < 0 && dofNumber[ei] >= 0 ) - { - localIndex const lid = dofNumber[ei] - rankOffset; - - // compute the change in pressure - real64 const absPresChange = LvArray::math::abs( localSolution[lid] ); - maxDeltaPres.max( absPresChange ); - - // maxAbsolutePresChange <= 0.0 means that scaling is disabled, and we are only collecting maxDeltaPres in this kernel - if( maxAbsolutePresChange > 0.0 && absPresChange > maxAbsolutePresChange ) - { - real64 const presScalingFactor = maxAbsolutePresChange / absPresChange; - scalingFactor.min( presScalingFactor ); - } - } - - } ); - - return { scalingFactor.get(), maxDeltaPres.get() }; - } - -}; - -/******************************** StatisticsKernel ********************************/ - -struct StatisticsKernel -{ - static void - saveDeltaPressure( localIndex const size, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & initPres, - arrayView1d< real64 > const & deltaPres ) - { - forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - deltaPres[ei] = pres[ei] - initPres[ei]; - } ); - } - - static void - launch( localIndex const size, - arrayView1d< integer const > const & elemGhostRank, - arrayView1d< real64 const > const & volume, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & deltaPres, - arrayView1d< real64 const > const & temp, - arrayView1d< real64 const > const & refPorosity, - arrayView2d< real64 const > const & porosity, - arrayView2d< real64 const > const & density, - real64 & minPres, - real64 & avgPresNumerator, - real64 & maxPres, - real64 & minDeltaPres, - real64 & maxDeltaPres, - real64 & minTemp, - real64 & avgTempNumerator, - real64 & maxTemp, - real64 & totalUncompactedPoreVol, - real64 & totalPoreVol, - real64 & totalMass ) - { - RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinPres( LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgPresNumerator( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPres( -LvArray::NumericLimits< real64 >::max ); - - RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinDeltaPres( LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxDeltaPres( -LvArray::NumericLimits< real64 >::max ); - - RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinTemp( LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgTempNumerator( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTemp( -LvArray::NumericLimits< real64 >::max ); - - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalUncompactedPoreVol( 0.0 ); - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalPoreVol( 0.0 ); - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalMass( 0.0 ); - - forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( elemGhostRank[ei] >= 0 ) - { - return; - } - - // To match our "reference", we have to use reference porosity here, not the actual porosity when we compute averages - real64 const uncompactedPoreVol = volume[ei] * refPorosity[ei]; - real64 const dynamicPoreVol = volume[ei] * porosity[ei][0]; - - subRegionMinPres.min( pres[ei] ); - subRegionAvgPresNumerator += uncompactedPoreVol * pres[ei]; - subRegionMaxPres.max( pres[ei] ); - - subRegionMinDeltaPres.min( deltaPres[ei] ); - subRegionMaxDeltaPres.max( deltaPres[ei] ); - - subRegionMinTemp.min( temp[ei] ); - subRegionAvgTempNumerator += uncompactedPoreVol * temp[ei]; - subRegionMaxTemp.max( temp[ei] ); - - subRegionTotalUncompactedPoreVol += uncompactedPoreVol; - subRegionTotalPoreVol += dynamicPoreVol; - subRegionTotalMass += dynamicPoreVol * density[ei][0]; - } ); - - minPres = subRegionMinPres.get(); - avgPresNumerator = subRegionAvgPresNumerator.get(); - maxPres = subRegionMaxPres.get(); - - minDeltaPres = subRegionMinDeltaPres.get(); - maxDeltaPres = subRegionMaxDeltaPres.get(); - - minTemp = subRegionMinTemp.get(); - avgTempNumerator = subRegionAvgTempNumerator.get(); - maxTemp = subRegionMaxTemp.get(); - - totalUncompactedPoreVol = subRegionTotalUncompactedPoreVol.get(); - totalPoreVol = subRegionTotalPoreVol.get(); - totalMass = subRegionTotalMass.get(); - } -}; - - -/******************************** HydrostaticPressureKernel ********************************/ - -struct HydrostaticPressureKernel -{ - - template< typename FLUID_WRAPPER > - static bool - computeHydrostaticPressure( integer const maxNumEquilIterations, - real64 const & equilTolerance, - real64 const (&gravVector)[ 3 ], - FLUID_WRAPPER fluidWrapper, - real64 const & refElevation, - real64 const & refPres, - real64 const & refDens, - real64 const & newElevation, - real64 & newPres, - real64 & newDens ) - { - // Step 1: guess the pressure with the refDensity - - real64 const gravCoef = gravVector[2] * ( refElevation - newElevation ); - real64 pres0 = refPres - refDens * gravCoef; - real64 pres1 = 0.0; - - // Step 2: compute the mass density at this elevation using the guess, and update pressure - - real64 dens = 0.0; - real64 visc = 0.0; - constitutive::SingleFluidBaseUpdate::computeValues( fluidWrapper, - pres0, - dens, - visc ); - pres1 = refPres - 0.5 * ( refDens + dens ) * gravCoef; - - // Step 3: fixed-point iteration until convergence - - bool equilHasConverged = false; - for( localIndex eqIter = 0; eqIter < maxNumEquilIterations; ++eqIter ) - { - - // check convergence - equilHasConverged = ( LvArray::math::abs( pres0 - pres1 ) < equilTolerance ); - pres0 = pres1; - - // if converged, move on - if( equilHasConverged ) - { - break; - } - - // compute the density at this elevation using the previous pressure, and compute the new pressure - constitutive::SingleFluidBaseUpdate::computeValues( fluidWrapper, - pres0, - dens, - visc ); - pres1 = refPres - 0.5 * ( refDens + dens ) * gravCoef; - } - - // Step 4: save the hydrostatic pressure and the corresponding density - - newPres = pres1; - newDens = dens; - - return equilHasConverged; - } - - - template< typename FLUID_WRAPPER > - static bool - launch( localIndex const size, - integer const maxNumEquilIterations, - real64 const equilTolerance, - real64 const (&gravVector)[ 3 ], - real64 const & minElevation, - real64 const & elevationIncrement, - real64 const & datumElevation, - real64 const & datumPres, - FLUID_WRAPPER fluidWrapper, - arrayView1d< arrayView1d< real64 > const > elevationValues, - arrayView1d< real64 > pressureValues ) - { - bool hasConverged = true; - - // Step 1: compute the mass density at the datum elevation - - real64 datumDens = 0.0; - real64 datumVisc = 0.0; - - constitutive::SingleFluidBaseUpdate::computeValues( fluidWrapper, - datumPres, - datumDens, - datumVisc ); - - // Step 2: find the closest elevation to datumElevation - - forAll< parallelHostPolicy >( size, [=] ( localIndex const i ) - { - real64 const elevation = minElevation + i * elevationIncrement; - elevationValues[0][i] = elevation; - } ); - integer const iRef = LvArray::sortedArrayManipulation::find( elevationValues[0].begin(), - elevationValues[0].size(), - datumElevation ); - - - // Step 3: compute the mass density and pressure at the reference elevation - - array1d< real64 > dens( pressureValues.size() ); - - bool const hasConvergedRef = - computeHydrostaticPressure( maxNumEquilIterations, - equilTolerance, - gravVector, - fluidWrapper, - datumElevation, - datumPres, - datumDens, - elevationValues[0][iRef], - pressureValues[iRef], - dens[iRef] ); - if( !hasConvergedRef ) - { - return false; - } - - - // Step 4: for each elevation above the reference elevation, compute the pressure - - localIndex const numEntriesAboveRef = size - iRef - 1; - forAll< serialPolicy >( numEntriesAboveRef, [=, &hasConverged] ( localIndex const i ) - { - bool const hasConvergedAboveRef = - computeHydrostaticPressure( maxNumEquilIterations, - equilTolerance, - gravVector, - fluidWrapper, - elevationValues[0][iRef+i], - pressureValues[iRef+i], - dens[iRef+i], - elevationValues[0][iRef+i+1], - pressureValues[iRef+i+1], - dens[iRef+i+1] ); - if( !hasConvergedAboveRef ) - { - hasConverged = false; - } - - - } ); - - // Step 5: for each elevation below the reference elevation, compute the pressure - - localIndex const numEntriesBelowRef = iRef; - forAll< serialPolicy >( numEntriesBelowRef, [=, &hasConverged] ( localIndex const i ) - { - bool const hasConvergedBelowRef = - computeHydrostaticPressure( maxNumEquilIterations, - equilTolerance, - gravVector, - fluidWrapper, - elevationValues[0][iRef-i], - pressureValues[iRef-i], - dens[iRef-i], - elevationValues[0][iRef-i-1], - pressureValues[iRef-i-1], - dens[iRef-i-1] ); - if( !hasConvergedBelowRef ) - { - hasConverged = false; - } - } ); - - return hasConverged; - } -}; - - -} // namespace singlePhaseBaseKernels - -} // namespace geos - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASEKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp index 222fe94041f..564a09000a7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp @@ -36,7 +36,8 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" @@ -359,21 +360,21 @@ class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase localIndex const subRegionIndex[2] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; localIndex const elementIndex[2] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; - fluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, - trans, - dTrans, - m_pres, - m_gravCoef, - m_dens, - m_dDens_dPres, - m_mob, - m_dMob_dPres, - alpha, - mobility, - potGrad, - fluxVal, - dFlux_dP, - dFlux_dTrans ); + singlePhaseFluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, + trans, + dTrans, + m_pres, + m_gravCoef, + m_dens, + m_dDens_dPres, + m_mob, + m_dMob_dPres, + alpha, + mobility, + potGrad, + fluxVal, + dFlux_dP, + dFlux_dTrans ); // populate local flux vector and derivatives stack.localFlux[k[0]*numEqn] += m_dt * fluxVal; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp index e555c771db0..b3b9f6a5a1d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp @@ -21,16 +21,12 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUXKERNELSHELPER_HPP #include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "finiteVolume/BoundaryStencil.hpp" -#include "linearAlgebra/interfaces/InterfaceTypes.hpp" #include "mesh/ElementRegionManager.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" namespace geos { -namespace fluxKernelsHelper +namespace singlePhaseFluxKernelsHelper { /** @@ -289,7 +285,7 @@ void computeConductiveFlux( localIndex const ( &seri )[2], } } -} // namespace fluxKernelsHelper +} // namespace singlePhaseFluxKernelsHelper } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp index 05d203538b5..a9447f1b935 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp @@ -37,7 +37,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" #include "codingUtilities/Utilities.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp new file mode 100644 index 00000000000..f702d0a7218 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp @@ -0,0 +1,214 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SinglePhaseHydrostaticPressureKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYDROSTATICPRESSUREKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYDROSTATICPRESSUREKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** HydrostaticPressureKernel ********************************/ + +struct HydrostaticPressureKernel +{ + + template< typename FLUID_WRAPPER > + static bool + computeHydrostaticPressure( integer const maxNumEquilIterations, + real64 const & equilTolerance, + real64 const (&gravVector)[ 3 ], + FLUID_WRAPPER fluidWrapper, + real64 const & refElevation, + real64 const & refPres, + real64 const & refDens, + real64 const & newElevation, + real64 & newPres, + real64 & newDens ) + { + // Step 1: guess the pressure with the refDensity + + real64 const gravCoef = gravVector[2] * ( refElevation - newElevation ); + real64 pres0 = refPres - refDens * gravCoef; + real64 pres1 = 0.0; + + // Step 2: compute the mass density at this elevation using the guess, and update pressure + + real64 dens = 0.0; + real64 visc = 0.0; + constitutive::SingleFluidBaseUpdate::computeValues( fluidWrapper, + pres0, + dens, + visc ); + pres1 = refPres - 0.5 * ( refDens + dens ) * gravCoef; + + // Step 3: fixed-point iteration until convergence + + bool equilHasConverged = false; + for( localIndex eqIter = 0; eqIter < maxNumEquilIterations; ++eqIter ) + { + + // check convergence + equilHasConverged = ( LvArray::math::abs( pres0 - pres1 ) < equilTolerance ); + pres0 = pres1; + + // if converged, move on + if( equilHasConverged ) + { + break; + } + + // compute the density at this elevation using the previous pressure, and compute the new pressure + constitutive::SingleFluidBaseUpdate::computeValues( fluidWrapper, + pres0, + dens, + visc ); + pres1 = refPres - 0.5 * ( refDens + dens ) * gravCoef; + } + + // Step 4: save the hydrostatic pressure and the corresponding density + + newPres = pres1; + newDens = dens; + + return equilHasConverged; + } + + + template< typename FLUID_WRAPPER > + static bool + launch( localIndex const size, + integer const maxNumEquilIterations, + real64 const equilTolerance, + real64 const (&gravVector)[ 3 ], + real64 const & minElevation, + real64 const & elevationIncrement, + real64 const & datumElevation, + real64 const & datumPres, + FLUID_WRAPPER fluidWrapper, + arrayView1d< arrayView1d< real64 > const > elevationValues, + arrayView1d< real64 > pressureValues ) + { + bool hasConverged = true; + + // Step 1: compute the mass density at the datum elevation + + real64 datumDens = 0.0; + real64 datumVisc = 0.0; + + constitutive::SingleFluidBaseUpdate::computeValues( fluidWrapper, + datumPres, + datumDens, + datumVisc ); + + // Step 2: find the closest elevation to datumElevation + + forAll< parallelHostPolicy >( size, [=] ( localIndex const i ) + { + real64 const elevation = minElevation + i * elevationIncrement; + elevationValues[0][i] = elevation; + } ); + integer const iRef = LvArray::sortedArrayManipulation::find( elevationValues[0].begin(), + elevationValues[0].size(), + datumElevation ); + + + // Step 3: compute the mass density and pressure at the reference elevation + + array1d< real64 > dens( pressureValues.size() ); + + bool const hasConvergedRef = + computeHydrostaticPressure( maxNumEquilIterations, + equilTolerance, + gravVector, + fluidWrapper, + datumElevation, + datumPres, + datumDens, + elevationValues[0][iRef], + pressureValues[iRef], + dens[iRef] ); + if( !hasConvergedRef ) + { + return false; + } + + + // Step 4: for each elevation above the reference elevation, compute the pressure + + localIndex const numEntriesAboveRef = size - iRef - 1; + forAll< serialPolicy >( numEntriesAboveRef, [=, &hasConverged] ( localIndex const i ) + { + bool const hasConvergedAboveRef = + computeHydrostaticPressure( maxNumEquilIterations, + equilTolerance, + gravVector, + fluidWrapper, + elevationValues[0][iRef+i], + pressureValues[iRef+i], + dens[iRef+i], + elevationValues[0][iRef+i+1], + pressureValues[iRef+i+1], + dens[iRef+i+1] ); + if( !hasConvergedAboveRef ) + { + hasConverged = false; + } + + + } ); + + // Step 5: for each elevation below the reference elevation, compute the pressure + + localIndex const numEntriesBelowRef = iRef; + forAll< serialPolicy >( numEntriesBelowRef, [=, &hasConverged] ( localIndex const i ) + { + bool const hasConvergedBelowRef = + computeHydrostaticPressure( maxNumEquilIterations, + equilTolerance, + gravVector, + fluidWrapper, + elevationValues[0][iRef-i], + pressureValues[iRef-i], + dens[iRef-i], + elevationValues[0][iRef-i-1], + pressureValues[iRef-i-1], + dens[iRef-i-1] ); + if( !hasConvergedBelowRef ) + { + hasConverged = false; + } + } ); + + return hasConverged; + } +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYDROSTATICPRESSUREKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp new file mode 100644 index 00000000000..d94e81fd379 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp @@ -0,0 +1,149 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SinglePhaseMobilityKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEMOBILITYKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEMOBILITYKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** MobilityKernel ********************************/ + +struct MobilityKernel +{ + // Isothermal version + GEOS_HOST_DEVICE + inline + static void + compute( real64 const & dens, + real64 const & dDens_dPres, + real64 const & visc, + real64 const & dVisc_dPres, + real64 & mob, + real64 & dMob_dPres ) + { + mob = dens / visc; + dMob_dPres = dDens_dPres / visc - mob / visc * dVisc_dPres; + } + +// Thermal version + GEOS_HOST_DEVICE + inline + static void + compute( real64 const & dens, + real64 const & dDens_dPres, + real64 const & dDens_dTemp, + real64 const & visc, + real64 const & dVisc_dPres, + real64 const & dVisc_dTemp, + real64 & mob, + real64 & dMob_dPres, + real64 & dMob_dTemp ) + { + mob = dens / visc; + dMob_dPres = dDens_dPres / visc - mob / visc * dVisc_dPres; + dMob_dTemp = dDens_dTemp / visc - mob / visc * dVisc_dTemp; + } + +// Value-only (no derivatives) version + GEOS_HOST_DEVICE + inline + static void + compute( real64 const & dens, + real64 const & visc, + real64 & mob ) + { + mob = dens / visc; + } + + // Isothermal version + template< typename POLICY > + static void launch( localIndex const size, + arrayView2d< real64 const > const & dens, + arrayView2d< real64 const > const & dDens_dPres, + arrayView2d< real64 const > const & visc, + arrayView2d< real64 const > const & dVisc_dPres, + arrayView1d< real64 > const & mob, + arrayView1d< real64 > const & dMob_dPres ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const a ) + { + compute( dens[a][0], + dDens_dPres[a][0], + visc[a][0], + dVisc_dPres[a][0], + mob[a], + dMob_dPres[a] ); + } ); + } + + // Thermal version + template< typename POLICY > + static void launch( localIndex const size, + arrayView2d< real64 const > const & dens, + arrayView2d< real64 const > const & dDens_dPres, + arrayView2d< real64 const > const & dDens_dTemp, + arrayView2d< real64 const > const & visc, + arrayView2d< real64 const > const & dVisc_dPres, + arrayView2d< real64 const > const & dVisc_dTemp, + arrayView1d< real64 > const & mob, + arrayView1d< real64 > const & dMob_dPres, + arrayView1d< real64 > const & dMob_dTemp ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const a ) + { + compute( dens[a][0], + dDens_dPres[a][0], + dDens_dTemp[a][0], + visc[a][0], + dVisc_dPres[a][0], + dVisc_dTemp[a][0], + mob[a], + dMob_dPres[a], + dMob_dTemp[a] ); + } ); + } + +// Value-only (no derivatives) version + template< typename POLICY > + static void launch( localIndex const size, + arrayView2d< real64 const > const & dens, + arrayView2d< real64 const > const & visc, + arrayView1d< real64 > const & mob ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const a ) + { + compute( dens[a][0], + visc[a][0], + mob[a] ); + } ); + } +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEMOBILITYKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp index 89e396c0990..e283a25bb44 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp @@ -27,7 +27,7 @@ namespace geos namespace singlePhaseProppantFluxKernels { -using namespace fluxKernelsHelper; +using namespace singlePhaseFluxKernelsHelper; void FaceElementFluxKernel:: diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp new file mode 100644 index 00000000000..9dfeab7e9cc --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp @@ -0,0 +1,140 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SinglePhaseResidualNormKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASERESIDUALNORMKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASERESIDUALNORMKERNEL_HPP + +#include "physicsSolvers/SolverBaseKernels.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** ResidualNormKernel ********************************/ + +/** + * @class ResidualNormKernel + */ +class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > +{ +public: + + using Base = solverBaseKernels::ResidualNormKernelBase< 1 >; + using Base::m_minNormalizer; + using Base::m_rankOffset; + using Base::m_localResidual; + using Base::m_dofNumber; + + ResidualNormKernel( globalIndex const rankOffset, + arrayView1d< real64 const > const & localResidual, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< localIndex const > const & ghostRank, + ElementSubRegionBase const & subRegion, + real64 const minNormalizer ) + : Base( rankOffset, + localResidual, + dofNumber, + ghostRank, + minNormalizer ), + m_mass_n( subRegion.template getField< fields::flow::mass_n >() ) + {} + + GEOS_HOST_DEVICE + virtual void computeLinf( localIndex const ei, + LinfStackVariables & stack ) const override + { + real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_mass_n[ei] ); + real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow] ) / massNormalizer; + if( valMass > stack.localValue[0] ) + { + stack.localValue[0] = valMass; + } + } + + GEOS_HOST_DEVICE + virtual void computeL2( localIndex const ei, + L2StackVariables & stack ) const override + { + real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_mass_n[ei] ); + stack.localValue[0] += m_localResidual[stack.localRow] * m_localResidual[stack.localRow]; + stack.localNormalizer[0] += massNormalizer; + } + + +protected: + + /// View on mass at the previous converged time step + arrayView1d< real64 const > const m_mass_n; + +}; + +/** + * @class ResidualNormKernelFactory + */ +class ResidualNormKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] normType the type of norm used (Linf or L2) + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] localResidual the residual vector on my MPI rank + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[out] residualNorm the residual norm on the subRegion + * @param[out] residualNormalizer the residual normalizer on the subRegion + */ + template< typename POLICY > + static void + createAndLaunch( solverBaseKernels::NormType const normType, + globalIndex const rankOffset, + string const dofKey, + arrayView1d< real64 const > const & localResidual, + ElementSubRegionBase const & subRegion, + real64 const minNormalizer, + real64 (& residualNorm)[1], + real64 (& residualNormalizer)[1] ) + { + arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, subRegion, minNormalizer ); + if( normType == solverBaseKernels::NormType::Linf ) + { + ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); + } + else // L2 norm + { + ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); + } + } + +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASERESIDUALNORMKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp new file mode 100644 index 00000000000..4a9a778ef6e --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp @@ -0,0 +1,73 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SinglePhaseSolutionCheckKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONCHECKKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONCHECKKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** SolutionCheckKernel ********************************/ + +struct SolutionCheckKernel +{ + template< typename POLICY > + static std::pair< integer, real64 > launch( arrayView1d< real64 const > const & localSolution, + globalIndex const rankOffset, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< integer const > const & ghostRank, + arrayView1d< real64 const > const & pres, + real64 const scalingFactor ) + { + RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegativePressures( 0 ); + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPres( 0.0 ); + + forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( ghostRank[ei] < 0 && dofNumber[ei] >= 0 ) + { + localIndex const lid = dofNumber[ei] - rankOffset; + real64 const newPres = pres[ei] + scalingFactor * localSolution[lid]; + + if( newPres < 0.0 ) + { + numNegativePressures += 1; + minPres.min( newPres ); + } + } + + } ); + + return { numNegativePressures.get(), minPres.get() }; + } + +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONCHECKKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp new file mode 100644 index 00000000000..39d007994ed --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp @@ -0,0 +1,76 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SinglePhaseSolutionScalingKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONSCALINGKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONSCALINGKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** SolutionScalingKernel ********************************/ + +struct SolutionScalingKernel +{ + template< typename POLICY > + static std::pair< real64, real64 > launch( arrayView1d< real64 const > const & localSolution, + globalIndex const rankOffset, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< integer const > const & ghostRank, + real64 const maxAbsolutePresChange ) + { + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > scalingFactor( 1.0 ); + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 ); + + forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) mutable + { + if( ghostRank[ei] < 0 && dofNumber[ei] >= 0 ) + { + localIndex const lid = dofNumber[ei] - rankOffset; + + // compute the change in pressure + real64 const absPresChange = LvArray::math::abs( localSolution[lid] ); + maxDeltaPres.max( absPresChange ); + + // maxAbsolutePresChange <= 0.0 means that scaling is disabled, and we are only collecting maxDeltaPres in this kernel + if( maxAbsolutePresChange > 0.0 && absPresChange > maxAbsolutePresChange ) + { + real64 const presScalingFactor = maxAbsolutePresChange / absPresChange; + scalingFactor.min( presScalingFactor ); + } + } + + } ); + + return { scalingFactor.get(), maxDeltaPres.get() }; + } + +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONSCALINGKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp new file mode 100644 index 00000000000..7caf93efefc --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp @@ -0,0 +1,134 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SinglePhaseStatisticsKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESTATISTICSKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESTATISTICSKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** StatisticsKernel ********************************/ + +struct StatisticsKernel +{ + static void + saveDeltaPressure( localIndex const size, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & initPres, + arrayView1d< real64 > const & deltaPres ) + { + forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + deltaPres[ei] = pres[ei] - initPres[ei]; + } ); + } + + static void + launch( localIndex const size, + arrayView1d< integer const > const & elemGhostRank, + arrayView1d< real64 const > const & volume, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & deltaPres, + arrayView1d< real64 const > const & temp, + arrayView1d< real64 const > const & refPorosity, + arrayView2d< real64 const > const & porosity, + arrayView2d< real64 const > const & density, + real64 & minPres, + real64 & avgPresNumerator, + real64 & maxPres, + real64 & minDeltaPres, + real64 & maxDeltaPres, + real64 & minTemp, + real64 & avgTempNumerator, + real64 & maxTemp, + real64 & totalUncompactedPoreVol, + real64 & totalPoreVol, + real64 & totalMass ) + { + RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinPres( LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgPresNumerator( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPres( -LvArray::NumericLimits< real64 >::max ); + + RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinDeltaPres( LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxDeltaPres( -LvArray::NumericLimits< real64 >::max ); + + RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinTemp( LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgTempNumerator( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTemp( -LvArray::NumericLimits< real64 >::max ); + + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalUncompactedPoreVol( 0.0 ); + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalPoreVol( 0.0 ); + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalMass( 0.0 ); + + forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( elemGhostRank[ei] >= 0 ) + { + return; + } + + // To match our "reference", we have to use reference porosity here, not the actual porosity when we compute averages + real64 const uncompactedPoreVol = volume[ei] * refPorosity[ei]; + real64 const dynamicPoreVol = volume[ei] * porosity[ei][0]; + + subRegionMinPres.min( pres[ei] ); + subRegionAvgPresNumerator += uncompactedPoreVol * pres[ei]; + subRegionMaxPres.max( pres[ei] ); + + subRegionMinDeltaPres.min( deltaPres[ei] ); + subRegionMaxDeltaPres.max( deltaPres[ei] ); + + subRegionMinTemp.min( temp[ei] ); + subRegionAvgTempNumerator += uncompactedPoreVol * temp[ei]; + subRegionMaxTemp.max( temp[ei] ); + + subRegionTotalUncompactedPoreVol += uncompactedPoreVol; + subRegionTotalPoreVol += dynamicPoreVol; + subRegionTotalMass += dynamicPoreVol * density[ei][0]; + } ); + + minPres = subRegionMinPres.get(); + avgPresNumerator = subRegionAvgPresNumerator.get(); + maxPres = subRegionMaxPres.get(); + + minDeltaPres = subRegionMinDeltaPres.get(); + maxDeltaPres = subRegionMaxDeltaPres.get(); + + minTemp = subRegionMinTemp.get(); + avgTempNumerator = subRegionAvgTempNumerator.get(); + maxTemp = subRegionMaxTemp.get(); + + totalUncompactedPoreVol = subRegionTotalUncompactedPoreVol.get(); + totalPoreVol = subRegionTotalPoreVol.get(); + totalMass = subRegionTotalMass.get(); + } +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESTATISTICSKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp index 271b7e51ac0..6b7182174b0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" namespace geos { @@ -28,79 +28,6 @@ namespace geos namespace thermalSinglePhaseBaseKernels { -/******************************** MobilityKernel ********************************/ - -struct MobilityKernel -{ - GEOS_HOST_DEVICE - inline - static void - compute( real64 const & dens, - real64 const & dDens_dPres, - real64 const & dDens_dTemp, - real64 const & visc, - real64 const & dVisc_dPres, - real64 const & dVisc_dTemp, - real64 & mob, - real64 & dMob_dPres, - real64 & dMob_dTemp ) - { - mob = dens / visc; - dMob_dPres = dDens_dPres / visc - mob / visc * dVisc_dPres; - dMob_dTemp = dDens_dTemp / visc - mob / visc * dVisc_dTemp; - } - - GEOS_HOST_DEVICE - inline - static void - compute( real64 const & dens, - real64 const & visc, - real64 & mob ) - { - mob = dens / visc; - } - - template< typename POLICY > - static void launch( localIndex const size, - arrayView2d< real64 const > const & dens, - arrayView2d< real64 const > const & dDens_dPres, - arrayView2d< real64 const > const & dDens_dTemp, - arrayView2d< real64 const > const & visc, - arrayView2d< real64 const > const & dVisc_dPres, - arrayView2d< real64 const > const & dVisc_dTemp, - arrayView1d< real64 > const & mob, - arrayView1d< real64 > const & dMob_dPres, - arrayView1d< real64 > const & dMob_dTemp ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const a ) - { - compute( dens[a][0], - dDens_dPres[a][0], - dDens_dTemp[a][0], - visc[a][0], - dVisc_dPres[a][0], - dVisc_dTemp[a][0], - mob[a], - dMob_dPres[a], - dMob_dTemp[a] ); - } ); - } - - template< typename POLICY > - static void launch( localIndex const size, - arrayView2d< real64 const > const & dens, - arrayView2d< real64 const > const & visc, - arrayView1d< real64 > const & mob ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const a ) - { - compute( dens[a][0], - visc[a][0], - mob[a] ); - } ); - } -}; - /******************************** ElementBasedAssemblyKernel ********************************/ /** @@ -108,12 +35,12 @@ struct MobilityKernel * @brief Define the interface for the assembly kernel in charge of accumulation */ template< typename SUBREGION_TYPE, integer NUM_DOF > -class ElementBasedAssemblyKernel : public singlePhaseBaseKernels::ElementBasedAssemblyKernel< SUBREGION_TYPE, NUM_DOF > +class ElementBasedAssemblyKernel : public singlePhaseBaseKernels::AccumulationKernel< SUBREGION_TYPE, NUM_DOF > { public: - using Base = singlePhaseBaseKernels::ElementBasedAssemblyKernel< SUBREGION_TYPE, NUM_DOF >; + using Base = singlePhaseBaseKernels::AccumulationKernel< SUBREGION_TYPE, NUM_DOF >; using Base::numDof; using Base::numEqn; using Base::m_rankOffset; diff --git a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp index 301eb93de28..3110402a96d 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp @@ -21,13 +21,14 @@ #include "constitutive/contact/HydraulicApertureRelationSelector.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" #include "physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp" #include "physicsSolvers/solidMechanics/SolidMechanicsFields.hpp" #include "physicsSolvers/multiphysics/SinglePhasePoromechanics.hpp" #include "physicsSolvers/multiphysics/MultiphasePoromechanics.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "mesh/MeshFields.hpp" -#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp index 32f5980986e..dd7347c4134 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp @@ -21,15 +21,16 @@ #include "constitutive/solid/PorousSolid.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" +#include "constitutive/contact/HydraulicApertureRelationSelector.hpp" #include "linearAlgebra/solvers/BlockPreconditioner.hpp" #include "linearAlgebra/solvers/SeparateComponentPreconditioner.hpp" -#include "constitutive/contact/HydraulicApertureRelationSelector.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanics.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanics.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsFractures.hpp" #include "physicsSolvers/solidMechanics/SolidMechanicsFields.hpp" #include "physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp index d2c1c2ddecb..99024d3ba77 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp @@ -28,6 +28,7 @@ #include "physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEFEM.hpp" #include "physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp" #include "physicsSolvers/solidMechanics/SolidMechanicsFields.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index 2e8893fc9a9..ddf30e2352c 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -191,21 +191,21 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse localIndex const subRegionIndex[2] = {m_sesri[iconn][k[0]], m_sesri[iconn][k[1]]}; localIndex const elementIndex[2] = {m_sei[iconn][k[0]], m_sei[iconn][k[1]]}; - fluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, - trans, - dTrans, - m_pres, - m_gravCoef, - m_dens, - m_dDens_dPres, - m_mob, - m_dMob_dPres, - alpha, - mobility, - potGrad, - fluxVal, - dFlux_dP, - dFlux_dTrans ); + singlePhaseFluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, + trans, + dTrans, + m_pres, + m_gravCoef, + m_dens, + m_dDens_dPres, + m_mob, + m_dMob_dPres, + alpha, + mobility, + potGrad, + fluxVal, + dFlux_dP, + dFlux_dTrans ); // populate local flux vector and derivatives stack.localFlux[k[0]* numDof] += m_dt * fluxVal; diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index dd820e257d3..e438daed5eb 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -181,21 +181,21 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse real64 mobility = 0.0; real64 potGrad = 0.0; - fluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, - trans, - dTrans, - m_pres, - m_gravCoef, - m_dens, - m_dDens_dPres, - m_mob, - m_dMob_dPres, - alpha, - mobility, - potGrad, - fluxVal, - dFlux_dP, - dFlux_dTrans ); + singlePhaseFluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, + trans, + dTrans, + m_pres, + m_gravCoef, + m_dens, + m_dDens_dPres, + m_mob, + m_dMob_dPres, + alpha, + mobility, + potGrad, + fluxVal, + dFlux_dP, + dFlux_dTrans ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp index 0621ec04d46..afbf536027a 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp @@ -205,25 +205,25 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsConformingFr real64 trans[2] = {stack.transmissibility[0][0], stack.transmissibility[0][1]}; real64 dMassFlux_dT[2]{}; - fluxKernelsHelper::computeEnthalpyFlux( seri, sesri, sei, - trans, - m_enthalpy, - m_dEnthalpy_dPres, - m_dEnthalpy_dTemp, - m_gravCoef, - m_dDens_dTemp, - m_dMob_dTemp, - alpha, - mobility, - potGrad, - massFlux, - dMassFlux_dTrans, - dMassFlux_dP, - dMassFlux_dT, - stack.energyFlux, - stack.dEnergyFlux_dTrans, - stack.dEnergyFlux_dP, - stack.dEnergyFlux_dT ); + singlePhaseFluxKernelsHelper::computeEnthalpyFlux( seri, sesri, sei, + trans, + m_enthalpy, + m_dEnthalpy_dPres, + m_dEnthalpy_dTemp, + m_gravCoef, + m_dDens_dTemp, + m_dMob_dTemp, + alpha, + mobility, + potGrad, + massFlux, + dMassFlux_dTrans, + dMassFlux_dP, + dMassFlux_dT, + stack.energyFlux, + stack.dEnergyFlux_dTrans, + stack.dEnergyFlux_dP, + stack.dEnergyFlux_dT ); // add dMassFlux_dT to localFluxJacobian for( integer ke = 0; ke < 2; ++ke ) @@ -260,7 +260,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsConformingFr localIndex const sei[2] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; // Step 2: compute temperature difference at the interface - fluxKernelsHelper::computeConductiveFlux( seri, sesri, sei, m_temp, thermalTrans, stack.energyFlux, stack.dEnergyFlux_dT ); + singlePhaseFluxKernelsHelper::computeConductiveFlux( seri, sesri, sei, m_temp, thermalTrans, stack.energyFlux, stack.dEnergyFlux_dT ); // add energyFlux and its derivatives to localFlux and localFluxJacobian stack.localFlux[k[0]*numEqn + numEqn - 1] += m_dt * stack.energyFlux; diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp index d62a283e364..12fe7e99a35 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp @@ -204,25 +204,25 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsEmbeddedFrac real64 trans[2] = {stack.transmissibility[0][0], stack.transmissibility[0][1]}; real64 dMassFlux_dT[2]{}; - fluxKernelsHelper::computeEnthalpyFlux( seri, sesri, sei, - trans, - m_enthalpy, - m_dEnthalpy_dPres, - m_dEnthalpy_dTemp, - m_gravCoef, - m_dDens_dTemp, - m_dMob_dTemp, - alpha, - mobility, - potGrad, - massFlux, - dMassFlux_dTrans, - dMassFlux_dP, - dMassFlux_dT, - stack.energyFlux, - stack.dEnergyFlux_dTrans, - stack.dEnergyFlux_dP, - stack.dEnergyFlux_dT ); + singlePhaseFluxKernelsHelper::computeEnthalpyFlux( seri, sesri, sei, + trans, + m_enthalpy, + m_dEnthalpy_dPres, + m_dEnthalpy_dTemp, + m_gravCoef, + m_dDens_dTemp, + m_dMob_dTemp, + alpha, + mobility, + potGrad, + massFlux, + dMassFlux_dTrans, + dMassFlux_dP, + dMassFlux_dT, + stack.energyFlux, + stack.dEnergyFlux_dTrans, + stack.dEnergyFlux_dP, + stack.dEnergyFlux_dT ); for( localIndex i=0; i < 3; i++ ) { @@ -271,7 +271,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsEmbeddedFrac localIndex const sei[2] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; // Step 2: compute temperature difference at the interface - fluxKernelsHelper::computeConductiveFlux( seri, sesri, sei, m_temp, thermalTrans, stack.energyFlux, stack.dEnergyFlux_dT ); + singlePhaseFluxKernelsHelper::computeConductiveFlux( seri, sesri, sei, m_temp, thermalTrans, stack.energyFlux, stack.dEnergyFlux_dT ); // add energyFlux and its derivatives to localFlux and localFluxJacobian stack.localFlux[k[0]*numEqn + numEqn - 1] += m_dt * stack.energyFlux; diff --git a/src/coreComponents/unitTests/fluidFlowTests/CMakeLists.txt b/src/coreComponents/unitTests/fluidFlowTests/CMakeLists.txt index c21190560cf..800fae6f0db 100644 --- a/src/coreComponents/unitTests/fluidFlowTests/CMakeLists.txt +++ b/src/coreComponents/unitTests/fluidFlowTests/CMakeLists.txt @@ -1,6 +1,6 @@ # Specify list of tests set( gtest_geosx_tests - testSinglePhaseBaseKernels.cpp + testSinglePhaseMobilityKernel.cpp testThermalCompMultiphaseFlow.cpp testThermalSinglePhaseFlow.cpp testFlowStatistics.cpp diff --git a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseMobilityKernel.cpp similarity index 98% rename from src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp rename to src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseMobilityKernel.cpp index 86b2518cb23..60704c53b9f 100644 --- a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseBaseKernels.cpp +++ b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseMobilityKernel.cpp @@ -15,7 +15,7 @@ // Source includes #include "mainInterface/initialization.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp" // TPL includes #include From e20b0314c2633ae2b068cc925dc1efb8ba066ed4 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 13:35:26 -0500 Subject: [PATCH 08/47] thermal base --- .../kernels/singlePhase/FluidUpdateKernel.hpp | 52 ++++ .../SinglePhaseResidualNormKernel.hpp | 142 +++++++++- .../SolidInternalEnergyUpdateKernel.hpp | 51 ++++ ...ThermalSinglePhaseAccumulationKernels.hpp} | 264 ++---------------- 4 files changed, 262 insertions(+), 247 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{ThermalSinglePhaseBaseKernels.hpp => ThermalSinglePhaseAccumulationKernels.hpp} (54%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp new file mode 100644 index 00000000000..89518accdaa --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp @@ -0,0 +1,52 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluidUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** FluidUpdateKernel ********************************/ + +struct FluidUpdateKernel +{ + template< typename FLUID_WRAPPER > + static void launch( FLUID_WRAPPER const & fluidWrapper, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & temp ) + { + forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) + { + fluidWrapper.update( k, q, pres[k], temp[k] ); + } + } ); + } +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp index 9dfeab7e9cc..2044101e348 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp @@ -31,9 +31,9 @@ namespace singlePhaseBaseKernels /******************************** ResidualNormKernel ********************************/ /** - * @class ResidualNormKernel + * @class IsothermalResidualNormKernel */ -class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > +class IsothermalResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > { public: @@ -43,7 +43,7 @@ class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > using Base::m_localResidual; using Base::m_dofNumber; - ResidualNormKernel( globalIndex const rankOffset, + IsothermalResidualNormKernel( globalIndex const rankOffset, arrayView1d< real64 const > const & localResidual, arrayView1d< globalIndex const > const & dofNumber, arrayView1d< localIndex const > const & ghostRank, @@ -86,6 +86,95 @@ class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > }; +/** + * @class ThermalResidualNormKernel + */ +class ThermalResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 2 > +{ +public: + + using Base = solverBaseKernels::ResidualNormKernelBase< 2 >; + using Base::m_minNormalizer; + using Base::m_rankOffset; + using Base::m_localResidual; + using Base::m_dofNumber; + + ThermalResidualNormKernel( globalIndex const rankOffset, + arrayView1d< real64 const > const & localResidual, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< localIndex const > const & ghostRank, + ElementSubRegionBase const & subRegion, + real64 const minNormalizer ) + : Base( rankOffset, + localResidual, + dofNumber, + ghostRank, + minNormalizer ), + m_mass_n( subRegion.template getField< fields::flow::mass_n >() ), + m_energy_n( subRegion.template getField< fields::flow::energy_n >() ) + {} + + GEOS_HOST_DEVICE + void computeMassEnergyNormalizers( localIndex const ei, + real64 & massNormalizer, + real64 & energyNormalizer ) const + { + massNormalizer = LvArray::math::max( m_minNormalizer, m_mass_n[ei] ); + energyNormalizer = LvArray::math::max( m_minNormalizer, m_energy_n[ei] ); + } + + GEOS_HOST_DEVICE + virtual void computeLinf( localIndex const ei, + LinfStackVariables & stack ) const override + { + real64 massNormalizer = 0.0, energyNormalizer = 0.0; + computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); + + // step 1: mass residual + + real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow] ) / massNormalizer; + if( valMass > stack.localValue[0] ) + { + stack.localValue[0] = valMass; + } + + // step 2: energy residual + real64 const valEnergy = LvArray::math::abs( m_localResidual[stack.localRow + 1] ) / energyNormalizer; + if( valEnergy > stack.localValue[1] ) + { + stack.localValue[1] = valEnergy; + } + } + + GEOS_HOST_DEVICE + virtual void computeL2( localIndex const ei, + L2StackVariables & stack ) const override + { + real64 massNormalizer = 0.0, energyNormalizer = 0.0; + computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); + + // step 1: mass residual + + stack.localValue[0] += m_localResidual[stack.localRow] * m_localResidual[stack.localRow]; + stack.localNormalizer[0] += massNormalizer; + + // step 2: energy residual + + stack.localValue[1] += m_localResidual[stack.localRow + 1] * m_localResidual[stack.localRow + 1]; + stack.localNormalizer[1] += energyNormalizer; + } + + +protected: + + /// View on mass at the previous converged time step + arrayView1d< real64 const > const m_mass_n; + + /// View on energy at the previous converged time step + arrayView1d< real64 const > const m_energy_n; + +}; + /** * @class ResidualNormKernelFactory */ @@ -94,7 +183,7 @@ class ResidualNormKernelFactory public: /** - * @brief Create a new kernel and launch + * @brief Create a new kernel and launch (isothermal version) * @tparam POLICY the policy used in the RAJA kernel * @param[in] normType the type of norm used (Linf or L2) * @param[in] rankOffset the offset of my MPI rank @@ -120,14 +209,53 @@ class ResidualNormKernelFactory arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, subRegion, minNormalizer ); + IsothermalResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, subRegion, minNormalizer ); + if( normType == solverBaseKernels::NormType::Linf ) + { + IsothermalResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); + } + else // L2 norm + { + IsothermalResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); + } + } + + /** + * @brief Create a new kernel and launch (thermal version) + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] normType the type of norm used (Linf or L2) + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] localResidual the residual vector on my MPI rank + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[in] solidInternalEnergy the solid internal energy model + * @param[out] residualNorm the residual norm on the subRegion + * @param[out] residualNormalizer the residual normalizer on the subRegion + */ + template< typename POLICY > + static void + createAndLaunch( solverBaseKernels::NormType const normType, + globalIndex const rankOffset, + string const & dofKey, + arrayView1d< real64 const > const & localResidual, + ElementSubRegionBase const & subRegion, + real64 const minNormalizer, + real64 (& residualNorm)[2], + real64 (& residualNormalizer)[2] ) + { + arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + ThermalResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, subRegion, minNormalizer ); if( normType == solverBaseKernels::NormType::Linf ) { - ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); + ThermalResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); } else // L2 norm { - ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); + ThermalResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp new file mode 100644 index 00000000000..e87bbff18b2 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp @@ -0,0 +1,51 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SolidInternalEnergyUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP + +namespace geos +{ + +namespace thermalSinglePhaseBaseKernels +{ + +/******************************** SolidInternalEnergyUpdateKernel ********************************/ + +struct SolidInternalEnergyUpdateKernel +{ + + template< typename POLICY, typename SOLID_INTERNAL_ENERGY_WRAPPER > + static void + launch( localIndex const size, + SOLID_INTERNAL_ENERGY_WRAPPER const & solidInternalEnergyWrapper, + arrayView1d< real64 const > const & temp ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + solidInternalEnergyWrapper.update( k, temp[k] ); + } ); + } +}; + +} // namespace thermalSinglePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseAccumulationKernels.hpp similarity index 54% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseAccumulationKernels.hpp index 6b7182174b0..86ae72ed76e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseAccumulationKernels.hpp @@ -14,11 +14,11 @@ */ /** - * @file ThermalSinglePhaseBaseKernels.hpp + * @file ThermalSinglePhaseAccumulationKernels.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEACCUMULATIONKERNELS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEACCUMULATIONKERNELS_HPP #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" @@ -28,14 +28,14 @@ namespace geos namespace thermalSinglePhaseBaseKernels { -/******************************** ElementBasedAssemblyKernel ********************************/ +/******************************** AccumulationKernel ********************************/ /** - * @class ElementBasedAssemblyKernel + * @class AccumulationKernel * @brief Define the interface for the assembly kernel in charge of accumulation */ template< typename SUBREGION_TYPE, integer NUM_DOF > -class ElementBasedAssemblyKernel : public singlePhaseBaseKernels::AccumulationKernel< SUBREGION_TYPE, NUM_DOF > +class AccumulationKernel : public singlePhaseBaseKernels::AccumulationKernel< SUBREGION_TYPE, NUM_DOF > { public: @@ -65,7 +65,7 @@ class ElementBasedAssemblyKernel : public singlePhaseBaseKernels::AccumulationKe * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - ElementBasedAssemblyKernel( globalIndex const rankOffset, + AccumulationKernel( globalIndex const rankOffset, string const dofKey, SUBREGION_TYPE const & subRegion, constitutive::SingleFluidBase const & fluid, @@ -204,8 +204,6 @@ class ElementBasedAssemblyKernel : public singlePhaseBaseKernels::AccumulationKe stack.dofIndices, stack.localJacobian[numEqn-1], numDof ); - - } protected: @@ -231,15 +229,15 @@ class ElementBasedAssemblyKernel : public singlePhaseBaseKernels::AccumulationKe }; /** - * @class SurfaceElementBasedAssemblyKernel + * @class SurfaceElementAccumulationKernel * @brief Define the interface for the assembly kernel in charge of accumulation in SurfaceElementSubRegion */ -class SurfaceElementBasedAssemblyKernel : public ElementBasedAssemblyKernel< SurfaceElementSubRegion, 2 > +class SurfaceElementAccumulationKernel : public AccumulationKernel< SurfaceElementSubRegion, 2 > { public: - using Base = ElementBasedAssemblyKernel< SurfaceElementSubRegion, 2 >; + using Base = AccumulationKernel< SurfaceElementSubRegion, 2 >; /** * @brief Constructor @@ -251,7 +249,7 @@ class SurfaceElementBasedAssemblyKernel : public ElementBasedAssemblyKernel< Sur * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - SurfaceElementBasedAssemblyKernel( globalIndex const rankOffset, + SurfaceElementAccumulationKernel( globalIndex const rankOffset, string const dofKey, SurfaceElementSubRegion const & subRegion, constitutive::SingleFluidBase const & fluid, @@ -286,9 +284,9 @@ class SurfaceElementBasedAssemblyKernel : public ElementBasedAssemblyKernel< Sur }; /** - * @class ElementBasedAssemblyKernelFactory + * @class AccumulationKernelFactory */ -class ElementBasedAssemblyKernelFactory +class AccumulationKernelFactory { public: @@ -303,244 +301,30 @@ class ElementBasedAssemblyKernelFactory * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - template< typename POLICY > + template< typename POLICY, typename SUBREGION_TYPE > static void createAndLaunch( globalIndex const rankOffset, string const dofKey, - CellElementSubRegion const & subRegion, + SUBREGION_TYPE const & subRegion, constitutive::SingleFluidBase const & fluid, constitutive::CoupledSolidBase const & solid, CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) { - integer constexpr NUM_DOF = 2; - - ElementBasedAssemblyKernel< CellElementSubRegion, NUM_DOF > - kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); - ElementBasedAssemblyKernel< CellElementSubRegion, NUM_DOF >::template - launch< POLICY, ElementBasedAssemblyKernel< CellElementSubRegion, NUM_DOF > >( subRegion.size(), kernel ); - } - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( globalIndex const rankOffset, - string const dofKey, - SurfaceElementSubRegion const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - SurfaceElementBasedAssemblyKernel - kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); - SurfaceElementBasedAssemblyKernel::launch< POLICY >( subRegion.size(), kernel ); - } - - -}; - - -/******************************** FluidUpdateKernel ********************************/ - -struct FluidUpdateKernel -{ - template< typename FLUID_WRAPPER > - static void launch( FLUID_WRAPPER const & fluidWrapper, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & temp ) - { - forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) - { - fluidWrapper.update( k, q, pres[k], temp[k] ); - } - } ); - } -}; - -/******************************** SolidInternalEnergyUpdateKernel ********************************/ - -struct SolidInternalEnergyUpdateKernel -{ - - template< typename POLICY, typename SOLID_INTERNAL_ENERGY_WRAPPER > - static void - launch( localIndex const size, - SOLID_INTERNAL_ENERGY_WRAPPER const & solidInternalEnergyWrapper, - arrayView1d< real64 const > const & temp ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - solidInternalEnergyWrapper.update( k, temp[k] ); - } ); - } -}; - -/******************************** ResidualNormKernel ********************************/ - -/** - * @class ResidualNormKernel - */ -class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 2 > -{ -public: - - using Base = solverBaseKernels::ResidualNormKernelBase< 2 >; - using Base::m_minNormalizer; - using Base::m_rankOffset; - using Base::m_localResidual; - using Base::m_dofNumber; - - ResidualNormKernel( globalIndex const rankOffset, - arrayView1d< real64 const > const & localResidual, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< localIndex const > const & ghostRank, - ElementSubRegionBase const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - constitutive::SolidInternalEnergy const & solidInternalEnergy, - real64 const minNormalizer ) - : Base( rankOffset, - localResidual, - dofNumber, - ghostRank, - minNormalizer ), - m_volume( subRegion.getElementVolume() ), - m_porosity_n( solid.getPorosity_n() ), - m_density_n( fluid.density_n() ), - m_fluidInternalEnergy_n( fluid.internalEnergy_n() ), - m_solidInternalEnergy_n( solidInternalEnergy.getInternalEnergy_n() ) - {} - - GEOS_HOST_DEVICE - void computeMassEnergyNormalizers( localIndex const ei, - real64 & massNormalizer, - real64 & energyNormalizer ) const - { - massNormalizer = LvArray::math::max( m_minNormalizer, m_density_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ); - energyNormalizer = - LvArray::math::max( m_minNormalizer, - LvArray::math::abs( m_solidInternalEnergy_n[ei][0] * ( 1.0 - m_porosity_n[ei][0] ) * m_volume[ei] - + m_fluidInternalEnergy_n[ei][0] * m_density_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ) ); - } - - GEOS_HOST_DEVICE - virtual void computeLinf( localIndex const ei, - LinfStackVariables & stack ) const override - { - real64 massNormalizer = 0.0, energyNormalizer = 0.0; - computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); - - // step 1: mass residual - - real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow] ) / massNormalizer; - if( valMass > stack.localValue[0] ) + if constexpr ( std::is_same_v< SUBREGION_TYPE, CellElementSubRegion > ) { - stack.localValue[0] = valMass; + integer constexpr NUM_DOF = 2; + AccumulationKernel< CellElementSubRegion, NUM_DOF > kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); + AccumulationKernel< CellElementSubRegion, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); } - - // step 2: energy residual - real64 const valEnergy = LvArray::math::abs( m_localResidual[stack.localRow + 1] ) / energyNormalizer; - if( valEnergy > stack.localValue[1] ) - { - stack.localValue[1] = valEnergy; - } - } - - GEOS_HOST_DEVICE - virtual void computeL2( localIndex const ei, - L2StackVariables & stack ) const override - { - real64 massNormalizer = 0.0, energyNormalizer = 0.0; - computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); - - // step 1: mass residual - - stack.localValue[0] += m_localResidual[stack.localRow] * m_localResidual[stack.localRow]; - stack.localNormalizer[0] += massNormalizer; - - // step 2: energy residual - - stack.localValue[1] += m_localResidual[stack.localRow + 1] * m_localResidual[stack.localRow + 1]; - stack.localNormalizer[1] += energyNormalizer; - } - - -protected: - - /// View on the volume - arrayView1d< real64 const > const m_volume; - - /// View on porosity at the previous converged time step - arrayView2d< real64 const > const m_porosity_n; - - /// View on total mass/molar density at the previous converged time step - arrayView2d< real64 const > const m_density_n; - arrayView2d< real64 const > const m_fluidInternalEnergy_n; - - /// View on solid internal energy at the previous converged time step - arrayView2d< real64 const > const m_solidInternalEnergy_n; - -}; - -/** - * @class ResidualNormKernelFactory - */ -class ResidualNormKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] normType the type of norm used (Linf or L2) - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] localResidual the residual vector on my MPI rank - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[in] solidInternalEnergy the solid internal energy model - * @param[out] residualNorm the residual norm on the subRegion - * @param[out] residualNormalizer the residual normalizer on the subRegion - */ - template< typename POLICY > - static void - createAndLaunch( solverBaseKernels::NormType const normType, - globalIndex const rankOffset, - string const & dofKey, - arrayView1d< real64 const > const & localResidual, - ElementSubRegionBase const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - constitutive::SolidInternalEnergy const & solidInternalEnergy, - real64 const minNormalizer, - real64 (& residualNorm)[2], - real64 (& residualNormalizer)[2] ) - { - arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); - arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - - ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, subRegion, fluid, solid, solidInternalEnergy, minNormalizer ); - if( normType == solverBaseKernels::NormType::Linf ) + else if constexpr ( std::is_same_v< SUBREGION_TYPE, SurfaceElementSubRegion > ) { - ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); + SurfaceElementAccumulationKernel kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); + SurfaceElementAccumulationKernel::launch< POLICY >( subRegion.size(), kernel ); } - else // L2 norm + else { - ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); + GEOS_ERROR( "Unsupported subregion type: " << typeid(SUBREGION_TYPE).name() ); } } From f4bd0f724b4a0387254646001169fa38ae927c60 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 14:01:47 -0500 Subject: [PATCH 09/47] rename --- .../fluidFlow/FlowSolverBase.cpp | 2 +- .../fluidFlow/SinglePhaseBase.cpp | 18 +-- .../fluidFlow/SinglePhaseBase.hpp | 6 +- .../fluidFlow/SinglePhaseFVM.cpp | 18 +-- .../fluidFlow/SinglePhaseHybridFVM.cpp | 2 +- .../fluidFlow/SinglePhaseStatistics.cpp | 2 +- ...ionKernels.hpp => AccumulationKernels.hpp} | 0 .../kernels/singlePhase/FluidUpdateKernel.hpp | 3 + ...ernelsHelper.hpp => FluxKernelsHelper.hpp} | 0 ...rnel.hpp => HydrostaticPressureKernel.hpp} | 0 ...eMobilityKernel.hpp => MobilityKernel.hpp} | 0 ...lNormKernel.hpp => ResidualNormKernel.hpp} | 0 .../singlePhase/SinglePhaseFVMKernels.hpp | 122 +----------------- .../SinglePhaseHybridFVMKernels.hpp | 2 +- .../SinglePhaseProppantFluxKernels.cpp | 2 +- .../SolidInternalEnergyUpdateKernel.hpp | 3 + ...heckKernel.hpp => SolutionCheckKernel.hpp} | 0 ...ngKernel.hpp => SolutionScalingKernel.hpp} | 0 ...tisticsKernel.hpp => StatisticsKernel.hpp} | 0 ...els.hpp => ThermalAccumulationKernels.hpp} | 2 +- .../fluidFlow/wells/SinglePhaseWell.cpp | 3 +- ...ePhasePoromechanicsConformingFractures.hpp | 2 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 2 +- 23 files changed, 37 insertions(+), 152 deletions(-) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseAccumulationKernels.hpp => AccumulationKernels.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseFluxKernelsHelper.hpp => FluxKernelsHelper.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseHydrostaticPressureKernel.hpp => HydrostaticPressureKernel.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseMobilityKernel.hpp => MobilityKernel.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseResidualNormKernel.hpp => ResidualNormKernel.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseSolutionCheckKernel.hpp => SolutionCheckKernel.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseSolutionScalingKernel.hpp => SolutionScalingKernel.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseStatisticsKernel.hpp => StatisticsKernel.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{ThermalSinglePhaseAccumulationKernels.hpp => ThermalAccumulationKernels.hpp} (99%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index ea89bb6786b..9777fac83e8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -34,7 +34,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" // TODO should not be here +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" // TODO should not be here namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index 0ff9dcfb0fe..ce476dd00ea 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -40,13 +40,15 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp" namespace geos @@ -263,7 +265,7 @@ void SinglePhaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const constitutiveUpdatePassThru( fluid, [&]( auto & castedFluid ) { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - thermalSinglePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); + singlePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); } ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp index c7065526cf1..72d7d3e6614 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp @@ -21,8 +21,8 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASE_HPP_ #include "physicsSolvers/fluidFlow/FlowSolverBase.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" #include "constitutive/solid/CoupledSolidBase.hpp" @@ -446,7 +446,7 @@ void SinglePhaseBase::accumulationAssemblyLaunch( DofManager const & dofManager, if( m_isThermal ) { thermalSinglePhaseBaseKernels:: - ElementBasedAssemblyKernelFactory:: + AccumulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, subRegion, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index 3fd96fddfb2..749102e96e1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -33,10 +33,11 @@ #include "fieldSpecification/AquiferBoundaryCondition.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp" @@ -156,22 +157,13 @@ real64 SinglePhaseFVM< BASE >::calculateResidualNorm( real64 const & GEOS_UNUSED if( m_isThermal ) { - string const & solidName = subRegion.template getReference< string >( BASE::viewKeyStruct::solidNamesString() ); - CoupledSolidBase const & solid = SolverBase::getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); - - string const & solidInternalEnergyName = subRegion.template getReference< string >( BASE::viewKeyStruct::solidInternalEnergyNamesString() ); - SolidInternalEnergy const & solidInternalEnergy = SolverBase::getConstitutiveModel< SolidInternalEnergy >( subRegion, solidInternalEnergyName ); - - thermalSinglePhaseBaseKernels:: + singlePhaseBaseKernels:: ResidualNormKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( normType, rankOffset, dofKey, localRhs, subRegion, - fluid, - solid, - solidInternalEnergy, m_nonlinearSolverParameters.m_minNormalizer, subRegionResidualNorm, subRegionResidualNormalizer ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp index f6ac3527e2f..a3c995869f0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseHybridFVM.cpp @@ -32,7 +32,7 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp" /** diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp index c5cf2097191..4a8a5da8acb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseStatistics.cpp @@ -25,7 +25,7 @@ #include "physicsSolvers/fluidFlow/SinglePhaseBase.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp index 89518accdaa..6e6e8e61b74 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp @@ -20,6 +20,9 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp index 564a09000a7..3f5e918c5c3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp @@ -36,9 +36,9 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos @@ -840,122 +840,6 @@ class DirichletFaceBasedAssemblyKernelFactory }; - -/******************************** AquiferBCKernel ********************************/ - -/** - * @brief Functions to assemble aquifer boundary condition contributions to residual and Jacobian - */ -struct AquiferBCKernel -{ - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - GEOS_HOST_DEVICE - static void - compute( real64 const & aquiferVolFlux, - real64 const & dAquiferVolFlux_dPres, - real64 const & aquiferDens, - real64 const & dens, - real64 const & dDens_dPres, - real64 const & dt, - real64 & localFlux, - real64 & localFluxJacobian ) - { - if( aquiferVolFlux > 0 ) // aquifer is upstream - { - localFlux -= dt * aquiferVolFlux * aquiferDens; - localFluxJacobian -= dt * dAquiferVolFlux_dPres * aquiferDens; - } - else // reservoir is upstream - { - localFlux -= dt * aquiferVolFlux * dens; - localFluxJacobian -= dt * (dAquiferVolFlux_dPres * dens + aquiferVolFlux * dDens_dPres); - } - } - - static void - launch( BoundaryStencil const & stencil, - globalIndex const rankOffset, - ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, - ElementViewConst< arrayView1d< integer const > > const & ghostRank, - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, - real64 const & aquiferDens, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & pres_n, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView2d< real64 const > > const & dens, - ElementViewConst< arrayView2d< real64 const > > const & dDens_dPres, - real64 const & timeAtBeginningOfStep, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - using Order = BoundaryStencil::Order; - - BoundaryStencil::IndexContainerViewConstType const & seri = stencil.getElementRegionIndices(); - BoundaryStencil::IndexContainerViewConstType const & sesri = stencil.getElementSubRegionIndices(); - BoundaryStencil::IndexContainerViewConstType const & sefi = stencil.getElementIndices(); - BoundaryStencil::WeightContainerViewConstType const & weight = stencil.getWeights(); - - forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - // working variables - real64 localFlux = 0.0; - real64 localFluxJacobian = 0.0; - - localIndex const er = seri( iconn, Order::ELEM ); - localIndex const esr = sesri( iconn, Order::ELEM ); - localIndex const ei = sefi( iconn, Order::ELEM ); - real64 const areaFraction = weight( iconn, Order::ELEM ); - - // compute the aquifer influx rate using the pressure influence function and the aquifer props - real64 dAquiferVolFlux_dPres = 0.0; - real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep, - dt, - pres[er][esr][ei], - pres_n[er][esr][ei], - gravCoef[er][esr][ei], - areaFraction, - dAquiferVolFlux_dPres ); - - // compute the phase/component aquifer flux - AquiferBCKernel::compute( aquiferVolFlux, - dAquiferVolFlux_dPres, - aquiferDens, - dens[er][esr][ei][0], - dDens_dPres[er][esr][ei][0], - dt, - localFlux, - localFluxJacobian ); - - // Add to residual/jacobian - if( ghostRank[er][esr][ei] < 0 ) - { - globalIndex const globalRow = dofNumber[er][esr][ei]; - localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - rankOffset ); - GEOS_ASSERT_GE( localRow, 0 ); - GEOS_ASSERT_GT( localMatrix.numRows(), localRow ); - - RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[localRow], localFlux ); - localMatrix.addToRow< parallelDeviceAtomic >( localRow, - &dofNumber[er][esr][ei], - &localFluxJacobian, - 1 ); - } - } ); - } - -}; - - } // namespace singlePhaseFVMKernels } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp index a9447f1b935..b38ec193601 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp @@ -37,7 +37,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" #include "codingUtilities/Utilities.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp index e283a25bb44..098d9f79ab8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp @@ -19,7 +19,7 @@ #include "SinglePhaseProppantFluxKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp index e87bbff18b2..4ed3658e569 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp @@ -20,6 +20,9 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseAccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseAccumulationKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp index 86ae72ed76e..f044fa9079c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseAccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEACCUMULATIONKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEACCUMULATIONKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index 73ea1fc34ac..ebcc83b1172 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -36,6 +36,7 @@ #include "physicsSolvers/fluidFlow/wells/SinglePhaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp" namespace geos { @@ -306,7 +307,7 @@ void SinglePhaseWell::updateFluidModel( WellElementSubRegion & subRegion ) const constitutiveUpdatePassThru( fluid, [&]( auto & castedFluid ) { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - thermalSinglePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); + singlePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); } ); } diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index ddf30e2352c..8993448718d 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index e438daed5eb..c7ee034779b 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos From f84dfc3d646b9170b95b2353db072973ed50236b Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 16:25:23 -0500 Subject: [PATCH 10/47] thermal flux --- .../fluidFlow/FlowSolverBase.cpp | 1 - .../fluidFlow/SinglePhaseFVM.cpp | 38 +- .../kernels/HybridFVMHelperKernels.hpp | 10 +- .../MinPoreVolumeMaxPorosityKernel.hpp | 8 +- .../singlePhase/AccumulationKernels.hpp | 8 +- .../kernels/singlePhase/AquiferBCKernel.hpp | 152 ++++ .../DirichletFluxComputeKernel.hpp | 373 ++++++++ .../kernels/singlePhase/FluidUpdateKernel.hpp | 6 +- .../kernels/singlePhase/FluxComputeKernel.hpp | 403 +++++++++ .../singlePhase/FluxComputeKernelBase.hpp | 179 ++++ .../kernels/singlePhase/FluxKernelsHelper.hpp | 8 +- .../singlePhase/HydrostaticPressureKernel.hpp | 8 +- .../kernels/singlePhase/MobilityKernel.hpp | 8 +- .../singlePhase/ResidualNormKernel.hpp | 8 +- .../singlePhase/SinglePhaseFVMKernels.hpp | 847 ------------------ .../SinglePhaseHybridFVMKernels.hpp | 6 +- .../SinglePhaseProppantBaseKernels.hpp | 6 +- .../SinglePhaseProppantFluxKernels.cpp | 2 +- .../singlePhase/SolutionCheckKernel.hpp | 8 +- .../singlePhase/SolutionScalingKernel.hpp | 8 +- ...ls.hpp => StabilizedFluxComputeKernel.hpp} | 29 +- .../kernels/singlePhase/StatisticsKernel.hpp | 9 +- .../ThermalAccumulationKernels.hpp | 8 +- .../ThermalDirichletFluxComputeKernel.hpp | 394 ++++++++ ...rnels.hpp => ThermalFluxComputeKernel.hpp} | 384 +------- ...ePhasePoromechanicsConformingFractures.hpp | 8 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 8 +- ...ePhasePoromechanicsConformingFractures.hpp | 5 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 4 +- .../testSinglePhaseMobilityKernel.cpp | 2 +- 30 files changed, 1617 insertions(+), 1321 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{StabilizedSinglePhaseFVMKernels.hpp => StabilizedFluxComputeKernel.hpp} (92%) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{ThermalSinglePhaseFVMKernels.hpp => ThermalFluxComputeKernel.hpp} (55%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index 9777fac83e8..f1bd271ef8a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -34,7 +34,6 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" // TODO should not be here namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index 749102e96e1..5bff8f4cfcf 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -36,11 +36,13 @@ #include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp" @@ -326,7 +328,7 @@ void SinglePhaseFVM<>::assembleFluxTerms( real64 const dt, if( m_isThermal ) { thermalSinglePhaseFVMKernels:: - FaceBasedAssemblyKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), + FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, getName(), mesh.getElemManager(), @@ -338,7 +340,7 @@ void SinglePhaseFVM<>::assembleFluxTerms( real64 const dt, else { singlePhaseFVMKernels:: - FaceBasedAssemblyKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), + FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, getName(), mesh.getElemManager(), @@ -379,7 +381,7 @@ void SinglePhaseFVM< SinglePhaseBase >::assembleStabilizedFluxTerms( real64 cons typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); // No thermal support yet - stabilizedSinglePhaseFVMKernels::FaceBasedAssemblyKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), + stabilizedSinglePhaseFVMKernels::FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, getName(), mesh.getElemManager(), @@ -423,9 +425,9 @@ void SinglePhaseFVM< SinglePhaseProppantBase >::assembleFluxTerms( real64 const { typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); - typename FaceBasedAssemblyKernelBase::SinglePhaseFlowAccessors flowAccessors( elemManager, getName() ); - typename FaceBasedAssemblyKernelBase::SlurryFluidAccessors fluidAccessors( elemManager, getName() ); - typename FaceBasedAssemblyKernelBase::ProppantPermeabilityAccessors permAccessors( elemManager, getName() ); + typename FluxComputeKernelBase::SinglePhaseFlowAccessors flowAccessors( elemManager, getName() ); + typename FluxComputeKernelBase::SlurryFluidAccessors fluidAccessors( elemManager, getName() ); + typename FluxComputeKernelBase::ProppantPermeabilityAccessors permAccessors( elemManager, getName() ); singlePhaseProppantFluxKernels::FaceElementFluxKernel::launch( stencilWrapper, dt, @@ -488,7 +490,7 @@ void SinglePhaseFVM< BASE >::assembleEDFMFluxTerms( real64 const GEOS_UNUSED_PAR if( m_isThermal ) { thermalSinglePhaseFVMKernels:: - FaceBasedAssemblyKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), + FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, this->getName(), mesh.getElemManager(), @@ -500,7 +502,7 @@ void SinglePhaseFVM< BASE >::assembleEDFMFluxTerms( real64 const GEOS_UNUSED_PAR else { singlePhaseFVMKernels:: - FaceBasedAssemblyKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), + FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, this->getName(), mesh.getElemManager(), @@ -577,7 +579,7 @@ void SinglePhaseFVM< BASE >::assembleHydrofracFluxTerms( real64 const GEOS_UNUSE if( m_isThermal ) { thermalSinglePhaseFVMKernels:: - FaceBasedAssemblyKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), + FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, this->getName(), mesh.getElemManager(), @@ -589,7 +591,7 @@ void SinglePhaseFVM< BASE >::assembleHydrofracFluxTerms( real64 const GEOS_UNUSE else { singlePhaseFVMKernels:: - FaceBasedAssemblyKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), + FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, this->getName(), mesh.getElemManager(), @@ -785,7 +787,7 @@ void SinglePhaseFVM< BASE >::applyFaceDirichletBC( real64 const time_n, SingleFluidBase & fluidBase = subRegion.getConstitutiveModel< SingleFluidBase >( fluidName ); thermalSinglePhaseFVMKernels:: - DirichletFaceBasedAssemblyKernelFactory:: + DirichletFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, this->getName(), @@ -846,7 +848,7 @@ void SinglePhaseFVM< BASE >::applyFaceDirichletBC( real64 const time_n, BoundaryStencilWrapper const stencilWrapper = stencil.createKernelWrapper(); singlePhaseFVMKernels:: - DirichletFaceBasedAssemblyKernelFactory:: + DirichletFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), dofKey, this->getName(), @@ -901,8 +903,8 @@ void SinglePhaseFVM<>::applyAquiferBC( real64 const time, elemManager.constructArrayViewAccessor< globalIndex, 1 >( elemDofKey ); elemDofNumber.setName( this->getName() + "/accessors/" + elemDofKey ); - typename FaceBasedAssemblyKernelBase::SinglePhaseFlowAccessors flowAccessors( elemManager, this->getName() ); - typename FaceBasedAssemblyKernelBase::SinglePhaseFluidAccessors fluidAccessors( elemManager, this->getName() ); + typename FluxComputeKernelBase::SinglePhaseFlowAccessors flowAccessors( elemManager, this->getName() ); + typename FluxComputeKernelBase::SinglePhaseFluidAccessors fluidAccessors( elemManager, this->getName() ); fsManager.apply< FaceManager, AquiferBoundaryCondition >( time + dt, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp index 8aff3af7d74..c3eb3805be3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/HybridFVMHelperKernels.hpp @@ -14,15 +14,13 @@ */ /** - * @file CompositionalMultiphaseHybridFVMHelperKernels.hpp + * @file HybridFVMHelperKernels.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_HYBRIDFVMUPWINDINGHELPERKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_HYBRIDFVMUPWINDINGHELPERKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_HYBRIDFVMHELPERKERNELS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_HYBRIDFVMHELPERKERNELS_HPP #include "common/DataTypes.hpp" -#include "linearAlgebra/interfaces/InterfaceTypes.hpp" -#include "mesh/MeshLevel.hpp" namespace geos { @@ -91,4 +89,4 @@ struct CellConnectivity } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONALMULTIPHASEHYBRIDFVMUPWINDINGHELPERKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_HYBRIDFVMHELPERKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp index 9d9edf47d72..36f286b707c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file FlowSolverBaseKernels.hpp + * @file MinPoreVolumeMaxPorosityKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_FLOWSOLVERBASEKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_FLOWSOLVERBASEKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_MINPOREVOLUMEMAXPOROSITYKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_MINPOREVOLUMEMAXPOROSITYKERNEL_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -107,4 +107,4 @@ struct MinPoreVolumeMaxPorosityKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_FLOWSOLVERBASEKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_MINPOREVOLUMEMAXPOROSITYKERNEL_HPP \ No newline at end of file diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp index 80380cb8259..922d94afd29 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp @@ -14,11 +14,11 @@ */ /** - * @file SinglePhaseAccumulationKernels.hpp + * @file AccumulationKernels.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEACCUMULATIONKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEACCUMULATIONKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_ACCUMULATIONKERNELS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_ACCUMULATIONKERNELS_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -357,4 +357,4 @@ class AccumulationKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEBASEKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_ACCUMULATIONKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp new file mode 100644 index 00000000000..733a7013ac2 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp @@ -0,0 +1,152 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 AquiferBCKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_AQUIFERBCKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_AQUIFERBCKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/BoundaryStencil.hpp" + +namespace geos +{ + +namespace singlePhaseFVMKernels +{ + +/******************************** AquiferBCKernel ********************************/ + +/** + * @brief Functions to assemble aquifer boundary condition contributions to residual and Jacobian + */ +struct AquiferBCKernel +{ + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + GEOS_HOST_DEVICE + static void + compute( real64 const & aquiferVolFlux, + real64 const & dAquiferVolFlux_dPres, + real64 const & aquiferDens, + real64 const & dens, + real64 const & dDens_dPres, + real64 const & dt, + real64 & localFlux, + real64 & localFluxJacobian ) + { + if( aquiferVolFlux > 0 ) // aquifer is upstream + { + localFlux -= dt * aquiferVolFlux * aquiferDens; + localFluxJacobian -= dt * dAquiferVolFlux_dPres * aquiferDens; + } + else // reservoir is upstream + { + localFlux -= dt * aquiferVolFlux * dens; + localFluxJacobian -= dt * (dAquiferVolFlux_dPres * dens + aquiferVolFlux * dDens_dPres); + } + } + + static void + launch( BoundaryStencil const & stencil, + globalIndex const rankOffset, + ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, + ElementViewConst< arrayView1d< integer const > > const & ghostRank, + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + real64 const & aquiferDens, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & pres_n, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const > > const & dens, + ElementViewConst< arrayView2d< real64 const > > const & dDens_dPres, + real64 const & timeAtBeginningOfStep, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + using Order = BoundaryStencil::Order; + + BoundaryStencil::IndexContainerViewConstType const & seri = stencil.getElementRegionIndices(); + BoundaryStencil::IndexContainerViewConstType const & sesri = stencil.getElementSubRegionIndices(); + BoundaryStencil::IndexContainerViewConstType const & sefi = stencil.getElementIndices(); + BoundaryStencil::WeightContainerViewConstType const & weight = stencil.getWeights(); + + forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + // working variables + real64 localFlux = 0.0; + real64 localFluxJacobian = 0.0; + + localIndex const er = seri( iconn, Order::ELEM ); + localIndex const esr = sesri( iconn, Order::ELEM ); + localIndex const ei = sefi( iconn, Order::ELEM ); + real64 const areaFraction = weight( iconn, Order::ELEM ); + + // compute the aquifer influx rate using the pressure influence function and the aquifer props + real64 dAquiferVolFlux_dPres = 0.0; + real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep, + dt, + pres[er][esr][ei], + pres_n[er][esr][ei], + gravCoef[er][esr][ei], + areaFraction, + dAquiferVolFlux_dPres ); + + // compute the phase/component aquifer flux + AquiferBCKernel::compute( aquiferVolFlux, + dAquiferVolFlux_dPres, + aquiferDens, + dens[er][esr][ei][0], + dDens_dPres[er][esr][ei][0], + dt, + localFlux, + localFluxJacobian ); + + // Add to residual/jacobian + if( ghostRank[er][esr][ei] < 0 ) + { + globalIndex const globalRow = dofNumber[er][esr][ei]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( localMatrix.numRows(), localRow ); + + RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[localRow], localFlux ); + localMatrix.addToRow< parallelDeviceAtomic >( localRow, + &dofNumber[er][esr][ei], + &localFluxJacobian, + 1 ); + } + } ); + } + +}; + +} // namespace singlePhaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_AQUIFERBCKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp new file mode 100644 index 00000000000..16bb9e89848 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp @@ -0,0 +1,373 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 DirichletFluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_DIRICHLETFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_DIRICHLETFLUXCOMPUTEKERNEL_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" +#include "constitutive/fluid/singlefluid/SlurryFluidBase.hpp" +#include "constitutive/fluid/singlefluid/SlurryFluidFields.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "linearAlgebra/interfaces/InterfaceTypes.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseFVMKernels +{ + +/******************************** DirichletFluxComputeKernel ********************************/ + +/** + * @class DirichletFluxComputeKernel + * @tparam FLUIDWRAPPER the type of the fluid wrapper + * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms + */ +template< integer NUM_EQN, integer NUM_DOF, typename FLUIDWRAPPER > +class DirichletFluxComputeKernel : public FluxComputeKernel< NUM_EQN, NUM_DOF, + BoundaryStencilWrapper > +{ +public: + + using AbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; + using DofNumberAccessor = AbstractBase::DofNumberAccessor; + using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; + using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; + using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; + using AbstractBase::m_dt; + using AbstractBase::m_rankOffset; + using AbstractBase::m_dofNumber; + using AbstractBase::m_ghostRank; + using AbstractBase::m_gravCoef; + using AbstractBase::m_pres; + using AbstractBase::m_mob; + using AbstractBase::m_dMob_dPres; + using AbstractBase::m_dens; + using AbstractBase::m_dDens_dPres; + using AbstractBase::m_permeability; + using AbstractBase::m_dPerm_dPres; + using AbstractBase::m_localMatrix; + using AbstractBase::m_localRhs; + + using Base = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, + BoundaryStencilWrapper >; + using Base::numDof; + using Base::numEqn; + using Base::m_stencilWrapper; + using Base::m_seri; + using Base::m_sesri; + using Base::m_sei; + + /** + * @brief Constructor for the kernel interface + * @param[in] rankOffset the offset of my MPI rank + * @param[in] faceManager the face manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] fluidWrapper reference to the fluid wrapper + * @param[in] dofNumberAccessor + * @param[in] singlePhaseFlowAccessors + * @param[in] singlePhaseFluidAccessors + * @param[in] permeabilityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + DirichletFluxComputeKernel( globalIndex const rankOffset, + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + : Base( rankOffset, + stencilWrapper, + dofNumberAccessor, + singlePhaseFlowAccessors, + singlePhaseFluidAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs ), + m_facePres( faceManager.getField< fields::flow::facePressure >() ), + m_faceGravCoef( faceManager.getField< fields::flow::gravityCoefficient >() ), + m_fluidWrapper( fluidWrapper ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const GEOS_UNUSED_PARAM( size ), + localIndex GEOS_UNUSED_PARAM( numElems ) ) + {} + + /// Transmissibility + real64 transmissibility = 0.0; + + /// Indices of the matrix rows/columns corresponding to the dofs in this face + globalIndex dofColIndices[numDof]{}; + + /// Storage for the face local residual + real64 localFlux[numEqn]{}; + + /// Storage for the face local Jacobian + real64 localFluxJacobian[numEqn][numDof]{}; + + }; + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] iconn the connection index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const iconn, + StackVariables & stack ) const + { + globalIndex const offset = + m_dofNumber[m_seri( iconn, BoundaryStencil::Order::ELEM )][m_sesri( iconn, BoundaryStencil::Order::ELEM )][m_sei( iconn, BoundaryStencil::Order::ELEM )]; + + for( integer jdof = 0; jdof < numDof; ++jdof ) + { + stack.dofColIndices[jdof] = offset + jdof; + } + } + + /** + * @brief Compute the local Dirichlet face flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeFlux( localIndex const iconn, + StackVariables & stack, + FUNC && compFluxKernelOp = NoOpFunc{} ) const + { + using Order = BoundaryStencil::Order; + localIndex constexpr numElems = BoundaryStencil::maxNumPointsInFlux; + + stackArray1d< real64, numElems > mobility( numElems ); + stackArray1d< real64, numElems > dMobility_dP( numElems ); + + localIndex const er = m_seri( iconn, Order::ELEM ); + localIndex const esr = m_sesri( iconn, Order::ELEM ); + localIndex const ei = m_sei( iconn, Order::ELEM ); + localIndex const kf = m_sei( iconn, Order::FACE ); + + // Get flow quantities on the elem/face + real64 faceDens, faceVisc; + constitutive::SingleFluidBaseUpdate::computeValues( m_fluidWrapper, m_facePres[kf], faceDens, faceVisc ); + + mobility[Order::ELEM] = m_mob[er][esr][ei]; + singlePhaseBaseKernels::MobilityKernel::compute( faceDens, faceVisc, mobility[Order::FACE] ); + + dMobility_dP[Order::ELEM] = m_dMob_dPres[er][esr][ei]; + dMobility_dP[Order::FACE] = 0.0; + + // Compute average density + real64 const densMean = 0.5 * ( m_dens[er][esr][ei][0] + faceDens ); + real64 const dDens_dP = 0.5 * m_dDens_dPres[er][esr][ei][0]; + + // Evaluate potential difference + real64 const potDif = (m_pres[er][esr][ei] - m_facePres[kf]) + - densMean * (m_gravCoef[er][esr][ei] - m_faceGravCoef[kf]); + real64 const dPotDif_dP = 1.0 - dDens_dP * m_gravCoef[er][esr][ei]; + + real64 dTrans_dPerm[3]; + m_stencilWrapper.computeWeights( iconn, m_permeability, stack.transmissibility, dTrans_dPerm ); + real64 const dTrans_dPres = LvArray::tensorOps::AiBi< 3 >( dTrans_dPerm, m_dPerm_dPres[er][esr][ei][0] ); + + real64 const f = stack.transmissibility * potDif; + real64 const dF_dP = stack.transmissibility * dPotDif_dP + dTrans_dPres * potDif; + + // Upwind mobility + localIndex const k_up = ( potDif >= 0 ) ? Order::ELEM : Order::FACE; + real64 const mobility_up = mobility[k_up]; + real64 const dMobility_dP_up = dMobility_dP[k_up]; + + // call the lambda in the phase loop to allow the reuse of the fluxes and their derivatives + // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase + + compFluxKernelOp( er, esr, ei, kf, f, dF_dP, mobility_up, dMobility_dP_up ); + + // *** end of upwinding + + // Populate local flux vector and derivatives + + stack.localFlux[0] = m_dt * mobility[k_up] * f; + stack.localFluxJacobian[0][0] = m_dt * ( mobility_up * dF_dP + dMobility_dP_up * f ); + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void complete( localIndex const iconn, + StackVariables & stack, + FUNC && assemblyKernelOp = NoOpFunc{} ) const + { + using Order = BoundaryStencil::Order; + + localIndex const er = m_seri( iconn, Order::ELEM ); + localIndex const esr = m_sesri( iconn, Order::ELEM ); + localIndex const ei = m_sei( iconn, Order::ELEM ); + + if( m_ghostRank[er][esr][ei] < 0 ) + { + // Add to global residual/jacobian + globalIndex const dofIndex = m_dofNumber[er][esr][ei]; + localIndex const localRow = LvArray::integerConversion< localIndex >( dofIndex - m_rankOffset ); + + RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow], stack.localFlux[0] ); + + AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow, + stack.dofColIndices, + stack.localFluxJacobian[0], + numDof ); + + assemblyKernelOp( localRow ); + } + } + +protected: + + /// Views on face pressure, temperature, and composition + arrayView1d< real64 const > const m_facePres; + + /// View on the face gravity coefficient + arrayView1d< real64 const > const m_faceGravCoef; + + /// Reference to the fluid wrapper + FLUIDWRAPPER const m_fluidWrapper; + +}; + + +/** + * @class DirichletFluxComputeKernelFactory + */ +class DirichletFluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] solverName name of the solver (to name accessors) + * @param[in] faceManager reference to the face manager + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the boundary stencil wrapper + * @param[in] fluidBase the single phase fluid constitutive model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY > + static void + createAndLaunch( globalIndex const rankOffset, + string const & dofKey, + string const & solverName, + FaceManager const & faceManager, + ElementRegionManager const & elemManager, + BoundaryStencilWrapper const & stencilWrapper, + constitutive::SingleFluidBase & fluidBase, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + constitutiveUpdatePassThru( fluidBase, [&]( auto & fluid ) + { + using FluidType = TYPEOFREF( fluid ); + typename FluidType::KernelWrapper fluidWrapper = fluid.createKernelWrapper(); + + integer constexpr NUM_DOF = 1; + integer constexpr NUM_EQN = 1; + using kernelType = DirichletFluxComputeKernel< NUM_EQN, NUM_DOF, typename FluidType::KernelWrapper >; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + typename kernelType::SinglePhaseFlowAccessors singlePhaseFlowAccessors( elemManager, solverName ); + typename kernelType::SinglePhaseFluidAccessors singlePhaseFluidAccessors( elemManager, solverName ); + typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + + kernelType kernel( rankOffset, + faceManager, + stencilWrapper, + fluidWrapper, + dofNumberAccessor, + singlePhaseFlowAccessors, + singlePhaseFluidAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs ); + + kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } + +}; + +} // namespace singlePhaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_DIRICHLETFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp index 6e6e8e61b74..9ee7550c9b7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp @@ -17,8 +17,8 @@ * @file FluidUpdateKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -52,4 +52,4 @@ struct FluidUpdateKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUIDUPDATEKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp new file mode 100644 index 00000000000..2b87d98b83d --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp @@ -0,0 +1,403 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXCOMPUTEKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp" + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" +#include "constitutive/fluid/singlefluid/SlurryFluidBase.hpp" +#include "constitutive/fluid/singlefluid/SlurryFluidFields.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "linearAlgebra/interfaces/InterfaceTypes.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseFVMKernels +{ + +/** + * @class FluxComputeKernel + * @tparam NUM_DOF number of degrees of freedom + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @brief Define the interface for the assembly kernel in charge of flux terms + */ +template< integer NUM_EQN, integer NUM_DOF, typename STENCILWRAPPER > +class FluxComputeKernel : public FluxComputeKernelBase +{ +public: + + /// Compute time value for the number of degrees of freedom + static constexpr integer numDof = NUM_DOF; + + /// Compute time value for the number of equations + static constexpr integer numEqn = NUM_EQN; + + /// Maximum number of elements at the face + static constexpr localIndex maxNumElems = STENCILWRAPPER::maxNumPointsInFlux; + + /// Maximum number of connections at the face + static constexpr localIndex maxNumConns = STENCILWRAPPER::maxNumConnections; + + /// Maximum number of points in the stencil + static constexpr localIndex maxStencilSize = STENCILWRAPPER::maxStencilSize; + + /** + * @brief Constructor for the kernel interface + * @param[in] rankOffset the offset of my MPI rank + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dofNumberAccessor + * @param[in] singlePhaseFlowAccessors + * @param[in] singlePhaseFluidAccessors + * @param[in] permeabilityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + FluxComputeKernel( globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + : FluxComputeKernelBase( rankOffset, + dofNumberAccessor, + singlePhaseFlowAccessors, + singlePhaseFluidAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs ), + m_stencilWrapper( stencilWrapper ), + m_seri( stencilWrapper.getElementRegionIndices() ), + m_sesri( stencilWrapper.getElementSubRegionIndices() ), + m_sei( stencilWrapper.getElementIndices() ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const size, localIndex numElems ) + : stencilSize( size ), + numFluxElems( numElems ), + dofColIndices( size * numDof ), + localFlux( numElems * numEqn ), + localFluxJacobian( numElems * numEqn, size * numDof ) + {} + + // Stencil information + + /// Stencil size for a given connection + localIndex const stencilSize; + + /// Number of elements for a given connection + localIndex const numFluxElems; + + // Transmissibility and derivatives + + /// Transmissibility + real64 transmissibility[maxNumConns][2]{}; + /// Derivatives of transmissibility with respect to pressure + real64 dTrans_dPres[maxNumConns][2]{}; + + // Local degrees of freedom and local residual/jacobian + + /// Indices of the matrix rows/columns corresponding to the dofs in this face + stackArray1d< globalIndex, maxNumElems * numDof > dofColIndices; + + /// Storage for the face local residual vector (all equations except volume balance) + stackArray1d< real64, maxNumElems * numEqn > localFlux; + /// Storage for the face local Jacobian matrix + stackArray2d< real64, maxNumElems * numEqn * maxStencilSize * numDof > localFluxJacobian; + + }; + + /** + * @brief Getter for the stencil size at this connection + * @param[in] iconn the connection index + * @return the size of the stencil at this connection + */ + GEOS_HOST_DEVICE + localIndex stencilSize( localIndex const iconn ) const + { return m_sei[iconn].size(); } + + /** + * @brief Getter for the number of elements at this connection + * @param[in] iconn the connection index + * @return the number of elements at this connection + */ + GEOS_HOST_DEVICE + localIndex numPointsInFlux( localIndex const iconn ) const + { return m_stencilWrapper.numPointsInFlux( iconn ); } + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] iconn the connection index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const iconn, + StackVariables & stack ) const + { + // set degrees of freedom indices for this face + for( integer i = 0; i < stack.stencilSize; ++i ) + { + globalIndex const offset = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + + for( integer jdof = 0; jdof < numDof; ++jdof ) + { + stack.dofColIndices[i * numDof + jdof] = offset + jdof; + } + } + } + + /** + * @brief Compute the local flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the flux + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] NoOpFunc the function used to customize the computation of the flux + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeFlux( localIndex const iconn, + StackVariables & stack, + FUNC && kernelOp = NoOpFunc{} ) const + { + // first, compute the transmissibilities at this face + m_stencilWrapper.computeWeights( iconn, + m_permeability, + m_dPerm_dPres, + stack.transmissibility, + stack.dTrans_dPres ); + + localIndex k[2]; + localIndex connectionIndex = 0; + + for( k[0] = 0; k[0] < stack.numFluxElems; ++k[0] ) + { + for( k[1] = k[0] + 1; k[1] < stack.numFluxElems; ++k[1] ) + { + real64 fluxVal = 0.0; + real64 dFlux_dTrans = 0.0; + real64 alpha = 0.0; + real64 mobility = 0.0; + real64 potGrad = 0.0; + real64 trans[2] = { stack.transmissibility[connectionIndex][0], stack.transmissibility[connectionIndex][1] }; + real64 dTrans[2] = { stack.dTrans_dPres[connectionIndex][0], stack.dTrans_dPres[connectionIndex][1] }; + real64 dFlux_dP[2] = {0.0, 0.0}; + localIndex const regionIndex[2] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; + localIndex const subRegionIndex[2] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; + localIndex const elementIndex[2] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; + + singlePhaseFluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, + trans, + dTrans, + m_pres, + m_gravCoef, + m_dens, + m_dDens_dPres, + m_mob, + m_dMob_dPres, + alpha, + mobility, + potGrad, + fluxVal, + dFlux_dP, + dFlux_dTrans ); + + // populate local flux vector and derivatives + stack.localFlux[k[0]*numEqn] += m_dt * fluxVal; + stack.localFlux[k[1]*numEqn] -= m_dt * fluxVal; + + for( integer ke = 0; ke < 2; ++ke ) + { + localIndex const localDofIndexPres = k[ke] * numDof; + stack.localFluxJacobian[k[0]*numEqn][localDofIndexPres] += m_dt * dFlux_dP[ke]; + stack.localFluxJacobian[k[1]*numEqn][localDofIndexPres] -= m_dt * dFlux_dP[ke]; + } + + // Customize the kernel with this lambda + kernelOp( k, regionIndex, subRegionIndex, elementIndex, connectionIndex, alpha, mobility, potGrad, fluxVal, dFlux_dP ); + + connectionIndex++; + } + } + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void complete( localIndex const iconn, + StackVariables & stack, + FUNC && kernelOp = NoOpFunc{} ) const + { + // add contribution to residual and jacobian into: + // - the mass balance equation + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + for( integer i = 0; i < stack.numFluxElems; ++i ) + { + if( m_ghostRank[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 ) + { + globalIndex const globalRow = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( m_localMatrix.numRows(), localRow ); + + RAJA::atomicAdd( parallelDeviceAtomic{}, &m_localRhs[localRow], stack.localFlux[i * numEqn] ); + m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( localRow, + stack.dofColIndices.data(), + stack.localFluxJacobian[i * numEqn].dataIfContiguous(), + stack.stencilSize * numDof ); + + // call the lambda to assemble additional terms, such as thermal terms + kernelOp( i, localRow ); + } + } + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numConnections the number of connections + * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numConnections, + KERNEL_TYPE const & kernelComponent ) + { + GEOS_MARK_FUNCTION; + + forAll< POLICY >( numConnections, [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ), + kernelComponent.numPointsInFlux( iconn ) ); + + kernelComponent.setup( iconn, stack ); + kernelComponent.computeFlux( iconn, stack ); + kernelComponent.complete( iconn, stack ); + } ); + } + + +protected: + + // Stencil information + + /// Reference to the stencil wrapper + STENCILWRAPPER const m_stencilWrapper; + + /// Connection to element maps + typename STENCILWRAPPER::IndexContainerViewConstType const m_seri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sesri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sei; +}; + +/** + * @class FluxComputeKernelFactory + */ +class FluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] solverName name of the solver (to name accessors) + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename STENCILWRAPPER > + static void + createAndLaunch( globalIndex const rankOffset, + string const & dofKey, + string const & solverName, + ElementRegionManager const & elemManager, + STENCILWRAPPER const & stencilWrapper, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + integer constexpr NUM_EQN = 1; + integer constexpr NUM_DOF = 1; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + using kernelType = FluxComputeKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; + typename kernelType::SinglePhaseFlowAccessors flowAccessors( elemManager, solverName ); + typename kernelType::SinglePhaseFluidAccessors fluidAccessors( elemManager, solverName ); + typename kernelType::PermeabilityAccessors permAccessors( elemManager, solverName ); + + kernelType kernel( rankOffset, stencilWrapper, dofNumberAccessor, + flowAccessors, fluidAccessors, permAccessors, + dt, localMatrix, localRhs ); + kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } +}; + +} // namespace singlePhaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp new file mode 100644 index 00000000000..0c9f0544413 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp @@ -0,0 +1,179 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluxComputeKernelBase.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXCOMPUTEKERNELBASE_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXCOMPUTEKERNELBASE_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" +#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" +#include "constitutive/fluid/singlefluid/SlurryFluidBase.hpp" +#include "constitutive/fluid/singlefluid/SlurryFluidFields.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "linearAlgebra/interfaces/InterfaceTypes.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" +#include "codingUtilities/Utilities.hpp" + +namespace geos +{ + +namespace singlePhaseFVMKernels +{ + +/******************************** FluxComputeKernelBase ********************************/ + +/** + * @brief Base class for FluxComputeKernel that holds all data not dependent + * on template parameters (like stencil type and number of dofs). + */ +class FluxComputeKernelBase +{ +public: + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using DofNumberAccessor = ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > >; + + using SinglePhaseFlowAccessors = + StencilAccessors< fields::ghostRank, + fields::flow::pressure, + fields::flow::pressure_n, + fields::flow::gravityCoefficient, + fields::flow::mobility, + fields::flow::dMobility_dPressure >; + + using SinglePhaseFluidAccessors = + StencilMaterialAccessors< constitutive::SingleFluidBase, + fields::singlefluid::density, + fields::singlefluid::dDensity_dPressure >; + + using SlurryFluidAccessors = + StencilMaterialAccessors< constitutive::SlurryFluidBase, + fields::singlefluid::density, + fields::singlefluid::dDensity_dPressure >; + + using PermeabilityAccessors = + StencilMaterialAccessors< constitutive::PermeabilityBase, + fields::permeability::permeability, + fields::permeability::dPerm_dPressure >; + + using ProppantPermeabilityAccessors = + StencilMaterialAccessors< constitutive::PermeabilityBase, + fields::permeability::permeability, + fields::permeability::dPerm_dPressure, + fields::permeability::dPerm_dDispJump, + fields::permeability::permeabilityMultiplier >; + + /** + * @brief Constructor for the kernel interface + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofNumberAccessor accessor for the dof numbers + * @param[in] singleFlowAccessors accessor for wrappers registered by the solver + * @param[in] singlePhaseFluidAccessors accessor for wrappers registered by the singlefluid model + * @param[in] permeabilityAccessors accessor for wrappers registered by the permeability model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + FluxComputeKernelBase( globalIndex const rankOffset, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + : m_rankOffset( rankOffset ), + m_dt( dt ), + m_dofNumber( dofNumberAccessor.toNestedViewConst() ), + m_permeability( permeabilityAccessors.get( fields::permeability::permeability {} ) ), + m_dPerm_dPres( permeabilityAccessors.get( fields::permeability::dPerm_dPressure {} ) ), + m_ghostRank( singlePhaseFlowAccessors.get( fields::ghostRank {} ) ), + m_gravCoef( singlePhaseFlowAccessors.get( fields::flow::gravityCoefficient {} ) ), + m_pres( singlePhaseFlowAccessors.get( fields::flow::pressure {} ) ), + m_mob( singlePhaseFlowAccessors.get( fields::flow::mobility {} ) ), + m_dMob_dPres( singlePhaseFlowAccessors.get( fields::flow::dMobility_dPressure {} ) ), + m_dens( singlePhaseFluidAccessors.get( fields::singlefluid::density {} ) ), + m_dDens_dPres( singlePhaseFluidAccessors.get( fields::singlefluid::dDensity_dPressure {} ) ), + m_localMatrix( localMatrix ), + m_localRhs( localRhs ) + {} + +protected: + + /// Offset for my MPI rank + globalIndex const m_rankOffset; + + /// Time step size + real64 const m_dt; + + /// Views on dof numbers + ElementViewConst< arrayView1d< globalIndex const > > const m_dofNumber; + + /// Views on permeability + ElementViewConst< arrayView3d< real64 const > > m_permeability; + ElementViewConst< arrayView3d< real64 const > > m_dPerm_dPres; + + /// Views on ghost rank numbers and gravity coefficients + ElementViewConst< arrayView1d< integer const > > const m_ghostRank; + ElementViewConst< arrayView1d< real64 const > > const m_gravCoef; + + // Primary and secondary variables + /// Views on pressure + ElementViewConst< arrayView1d< real64 const > > const m_pres; + + /// Views on fluid mobility + ElementViewConst< arrayView1d< real64 const > > const m_mob; + ElementViewConst< arrayView1d< real64 const > > const m_dMob_dPres; + + /// Views on fluid density + ElementViewConst< arrayView2d< real64 const > > const m_dens; + ElementViewConst< arrayView2d< real64 const > > const m_dDens_dPres; + + // Residual and jacobian + + /// View on the local CRS matrix + CRSMatrixView< real64, globalIndex const > const m_localMatrix; + /// View on the local RHS + arrayView1d< real64 > const m_localRhs; +}; + +} // namespace singlePhaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXCOMPUTEKERNELBASE_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp index b3b9f6a5a1d..07f81dfd2f0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp @@ -14,11 +14,11 @@ */ /** - * @file SinglePhaseFluxKernelsHelper.hpp + * @file FluxKernelsHelper.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUXKERNELSHELPER_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUXKERNELSHELPER_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXKERNELSHELPER_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXKERNELSHELPER_HPP #include "common/DataTypes.hpp" #include "mesh/ElementRegionManager.hpp" @@ -289,4 +289,4 @@ void computeConductiveFlux( localIndex const ( &seri )[2], } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFLUXKERNELSHELPER_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUXKERNELSHELPER_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp index f702d0a7218..a988df8fd38 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file SinglePhaseHydrostaticPressureKernel.hpp + * @file HydrostaticPressureKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYDROSTATICPRESSUREKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYDROSTATICPRESSUREKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_HYDROSTATICPRESSUREKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_HYDROSTATICPRESSUREKERNEL_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -211,4 +211,4 @@ struct HydrostaticPressureKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYDROSTATICPRESSUREKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_HYDROSTATICPRESSUREKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp index d94e81fd379..22f6470f5f3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file SinglePhaseMobilityKernel.hpp + * @file MobilityKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEMOBILITYKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEMOBILITYKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_MOBILITYKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_MOBILITYKERNEL_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -146,4 +146,4 @@ struct MobilityKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEMOBILITYKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_MOBILITYKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp index 2044101e348..7293104cf2b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file SinglePhaseResidualNormKernel.hpp + * @file ResidualNormKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASERESIDUALNORMKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASERESIDUALNORMKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_RESIDUALNORMKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_RESIDUALNORMKERNEL_HPP #include "physicsSolvers/SolverBaseKernels.hpp" @@ -265,4 +265,4 @@ class ResidualNormKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASERESIDUALNORMKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_RESIDUALNORMKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp deleted file mode 100644 index 3f5e918c5c3..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp +++ /dev/null @@ -1,847 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 SinglePhaseFVMKernels.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFVMKERNELS_HPP - -#include "common/DataLayouts.hpp" -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" -#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" -#include "constitutive/fluid/singlefluid/SlurryFluidBase.hpp" -#include "constitutive/fluid/singlefluid/SlurryFluidFields.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/BoundaryStencil.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "linearAlgebra/interfaces/InterfaceTypes.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" -#include "codingUtilities/Utilities.hpp" - -namespace geos -{ - -namespace singlePhaseFVMKernels -{ - -/******************************** FaceBasedAssemblyKernelBase ********************************/ - -/** - * @brief Base class for FaceBasedAssemblyKernel that holds all data not dependent - * on template parameters (like stencil type and number of dofs). - */ -class FaceBasedAssemblyKernelBase -{ -public: - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using DofNumberAccessor = ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > >; - - using SinglePhaseFlowAccessors = - StencilAccessors< fields::ghostRank, - fields::flow::pressure, - fields::flow::pressure_n, - fields::flow::gravityCoefficient, - fields::flow::mobility, - fields::flow::dMobility_dPressure >; - - using SinglePhaseFluidAccessors = - StencilMaterialAccessors< constitutive::SingleFluidBase, - fields::singlefluid::density, - fields::singlefluid::dDensity_dPressure >; - - using SlurryFluidAccessors = - StencilMaterialAccessors< constitutive::SlurryFluidBase, - fields::singlefluid::density, - fields::singlefluid::dDensity_dPressure >; - - using PermeabilityAccessors = - StencilMaterialAccessors< constitutive::PermeabilityBase, - fields::permeability::permeability, - fields::permeability::dPerm_dPressure >; - - using ProppantPermeabilityAccessors = - StencilMaterialAccessors< constitutive::PermeabilityBase, - fields::permeability::permeability, - fields::permeability::dPerm_dPressure, - fields::permeability::dPerm_dDispJump, - fields::permeability::permeabilityMultiplier >; - - /** - * @brief Constructor for the kernel interface - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofNumberAccessor accessor for the dof numbers - * @param[in] singleFlowAccessors accessor for wrappers registered by the solver - * @param[in] singlePhaseFluidAccessors accessor for wrappers registered by the singlefluid model - * @param[in] permeabilityAccessors accessor for wrappers registered by the permeability model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - FaceBasedAssemblyKernelBase( globalIndex const rankOffset, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - : m_rankOffset( rankOffset ), - m_dt( dt ), - m_dofNumber( dofNumberAccessor.toNestedViewConst() ), - m_permeability( permeabilityAccessors.get( fields::permeability::permeability {} ) ), - m_dPerm_dPres( permeabilityAccessors.get( fields::permeability::dPerm_dPressure {} ) ), - m_ghostRank( singlePhaseFlowAccessors.get( fields::ghostRank {} ) ), - m_gravCoef( singlePhaseFlowAccessors.get( fields::flow::gravityCoefficient {} ) ), - m_pres( singlePhaseFlowAccessors.get( fields::flow::pressure {} ) ), - m_mob( singlePhaseFlowAccessors.get( fields::flow::mobility {} ) ), - m_dMob_dPres( singlePhaseFlowAccessors.get( fields::flow::dMobility_dPressure {} ) ), - m_dens( singlePhaseFluidAccessors.get( fields::singlefluid::density {} ) ), - m_dDens_dPres( singlePhaseFluidAccessors.get( fields::singlefluid::dDensity_dPressure {} ) ), - m_localMatrix( localMatrix ), - m_localRhs( localRhs ) - {} - -protected: - - /// Offset for my MPI rank - globalIndex const m_rankOffset; - - /// Time step size - real64 const m_dt; - - /// Views on dof numbers - ElementViewConst< arrayView1d< globalIndex const > > const m_dofNumber; - - /// Views on permeability - ElementViewConst< arrayView3d< real64 const > > m_permeability; - ElementViewConst< arrayView3d< real64 const > > m_dPerm_dPres; - - /// Views on ghost rank numbers and gravity coefficients - ElementViewConst< arrayView1d< integer const > > const m_ghostRank; - ElementViewConst< arrayView1d< real64 const > > const m_gravCoef; - - // Primary and secondary variables - /// Views on pressure - ElementViewConst< arrayView1d< real64 const > > const m_pres; - - /// Views on fluid mobility - ElementViewConst< arrayView1d< real64 const > > const m_mob; - ElementViewConst< arrayView1d< real64 const > > const m_dMob_dPres; - - /// Views on fluid density - ElementViewConst< arrayView2d< real64 const > > const m_dens; - ElementViewConst< arrayView2d< real64 const > > const m_dDens_dPres; - - // Residual and jacobian - - /// View on the local CRS matrix - CRSMatrixView< real64, globalIndex const > const m_localMatrix; - /// View on the local RHS - arrayView1d< real64 > const m_localRhs; -}; - -/** - * @class FaceBasedAssemblyKernel - * @tparam NUM_DOF number of degrees of freedom - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @brief Define the interface for the assembly kernel in charge of flux terms - */ -template< integer NUM_EQN, integer NUM_DOF, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase -{ -public: - - /// Compute time value for the number of degrees of freedom - static constexpr integer numDof = NUM_DOF; - - /// Compute time value for the number of equations - static constexpr integer numEqn = NUM_EQN; - - /// Maximum number of elements at the face - static constexpr localIndex maxNumElems = STENCILWRAPPER::maxNumPointsInFlux; - - /// Maximum number of connections at the face - static constexpr localIndex maxNumConns = STENCILWRAPPER::maxNumConnections; - - /// Maximum number of points in the stencil - static constexpr localIndex maxStencilSize = STENCILWRAPPER::maxStencilSize; - - /** - * @brief Constructor for the kernel interface - * @param[in] rankOffset the offset of my MPI rank - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dofNumberAccessor - * @param[in] singlePhaseFlowAccessors - * @param[in] singlePhaseFluidAccessors - * @param[in] permeabilityAccessors - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - FaceBasedAssemblyKernel( globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - : FaceBasedAssemblyKernelBase( rankOffset, - dofNumberAccessor, - singlePhaseFlowAccessors, - singlePhaseFluidAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs ), - m_stencilWrapper( stencilWrapper ), - m_seri( stencilWrapper.getElementRegionIndices() ), - m_sesri( stencilWrapper.getElementSubRegionIndices() ), - m_sei( stencilWrapper.getElementIndices() ) - {} - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables - { -public: - - /** - * @brief Constructor for the stack variables - * @param[in] size size of the stencil for this connection - * @param[in] numElems number of elements for this connection - */ - GEOS_HOST_DEVICE - StackVariables( localIndex const size, localIndex numElems ) - : stencilSize( size ), - numFluxElems( numElems ), - dofColIndices( size * numDof ), - localFlux( numElems * numEqn ), - localFluxJacobian( numElems * numEqn, size * numDof ) - {} - - // Stencil information - - /// Stencil size for a given connection - localIndex const stencilSize; - - /// Number of elements for a given connection - localIndex const numFluxElems; - - // Transmissibility and derivatives - - /// Transmissibility - real64 transmissibility[maxNumConns][2]{}; - /// Derivatives of transmissibility with respect to pressure - real64 dTrans_dPres[maxNumConns][2]{}; - - // Local degrees of freedom and local residual/jacobian - - /// Indices of the matrix rows/columns corresponding to the dofs in this face - stackArray1d< globalIndex, maxNumElems * numDof > dofColIndices; - - /// Storage for the face local residual vector (all equations except volume balance) - stackArray1d< real64, maxNumElems * numEqn > localFlux; - /// Storage for the face local Jacobian matrix - stackArray2d< real64, maxNumElems * numEqn * maxStencilSize * numDof > localFluxJacobian; - - }; - - /** - * @brief Getter for the stencil size at this connection - * @param[in] iconn the connection index - * @return the size of the stencil at this connection - */ - GEOS_HOST_DEVICE - localIndex stencilSize( localIndex const iconn ) const - { return m_sei[iconn].size(); } - - /** - * @brief Getter for the number of elements at this connection - * @param[in] iconn the connection index - * @return the number of elements at this connection - */ - GEOS_HOST_DEVICE - localIndex numPointsInFlux( localIndex const iconn ) const - { return m_stencilWrapper.numPointsInFlux( iconn ); } - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] iconn the connection index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - void setup( localIndex const iconn, - StackVariables & stack ) const - { - // set degrees of freedom indices for this face - for( integer i = 0; i < stack.stencilSize; ++i ) - { - globalIndex const offset = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; - - for( integer jdof = 0; jdof < numDof; ++jdof ) - { - stack.dofColIndices[i * numDof + jdof] = offset + jdof; - } - } - } - - /** - * @brief Compute the local flux contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the computation of the flux - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - * @param[in] NoOpFunc the function used to customize the computation of the flux - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void computeFlux( localIndex const iconn, - StackVariables & stack, - FUNC && kernelOp = NoOpFunc{} ) const - { - // first, compute the transmissibilities at this face - m_stencilWrapper.computeWeights( iconn, - m_permeability, - m_dPerm_dPres, - stack.transmissibility, - stack.dTrans_dPres ); - - localIndex k[2]; - localIndex connectionIndex = 0; - - for( k[0] = 0; k[0] < stack.numFluxElems; ++k[0] ) - { - for( k[1] = k[0] + 1; k[1] < stack.numFluxElems; ++k[1] ) - { - real64 fluxVal = 0.0; - real64 dFlux_dTrans = 0.0; - real64 alpha = 0.0; - real64 mobility = 0.0; - real64 potGrad = 0.0; - real64 trans[2] = { stack.transmissibility[connectionIndex][0], stack.transmissibility[connectionIndex][1] }; - real64 dTrans[2] = { stack.dTrans_dPres[connectionIndex][0], stack.dTrans_dPres[connectionIndex][1] }; - real64 dFlux_dP[2] = {0.0, 0.0}; - localIndex const regionIndex[2] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; - localIndex const subRegionIndex[2] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; - localIndex const elementIndex[2] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; - - singlePhaseFluxKernelsHelper::computeSinglePhaseFlux( regionIndex, subRegionIndex, elementIndex, - trans, - dTrans, - m_pres, - m_gravCoef, - m_dens, - m_dDens_dPres, - m_mob, - m_dMob_dPres, - alpha, - mobility, - potGrad, - fluxVal, - dFlux_dP, - dFlux_dTrans ); - - // populate local flux vector and derivatives - stack.localFlux[k[0]*numEqn] += m_dt * fluxVal; - stack.localFlux[k[1]*numEqn] -= m_dt * fluxVal; - - for( integer ke = 0; ke < 2; ++ke ) - { - localIndex const localDofIndexPres = k[ke] * numDof; - stack.localFluxJacobian[k[0]*numEqn][localDofIndexPres] += m_dt * dFlux_dP[ke]; - stack.localFluxJacobian[k[1]*numEqn][localDofIndexPres] -= m_dt * dFlux_dP[ke]; - } - - // Customize the kernel with this lambda - kernelOp( k, regionIndex, subRegionIndex, elementIndex, connectionIndex, alpha, mobility, potGrad, fluxVal, dFlux_dP ); - - connectionIndex++; - } - } - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void complete( localIndex const iconn, - StackVariables & stack, - FUNC && kernelOp = NoOpFunc{} ) const - { - // add contribution to residual and jacobian into: - // - the mass balance equation - // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels - for( integer i = 0; i < stack.numFluxElems; ++i ) - { - if( m_ghostRank[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 ) - { - globalIndex const globalRow = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; - localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); - GEOS_ASSERT_GE( localRow, 0 ); - GEOS_ASSERT_GT( m_localMatrix.numRows(), localRow ); - - RAJA::atomicAdd( parallelDeviceAtomic{}, &m_localRhs[localRow], stack.localFlux[i * numEqn] ); - m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( localRow, - stack.dofColIndices.data(), - stack.localFluxJacobian[i * numEqn].dataIfContiguous(), - stack.stencilSize * numDof ); - - // call the lambda to assemble additional terms, such as thermal terms - kernelOp( i, localRow ); - } - } - } - - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numConnections the number of connections - * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables - */ - template< typename POLICY, typename KERNEL_TYPE > - static void - launch( localIndex const numConnections, - KERNEL_TYPE const & kernelComponent ) - { - GEOS_MARK_FUNCTION; - - forAll< POLICY >( numConnections, [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ), - kernelComponent.numPointsInFlux( iconn ) ); - - kernelComponent.setup( iconn, stack ); - kernelComponent.computeFlux( iconn, stack ); - kernelComponent.complete( iconn, stack ); - } ); - } - - -protected: - - // Stencil information - - /// Reference to the stencil wrapper - STENCILWRAPPER const m_stencilWrapper; - - /// Connection to element maps - typename STENCILWRAPPER::IndexContainerViewConstType const m_seri; - typename STENCILWRAPPER::IndexContainerViewConstType const m_sesri; - typename STENCILWRAPPER::IndexContainerViewConstType const m_sei; -}; - -/** - * @class FaceBasedAssemblyKernelFactory - */ -class FaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] solverName name of the solver (to name accessors) - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY, typename STENCILWRAPPER > - static void - createAndLaunch( globalIndex const rankOffset, - string const & dofKey, - string const & solverName, - ElementRegionManager const & elemManager, - STENCILWRAPPER const & stencilWrapper, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - integer constexpr NUM_EQN = 1; - integer constexpr NUM_DOF = 1; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - using kernelType = FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; - typename kernelType::SinglePhaseFlowAccessors flowAccessors( elemManager, solverName ); - typename kernelType::SinglePhaseFluidAccessors fluidAccessors( elemManager, solverName ); - typename kernelType::PermeabilityAccessors permAccessors( elemManager, solverName ); - - kernelType kernel( rankOffset, stencilWrapper, dofNumberAccessor, - flowAccessors, fluidAccessors, permAccessors, - dt, localMatrix, localRhs ); - kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); - } -}; - -/******************************** DirichletFaceBasedAssemblyKernel ********************************/ - -/** - * @class DirichFaceBasedAssemblyKernel - * @tparam FLUIDWRAPPER the type of the fluid wrapper - * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms - */ -template< integer NUM_EQN, integer NUM_DOF, typename FLUIDWRAPPER > -class DirichletFaceBasedAssemblyKernel : public FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, - BoundaryStencilWrapper > -{ -public: - - using AbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; - using DofNumberAccessor = AbstractBase::DofNumberAccessor; - using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; - using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; - using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; - - using AbstractBase::m_dt; - using AbstractBase::m_rankOffset; - using AbstractBase::m_dofNumber; - using AbstractBase::m_ghostRank; - using AbstractBase::m_gravCoef; - using AbstractBase::m_pres; - using AbstractBase::m_mob; - using AbstractBase::m_dMob_dPres; - using AbstractBase::m_dens; - using AbstractBase::m_dDens_dPres; - using AbstractBase::m_permeability; - using AbstractBase::m_dPerm_dPres; - - using AbstractBase::m_localMatrix; - using AbstractBase::m_localRhs; - - using Base = singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, - BoundaryStencilWrapper >; - using Base::numDof; - using Base::numEqn; - using Base::m_stencilWrapper; - using Base::m_seri; - using Base::m_sesri; - using Base::m_sei; - - /** - * @brief Constructor for the kernel interface - * @param[in] rankOffset the offset of my MPI rank - * @param[in] faceManager the face manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] fluidWrapper reference to the fluid wrapper - * @param[in] dofNumberAccessor - * @param[in] singlePhaseFlowAccessors - * @param[in] singlePhaseFluidAccessors - * @param[in] permeabilityAccessors - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - DirichletFaceBasedAssemblyKernel( globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - : Base( rankOffset, - stencilWrapper, - dofNumberAccessor, - singlePhaseFlowAccessors, - singlePhaseFluidAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs ), - m_facePres( faceManager.getField< fields::flow::facePressure >() ), - m_faceGravCoef( faceManager.getField< fields::flow::gravityCoefficient >() ), - m_fluidWrapper( fluidWrapper ) - {} - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables - { -public: - - /** - * @brief Constructor for the stack variables - * @param[in] size size of the stencil for this connection - * @param[in] numElems number of elements for this connection - */ - GEOS_HOST_DEVICE - StackVariables( localIndex const GEOS_UNUSED_PARAM( size ), - localIndex GEOS_UNUSED_PARAM( numElems ) ) - {} - - /// Transmissibility - real64 transmissibility = 0.0; - - /// Indices of the matrix rows/columns corresponding to the dofs in this face - globalIndex dofColIndices[numDof]{}; - - /// Storage for the face local residual - real64 localFlux[numEqn]{}; - - /// Storage for the face local Jacobian - real64 localFluxJacobian[numEqn][numDof]{}; - - }; - - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] iconn the connection index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - void setup( localIndex const iconn, - StackVariables & stack ) const - { - globalIndex const offset = - m_dofNumber[m_seri( iconn, BoundaryStencil::Order::ELEM )][m_sesri( iconn, BoundaryStencil::Order::ELEM )][m_sei( iconn, BoundaryStencil::Order::ELEM )]; - - for( integer jdof = 0; jdof < numDof; ++jdof ) - { - stack.dofColIndices[jdof] = offset + jdof; - } - } - - /** - * @brief Compute the local Dirichlet face flux contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void computeFlux( localIndex const iconn, - StackVariables & stack, - FUNC && compFluxKernelOp = NoOpFunc{} ) const - { - using Order = BoundaryStencil::Order; - localIndex constexpr numElems = BoundaryStencil::maxNumPointsInFlux; - - stackArray1d< real64, numElems > mobility( numElems ); - stackArray1d< real64, numElems > dMobility_dP( numElems ); - - localIndex const er = m_seri( iconn, Order::ELEM ); - localIndex const esr = m_sesri( iconn, Order::ELEM ); - localIndex const ei = m_sei( iconn, Order::ELEM ); - localIndex const kf = m_sei( iconn, Order::FACE ); - - // Get flow quantities on the elem/face - real64 faceDens, faceVisc; - constitutive::SingleFluidBaseUpdate::computeValues( m_fluidWrapper, m_facePres[kf], faceDens, faceVisc ); - - mobility[Order::ELEM] = m_mob[er][esr][ei]; - singlePhaseBaseKernels::MobilityKernel::compute( faceDens, faceVisc, mobility[Order::FACE] ); - - dMobility_dP[Order::ELEM] = m_dMob_dPres[er][esr][ei]; - dMobility_dP[Order::FACE] = 0.0; - - // Compute average density - real64 const densMean = 0.5 * ( m_dens[er][esr][ei][0] + faceDens ); - real64 const dDens_dP = 0.5 * m_dDens_dPres[er][esr][ei][0]; - - // Evaluate potential difference - real64 const potDif = (m_pres[er][esr][ei] - m_facePres[kf]) - - densMean * (m_gravCoef[er][esr][ei] - m_faceGravCoef[kf]); - real64 const dPotDif_dP = 1.0 - dDens_dP * m_gravCoef[er][esr][ei]; - - real64 dTrans_dPerm[3]; - m_stencilWrapper.computeWeights( iconn, m_permeability, stack.transmissibility, dTrans_dPerm ); - real64 const dTrans_dPres = LvArray::tensorOps::AiBi< 3 >( dTrans_dPerm, m_dPerm_dPres[er][esr][ei][0] ); - - real64 const f = stack.transmissibility * potDif; - real64 const dF_dP = stack.transmissibility * dPotDif_dP + dTrans_dPres * potDif; - - // Upwind mobility - localIndex const k_up = ( potDif >= 0 ) ? Order::ELEM : Order::FACE; - real64 const mobility_up = mobility[k_up]; - real64 const dMobility_dP_up = dMobility_dP[k_up]; - - // call the lambda in the phase loop to allow the reuse of the fluxes and their derivatives - // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase - - compFluxKernelOp( er, esr, ei, kf, f, dF_dP, mobility_up, dMobility_dP_up ); - - // *** end of upwinding - - // Populate local flux vector and derivatives - - stack.localFlux[0] = m_dt * mobility[k_up] * f; - stack.localFluxJacobian[0][0] = m_dt * ( mobility_up * dF_dP + dMobility_dP_up * f ); - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void complete( localIndex const iconn, - StackVariables & stack, - FUNC && assemblyKernelOp = NoOpFunc{} ) const - { - using Order = BoundaryStencil::Order; - - localIndex const er = m_seri( iconn, Order::ELEM ); - localIndex const esr = m_sesri( iconn, Order::ELEM ); - localIndex const ei = m_sei( iconn, Order::ELEM ); - - if( m_ghostRank[er][esr][ei] < 0 ) - { - // Add to global residual/jacobian - globalIndex const dofIndex = m_dofNumber[er][esr][ei]; - localIndex const localRow = LvArray::integerConversion< localIndex >( dofIndex - m_rankOffset ); - - RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow], stack.localFlux[0] ); - - AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > - ( localRow, - stack.dofColIndices, - stack.localFluxJacobian[0], - numDof ); - - assemblyKernelOp( localRow ); - } - } - -protected: - - /// Views on face pressure, temperature, and composition - arrayView1d< real64 const > const m_facePres; - - /// View on the face gravity coefficient - arrayView1d< real64 const > const m_faceGravCoef; - - /// Reference to the fluid wrapper - FLUIDWRAPPER const m_fluidWrapper; - -}; - - -/** - * @class DirichletFaceBasedAssemblyKernelFactory - */ -class DirichletFaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] solverName name of the solver (to name accessors) - * @param[in] faceManager reference to the face manager - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the boundary stencil wrapper - * @param[in] fluidBase the single phase fluid constitutive model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( globalIndex const rankOffset, - string const & dofKey, - string const & solverName, - FaceManager const & faceManager, - ElementRegionManager const & elemManager, - BoundaryStencilWrapper const & stencilWrapper, - constitutive::SingleFluidBase & fluidBase, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - constitutiveUpdatePassThru( fluidBase, [&]( auto & fluid ) - { - using FluidType = TYPEOFREF( fluid ); - typename FluidType::KernelWrapper fluidWrapper = fluid.createKernelWrapper(); - - integer constexpr NUM_DOF = 1; - integer constexpr NUM_EQN = 1; - using kernelType = DirichletFaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, typename FluidType::KernelWrapper >; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - typename kernelType::SinglePhaseFlowAccessors singlePhaseFlowAccessors( elemManager, solverName ); - typename kernelType::SinglePhaseFluidAccessors singlePhaseFluidAccessors( elemManager, solverName ); - typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); - - kernelType kernel( rankOffset, - faceManager, - stencilWrapper, - fluidWrapper, - dofNumberAccessor, - singlePhaseFlowAccessors, - singlePhaseFluidAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs ); - - kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); - } ); - } - -}; - -} // namespace singlePhaseFVMKernels - -} // namespace geos - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEFVMKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp index b38ec193601..2b16e2b2200 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp @@ -17,8 +17,8 @@ * @file SinglePhaseHybridFVMKernels.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYBRIDFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYBRIDFVMKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_HYBRIDFVMKERNELS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_HYBRIDFVMKERNELS_HPP #include "common/DataTypes.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" @@ -959,4 +959,4 @@ class ResidualNormKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEHYBRIDFVMKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_HYBRIDFVMKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp index 6f3395bad2e..9e36375b45c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp @@ -16,8 +16,8 @@ /** * @file SinglePhaseProppantBaseKernels.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEPROPPANTBASEKERNELS_HPP_ -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEPROPPANTBASEKERNELS_HPP_ +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_PROPPANTBASEKERNELS_HPP_ +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_PROPPANTBASEKERNELS_HPP_ #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -61,4 +61,4 @@ struct FluidUpdateKernel } //namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEPROPPANTBASEKERNELS_HPP_ +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_PROPPANTBASEKERNELS_HPP_ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp index 098d9f79ab8..f1fa159957e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp @@ -14,7 +14,7 @@ */ /** - * @file singlePhaseProppantFluxKernels.cpp + * @file SinglePhaseProppantFluxKernels.cpp */ #include "SinglePhaseProppantFluxKernels.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp index 4a9a778ef6e..2ed64c55344 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file SinglePhaseSolutionCheckKernel.hpp + * @file SolutionCheckKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONCHECKKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONCHECKKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONCHECKKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONCHECKKERNEL_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -70,4 +70,4 @@ struct SolutionCheckKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONCHECKKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONCHECKKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp index 39d007994ed..a0b1e3c84d4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file SinglePhaseSolutionScalingKernel.hpp + * @file SolutionScalingKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONSCALINGKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONSCALINGKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONSCALINGKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONSCALINGKERNEL_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" @@ -73,4 +73,4 @@ struct SolutionScalingKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESOLUTIONSCALINGKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONSCALINGKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp similarity index 92% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp index df0c3c0f3cc..c1e1909e00b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp @@ -14,13 +14,13 @@ */ /** - * @file StabilizedSinglePhaseFVMKernels.hpp + * @file StabilizedFluxComputeKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDSINGLEPHASEFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDSINGLEPHASEFVMKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STABILIZEDFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STABILIZEDFLUXCOMPUTEKERNEL_HPP -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp" namespace geos { @@ -28,24 +28,23 @@ namespace geos namespace stabilizedSinglePhaseFVMKernels { - -/******************************** FaceBasedAssemblyKernel ********************************/ +/******************************** FluxComputeKernel ********************************/ /** - * @class FaceBasedAssemblyKernel + * @class FluxComputeKernel * @tparam NUM_DOF number of degrees of freedom * @tparam STENCILWRAPPER the type of the stencil wrapper * @brief Define the interface for the assembly kernel in charge of flux terms */ template< integer NUM_EQN, integer NUM_DOF, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER > +class FluxComputeKernel : public singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER > { public: template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using AbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; + using AbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = AbstractBase::DofNumberAccessor; using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; @@ -67,7 +66,7 @@ class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyK using AbstractBase::m_gravCoef; using AbstractBase::m_pres; - using Base = singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; + using Base = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; using Base::numDof; using Base::numEqn; using Base::maxNumElems; @@ -92,7 +91,7 @@ class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyK * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - FaceBasedAssemblyKernel( globalIndex const rankOffset, + FluxComputeKernel( globalIndex const rankOffset, STENCILWRAPPER const & stencilWrapper, DofNumberAccessor const & dofNumberAccessor, SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, @@ -248,9 +247,9 @@ class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyK }; /** - * @class FaceBasedAssemblyKernelFactory + * @class FluxComputeKernelFactory */ -class FaceBasedAssemblyKernelFactory +class FluxComputeKernelFactory { public: @@ -286,7 +285,7 @@ class FaceBasedAssemblyKernelFactory elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - using KERNEL_TYPE = FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; + using KERNEL_TYPE = FluxComputeKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; typename KERNEL_TYPE::SinglePhaseFlowAccessors singlePhaseFlowAccessors( elemManager, solverName ); typename KERNEL_TYPE::SinglePhaseFluidAccessors singlePhaseFluidAccessors( elemManager, solverName ); typename KERNEL_TYPE::StabSinglePhaseFlowAccessors stabSinglePhaseFlowAccessors( elemManager, solverName ); @@ -306,4 +305,4 @@ class FaceBasedAssemblyKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDSINGLEPHASEFVMKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STABILIZEDFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp index 7caf93efefc..59e0d267dc8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp @@ -14,15 +14,14 @@ */ /** - * @file SinglePhaseStatisticsKernel.hpp + * @file StatisticsKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESTATISTICSKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESTATISTICSKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STATISTICSKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STATISTICSKERNEL_HPP #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "codingUtilities/Utilities.hpp" namespace geos { @@ -131,4 +130,4 @@ struct StatisticsKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASESTATISTICSKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STATISTICSKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp index f044fa9079c..553465d3066 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp @@ -14,11 +14,11 @@ */ /** - * @file ThermalSinglePhaseAccumulationKernels.hpp + * @file ThermalAccumulationKernels.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEACCUMULATIONKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEACCUMULATIONKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALACCUMULATIONKERNELS_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALACCUMULATIONKERNELS_HPP #include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" @@ -334,4 +334,4 @@ class AccumulationKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEBASEKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALACCUMULATIONKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp new file mode 100644 index 00000000000..ad8751eebd1 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp @@ -0,0 +1,394 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalDirichletFluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALDIRICHLETFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALDIRICHLETFLUXCOMPUTEKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp" + +#include "constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.hpp" +#include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" +#include "constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp" + +namespace geos +{ + +namespace thermalSinglePhaseFVMKernels +{ + +/******************************** DirichletFluxComputeKernel ********************************/ + +/** + * @class DirichletFluxComputeKernel + * @tparam FLUIDWRAPPER the type of the fluid wrapper + * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms + */ +template< integer NUM_EQN, integer NUM_DOF, typename FLUIDWRAPPER > +class DirichletFluxComputeKernel : public singlePhaseFVMKernels::DirichletFluxComputeKernel< NUM_EQN, NUM_DOF, FLUIDWRAPPER > +{ +public: + +/** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using AbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; + using DofNumberAccessor = AbstractBase::DofNumberAccessor; + using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; + using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; + using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; + + using AbstractBase::m_dt; + using AbstractBase::m_rankOffset; + using AbstractBase::m_dofNumber; + using AbstractBase::m_ghostRank; + using AbstractBase::m_gravCoef; + using AbstractBase::m_mob; + using AbstractBase::m_pres; + using AbstractBase::m_permeability; + using AbstractBase::m_dPerm_dPres; + + using AbstractBase::m_localMatrix; + using AbstractBase::m_localRhs; + + using Base = singlePhaseFVMKernels::DirichletFluxComputeKernel< NUM_EQN, NUM_DOF, FLUIDWRAPPER >; + using Base::numDof; + using Base::numEqn; + using Base::m_stencilWrapper; + using Base::m_seri; + using Base::m_sesri; + using Base::m_sei; + using Base::m_facePres; + using Base::m_faceGravCoef; + + using ThermalSinglePhaseFlowAccessors = + StencilAccessors< fields::flow::temperature, + fields::flow::dMobility_dTemperature >; + + using ThermalSinglePhaseFluidAccessors = + StencilMaterialAccessors< constitutive::SingleFluidBase, + fields::singlefluid::dDensity_dTemperature, + fields::singlefluid::enthalpy, + fields::singlefluid::dEnthalpy_dPressure, + fields::singlefluid::dEnthalpy_dTemperature >; + + using ThermalConductivityAccessors = + StencilMaterialAccessors< constitutive::SinglePhaseThermalConductivityBase, + fields::thermalconductivity::effectiveConductivity, + fields::thermalconductivity::dEffectiveConductivity_dT >; + + /** + * @brief Constructor for the kernel interface + * @param[in] rankOffset the offset of the MPI rank + * @param[in] faceManager the face manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] fluidWrapper reference to the fluid wrapper + * @param[in] dofNumberAccessor the degree of freedom number accessor + * @param[in] singlePhaseFlowAccessors the single phase flow accessor + * @param[in] thermalSinglePhaseFlowAccessors the thermal single phase flow accessor + * @param[in] singlePhaseFluidAccessors the single phase fluid accessor + * @param[in] thermalSinglePhaseFluidAccessors the thermal single phase fluid accessor + * @param[in] permeabilityAccessors the permeability accessor + * @param[in] thermalConductivityAccessors the thermal conductivity accessor + * @param[in] dt the time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + DirichletFluxComputeKernel( globalIndex const rankOffset, + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + ThermalSinglePhaseFlowAccessors const & thermalSinglePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + ThermalSinglePhaseFluidAccessors const & thermalSinglePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + ThermalConductivityAccessors const & thermalConductivityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + + : Base( rankOffset, + faceManager, + stencilWrapper, + fluidWrapper, + dofNumberAccessor, + singlePhaseFlowAccessors, + singlePhaseFluidAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs ), + m_temp( thermalSinglePhaseFlowAccessors.get( fields::flow::temperature {} ) ), + m_faceTemp( faceManager.getField< fields::flow::faceTemperature >() ), + m_dMob_dTemp( thermalSinglePhaseFlowAccessors.get( fields::flow::dMobility_dTemperature {} ) ), + m_dDens_dTemp( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::dDensity_dTemperature {} ) ), + m_enthalpy( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::enthalpy {} ) ), + m_dEnthalpy_dPres( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::dEnthalpy_dPressure {} ) ), + m_dEnthalpy_dTemp( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::dEnthalpy_dTemperature {} ) ), + m_thermalConductivity( thermalConductivityAccessors.get( fields::thermalconductivity::effectiveConductivity {} ) ), + m_dThermalCond_dT( thermalConductivityAccessors.get( fields::thermalconductivity::dEffectiveConductivity_dT {} ) ) + {} + + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables : Base::StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const size, + localIndex numElems ): + Base::StackVariables( size, + numElems ) + {} + + using Base::StackVariables::localFlux; + using Base::StackVariables::localFluxJacobian; + using Base::StackVariables::dofColIndices; + using Base::StackVariables::transmissibility; + + /// Energy fluxes and derivatives wrt pressure and temperature + real64 energyFlux = 0.0; + real64 dEnergyFlux_dP = 0.0; + real64 dEnergyFlux_dT = 0.0; + }; + + /** + * @brief Compute the local Dirichlet face flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes + */ + GEOS_HOST_DEVICE + void computeFlux( localIndex const iconn, + StackVariables & stack ) const + { + Base::computeFlux( iconn, stack, [&] ( localIndex const er, + localIndex const esr, + localIndex const ei, + localIndex const kf, + real64 const & f, + real64 const & dF_dP, + real64 const & mobility_up, + real64 const & dMobility_dP_up ) + { + + // Compute the derivatives of the density wrt temperature + + real64 const dDens_dT = 0.5 * m_dDens_dTemp[er][esr][ei][0]; + + // Compute the derivatives of the phase potential difference wrt temperature + + real64 const dF_dT = -stack.transmissibility * dDens_dT * ( m_gravCoef[er][esr][ei] - m_faceGravCoef[kf] ); + + // Compute the (upwinded) energy flux + + real64 const flux = mobility_up * f; + real64 const enthalpy = m_enthalpy[er][esr][ei][0]; + stack.energyFlux += flux * enthalpy; + + // Compute the derivatives of the (upwinded) energy flux wrt pressure and temperature + + if( f >= 0 ) // the element is upstream + { + real64 const dFlux_dP = mobility_up * dF_dP + dMobility_dP_up * f; + real64 const dFlux_dT = mobility_up * dF_dT + m_dMob_dTemp[er][esr][ei] * f; + + stack.dEnergyFlux_dP += dFlux_dP * enthalpy + flux * m_dEnthalpy_dPres[er][esr][ei][0]; + stack.dEnergyFlux_dT += dFlux_dT * enthalpy + flux * m_dEnthalpy_dTemp[er][esr][ei][0]; + } + else + { + real64 const dFlux_dP = mobility_up * dF_dP; + real64 const dFlux_dT = mobility_up * dF_dT; + + stack.dEnergyFlux_dP += dFlux_dP * enthalpy; + stack.dEnergyFlux_dT += dFlux_dT * enthalpy; + } + + // Contribution of energy conduction through the solid phase + real64 thermalTrans = 0.0; + real64 dThermalTrans_dThermalCond[3]{}; + m_stencilWrapper.computeWeights( iconn, + m_thermalConductivity, + thermalTrans, + dThermalTrans_dThermalCond ); + + real64 const dThermalTrans_dT = LvArray::tensorOps::AiBi< 3 >( dThermalTrans_dThermalCond, m_dThermalCond_dT[er][esr][ei][0] ); + + real64 const deltaT = m_temp[er][esr][ei] - m_faceTemp[kf]; + stack.energyFlux += thermalTrans * deltaT; + stack.dEnergyFlux_dT += thermalTrans + dThermalTrans_dT * deltaT; + + // Add energyFlux and its derivatives to localFlux and localFluxJacobian + integer const localRowIndexEnergy = numEqn - 1; + stack.localFlux[localRowIndexEnergy] = m_dt * stack.energyFlux; + + stack.localFluxJacobian[localRowIndexEnergy][0] = m_dt * stack.dEnergyFlux_dP; + stack.localFluxJacobian[localRowIndexEnergy][numDof-1] = m_dt * stack.dEnergyFlux_dT; + } ); + + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void complete( localIndex const iconn, + StackVariables & stack ) const + { + Base::complete( iconn, stack, [&] ( localIndex const localRow ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + numEqn - 1], stack.localFlux[numEqn-1] ); + + AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + numEqn - 1, + stack.dofColIndices, + stack.localFluxJacobian[numEqn-1], + numDof ); + } ); + } + +protected: + + /// Views on temperature + ElementViewConst< arrayView1d< real64 const > > const m_temp; + + /// Views on face temperature + arrayView1d< real64 const > const m_faceTemp; + + /// Views on derivatives of fluid mobilities + ElementViewConst< arrayView1d< real64 const > > const m_dMob_dTemp; + + /// Views on derivatives of fluid densities + ElementViewConst< arrayView2d< real64 const > > const m_dDens_dTemp; + + /// Views on enthalpies + ElementViewConst< arrayView2d< real64 const > > const m_enthalpy; + ElementViewConst< arrayView2d< real64 const > > const m_dEnthalpy_dPres; + ElementViewConst< arrayView2d< real64 const > > const m_dEnthalpy_dTemp; + + /// View on thermal conductivity + ElementViewConst< arrayView3d< real64 const > > m_thermalConductivity; + + /// View on derivatives of thermal conductivity w.r.t. temperature + ElementViewConst< arrayView3d< real64 const > > m_dThermalCond_dT; + +}; + +/** + * @class DirichletFluxComputeKernelFactory + */ +class DirichletFluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] solverName name of the solver (to name accessors) + * @param[in] faceManager reference to the face manager + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the boundary stencil wrapper + * @param[in] fluidBase the single phase fluid constitutive model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY > + static void + createAndLaunch( globalIndex const rankOffset, + string const & dofKey, + string const & solverName, + FaceManager const & faceManager, + ElementRegionManager const & elemManager, + BoundaryStencilWrapper const & stencilWrapper, + constitutive::SingleFluidBase & fluidBase, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + constitutiveUpdatePassThru( fluidBase, [&]( auto & fluid ) + { + using FluidType = TYPEOFREF( fluid ); + typename FluidType::KernelWrapper fluidWrapper = fluid.createKernelWrapper(); + + integer constexpr NUM_DOF = 2; + integer constexpr NUM_EQN = 2; + + using kernelType = DirichletFluxComputeKernel< NUM_EQN, NUM_DOF, typename FluidType::KernelWrapper >; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + typename kernelType::SinglePhaseFlowAccessors singlePhaseFlowAccessors( elemManager, solverName ); + typename kernelType::ThermalSinglePhaseFlowAccessors thermalSinglePhaseFlowAccessors( elemManager, solverName ); + typename kernelType::SinglePhaseFluidAccessors singlePhaseFluidAccessors( elemManager, solverName ); + typename kernelType::ThermalSinglePhaseFluidAccessors thermalSinglePhaseFluidAccessors( elemManager, solverName ); + typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + typename kernelType::ThermalConductivityAccessors thermalConductivityAccessors( elemManager, solverName ); + + kernelType kernel( rankOffset, + faceManager, + stencilWrapper, + fluidWrapper, + dofNumberAccessor, + singlePhaseFlowAccessors, + thermalSinglePhaseFlowAccessors, + singlePhaseFluidAccessors, + thermalSinglePhaseFluidAccessors, + permeabilityAccessors, + thermalConductivityAccessors, + dt, + localMatrix, + localRhs ); + + kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } + +}; + +} // namespace thermalSinglePhaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALDIRICHLETFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp similarity index 55% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp index 7bc7c1653a7..89615d7eb3e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp @@ -14,13 +14,13 @@ */ /** - * @file ThermalSinglePhaseFVMKernels.hpp + * @file ThermalFluxComputeKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEFVMKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALFLUXCOMPUTEKERNEL_HPP -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp" #include "constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" @@ -31,16 +31,16 @@ namespace geos namespace thermalSinglePhaseFVMKernels { -/******************************** FaceBasedAssemblyKernel ********************************/ +/******************************** FluxComputeKernel ********************************/ /** - * @class FaceBasedAssemblyKernel + * @class FluxComputeKernel * @tparam NUM_DOF number of degrees of freedom * @tparam STENCILWRAPPER the type of the stencil wrapper * @brief Define the interface for the assembly kernel in charge of flux terms */ template< integer NUM_EQN, integer NUM_DOF, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER > +class FluxComputeKernel : public singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER > { public: @@ -53,7 +53,7 @@ class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyK template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using AbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; + using AbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = AbstractBase::DofNumberAccessor; using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; @@ -66,7 +66,7 @@ class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyK using AbstractBase::m_mob; using AbstractBase::m_dens; - using Base = singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; + using Base = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; using Base::numDof; using Base::numEqn; using Base::maxNumElems; @@ -109,7 +109,7 @@ class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyK * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - FaceBasedAssemblyKernel( globalIndex const rankOffset, + FluxComputeKernel( globalIndex const rankOffset, STENCILWRAPPER const & stencilWrapper, DofNumberAccessor const & dofNumberAccessor, SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, @@ -433,9 +433,9 @@ class FaceBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyK }; /** - * @class FaceBasedAssemblyKernelFactory + * @class FluxComputeKernelFactory */ -class FaceBasedAssemblyKernelFactory +class FluxComputeKernelFactory { public: @@ -470,7 +470,7 @@ class FaceBasedAssemblyKernelFactory elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - using KernelType = FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; + using KernelType = FluxComputeKernel< NUM_EQN, NUM_DOF, STENCILWRAPPER >; typename KernelType::SinglePhaseFlowAccessors flowAccessors( elemManager, solverName ); typename KernelType::ThermalSinglePhaseFlowAccessors thermalFlowAccessors( elemManager, solverName ); typename KernelType::SinglePhaseFluidAccessors fluidAccessors( elemManager, solverName ); @@ -486,364 +486,8 @@ class FaceBasedAssemblyKernelFactory } }; -/******************************** DirichletFaceBasedAssemblyKernel ********************************/ - -/** - * @class DirichFaceBasedAssemblyKernel - * @tparam FLUIDWRAPPER the type of the fluid wrapper - * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms - */ -template< integer NUM_EQN, integer NUM_DOF, typename FLUIDWRAPPER > -class DirichletFaceBasedAssemblyKernel : public singlePhaseFVMKernels::DirichletFaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, FLUIDWRAPPER > -{ -public: - -/** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using AbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; - using DofNumberAccessor = AbstractBase::DofNumberAccessor; - using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; - using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; - using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; - - using AbstractBase::m_dt; - using AbstractBase::m_rankOffset; - using AbstractBase::m_dofNumber; - using AbstractBase::m_ghostRank; - using AbstractBase::m_gravCoef; - using AbstractBase::m_mob; - using AbstractBase::m_pres; - using AbstractBase::m_permeability; - using AbstractBase::m_dPerm_dPres; - - using AbstractBase::m_localMatrix; - using AbstractBase::m_localRhs; - - using Base = singlePhaseFVMKernels::DirichletFaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, FLUIDWRAPPER >; - using Base::numDof; - using Base::numEqn; - using Base::m_stencilWrapper; - using Base::m_seri; - using Base::m_sesri; - using Base::m_sei; - using Base::m_facePres; - using Base::m_faceGravCoef; - - using ThermalSinglePhaseFlowAccessors = - StencilAccessors< fields::flow::temperature, - fields::flow::dMobility_dTemperature >; - - using ThermalSinglePhaseFluidAccessors = - StencilMaterialAccessors< constitutive::SingleFluidBase, - fields::singlefluid::dDensity_dTemperature, - fields::singlefluid::enthalpy, - fields::singlefluid::dEnthalpy_dPressure, - fields::singlefluid::dEnthalpy_dTemperature >; - - using ThermalConductivityAccessors = - StencilMaterialAccessors< constitutive::SinglePhaseThermalConductivityBase, - fields::thermalconductivity::effectiveConductivity, - fields::thermalconductivity::dEffectiveConductivity_dT >; - - /** - * @brief Constructor for the kernel interface - * @param[in] rankOffset the offset of the MPI rank - * @param[in] faceManager the face manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] fluidWrapper reference to the fluid wrapper - * @param[in] dofNumberAccessor the degree of freedom number accessor - * @param[in] singlePhaseFlowAccessors the single phase flow accessor - * @param[in] thermalSinglePhaseFlowAccessors the thermal single phase flow accessor - * @param[in] singlePhaseFluidAccessors the single phase fluid accessor - * @param[in] thermalSinglePhaseFluidAccessors the thermal single phase fluid accessor - * @param[in] permeabilityAccessors the permeability accessor - * @param[in] thermalConductivityAccessors the thermal conductivity accessor - * @param[in] dt the time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - DirichletFaceBasedAssemblyKernel( globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - ThermalSinglePhaseFlowAccessors const & thermalSinglePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - ThermalSinglePhaseFluidAccessors const & thermalSinglePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - ThermalConductivityAccessors const & thermalConductivityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - - : Base( rankOffset, - faceManager, - stencilWrapper, - fluidWrapper, - dofNumberAccessor, - singlePhaseFlowAccessors, - singlePhaseFluidAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs ), - m_temp( thermalSinglePhaseFlowAccessors.get( fields::flow::temperature {} ) ), - m_faceTemp( faceManager.getField< fields::flow::faceTemperature >() ), - m_dMob_dTemp( thermalSinglePhaseFlowAccessors.get( fields::flow::dMobility_dTemperature {} ) ), - m_dDens_dTemp( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::dDensity_dTemperature {} ) ), - m_enthalpy( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::enthalpy {} ) ), - m_dEnthalpy_dPres( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::dEnthalpy_dPressure {} ) ), - m_dEnthalpy_dTemp( thermalSinglePhaseFluidAccessors.get( fields::singlefluid::dEnthalpy_dTemperature {} ) ), - m_thermalConductivity( thermalConductivityAccessors.get( fields::thermalconductivity::effectiveConductivity {} ) ), - m_dThermalCond_dT( thermalConductivityAccessors.get( fields::thermalconductivity::dEffectiveConductivity_dT {} ) ) - {} - - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables : Base::StackVariables - { -public: - - /** - * @brief Constructor for the stack variables - * @param[in] size size of the stencil for this connection - * @param[in] numElems number of elements for this connection - */ - GEOS_HOST_DEVICE - StackVariables( localIndex const size, - localIndex numElems ): - Base::StackVariables( size, - numElems ) - {} - - using Base::StackVariables::localFlux; - using Base::StackVariables::localFluxJacobian; - using Base::StackVariables::dofColIndices; - using Base::StackVariables::transmissibility; - - /// Energy fluxes and derivatives wrt pressure and temperature - real64 energyFlux = 0.0; - real64 dEnergyFlux_dP = 0.0; - real64 dEnergyFlux_dT = 0.0; - }; - - /** - * @brief Compute the local Dirichlet face flux contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes - */ - GEOS_HOST_DEVICE - void computeFlux( localIndex const iconn, - StackVariables & stack ) const - { - Base::computeFlux( iconn, stack, [&] ( localIndex const er, - localIndex const esr, - localIndex const ei, - localIndex const kf, - real64 const & f, - real64 const & dF_dP, - real64 const & mobility_up, - real64 const & dMobility_dP_up ) - { - - // Compute the derivatives of the density wrt temperature - - real64 const dDens_dT = 0.5 * m_dDens_dTemp[er][esr][ei][0]; - - // Compute the derivatives of the phase potential difference wrt temperature - - real64 const dF_dT = -stack.transmissibility * dDens_dT * ( m_gravCoef[er][esr][ei] - m_faceGravCoef[kf] ); - - // Compute the (upwinded) energy flux - - real64 const flux = mobility_up * f; - real64 const enthalpy = m_enthalpy[er][esr][ei][0]; - stack.energyFlux += flux * enthalpy; - - // Compute the derivatives of the (upwinded) energy flux wrt pressure and temperature - - if( f >= 0 ) // the element is upstream - { - real64 const dFlux_dP = mobility_up * dF_dP + dMobility_dP_up * f; - real64 const dFlux_dT = mobility_up * dF_dT + m_dMob_dTemp[er][esr][ei] * f; - - stack.dEnergyFlux_dP += dFlux_dP * enthalpy + flux * m_dEnthalpy_dPres[er][esr][ei][0]; - stack.dEnergyFlux_dT += dFlux_dT * enthalpy + flux * m_dEnthalpy_dTemp[er][esr][ei][0]; - } - else - { - real64 const dFlux_dP = mobility_up * dF_dP; - real64 const dFlux_dT = mobility_up * dF_dT; - - stack.dEnergyFlux_dP += dFlux_dP * enthalpy; - stack.dEnergyFlux_dT += dFlux_dT * enthalpy; - } - - // Contribution of energy conduction through the solid phase - real64 thermalTrans = 0.0; - real64 dThermalTrans_dThermalCond[3]{}; - m_stencilWrapper.computeWeights( iconn, - m_thermalConductivity, - thermalTrans, - dThermalTrans_dThermalCond ); - - real64 const dThermalTrans_dT = LvArray::tensorOps::AiBi< 3 >( dThermalTrans_dThermalCond, m_dThermalCond_dT[er][esr][ei][0] ); - - real64 const deltaT = m_temp[er][esr][ei] - m_faceTemp[kf]; - stack.energyFlux += thermalTrans * deltaT; - stack.dEnergyFlux_dT += thermalTrans + dThermalTrans_dT * deltaT; - - // Add energyFlux and its derivatives to localFlux and localFluxJacobian - integer const localRowIndexEnergy = numEqn - 1; - stack.localFlux[localRowIndexEnergy] = m_dt * stack.energyFlux; - - stack.localFluxJacobian[localRowIndexEnergy][0] = m_dt * stack.dEnergyFlux_dP; - stack.localFluxJacobian[localRowIndexEnergy][numDof-1] = m_dt * stack.dEnergyFlux_dT; - } ); - - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void complete( localIndex const iconn, - StackVariables & stack ) const - { - Base::complete( iconn, stack, [&] ( localIndex const localRow ) - { - RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + numEqn - 1], stack.localFlux[numEqn-1] ); - - AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > - ( localRow + numEqn - 1, - stack.dofColIndices, - stack.localFluxJacobian[numEqn-1], - numDof ); - } ); - } - -protected: - - /// Views on temperature - ElementViewConst< arrayView1d< real64 const > > const m_temp; - - /// Views on face temperature - arrayView1d< real64 const > const m_faceTemp; - - /// Views on derivatives of fluid mobilities - ElementViewConst< arrayView1d< real64 const > > const m_dMob_dTemp; - - /// Views on derivatives of fluid densities - ElementViewConst< arrayView2d< real64 const > > const m_dDens_dTemp; - - /// Views on enthalpies - ElementViewConst< arrayView2d< real64 const > > const m_enthalpy; - ElementViewConst< arrayView2d< real64 const > > const m_dEnthalpy_dPres; - ElementViewConst< arrayView2d< real64 const > > const m_dEnthalpy_dTemp; - - /// View on thermal conductivity - ElementViewConst< arrayView3d< real64 const > > m_thermalConductivity; - - /// View on derivatives of thermal conductivity w.r.t. temperature - ElementViewConst< arrayView3d< real64 const > > m_dThermalCond_dT; - -}; - - -/** - * @class DirichletFaceBasedAssemblyKernelFactory - */ -class DirichletFaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] solverName name of the solver (to name accessors) - * @param[in] faceManager reference to the face manager - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the boundary stencil wrapper - * @param[in] fluidBase the single phase fluid constitutive model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( globalIndex const rankOffset, - string const & dofKey, - string const & solverName, - FaceManager const & faceManager, - ElementRegionManager const & elemManager, - BoundaryStencilWrapper const & stencilWrapper, - constitutive::SingleFluidBase & fluidBase, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - constitutiveUpdatePassThru( fluidBase, [&]( auto & fluid ) - { - using FluidType = TYPEOFREF( fluid ); - typename FluidType::KernelWrapper fluidWrapper = fluid.createKernelWrapper(); - - integer constexpr NUM_DOF = 2; - integer constexpr NUM_EQN = 2; - - using kernelType = DirichletFaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, typename FluidType::KernelWrapper >; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - typename kernelType::SinglePhaseFlowAccessors singlePhaseFlowAccessors( elemManager, solverName ); - typename kernelType::ThermalSinglePhaseFlowAccessors thermalSinglePhaseFlowAccessors( elemManager, solverName ); - typename kernelType::SinglePhaseFluidAccessors singlePhaseFluidAccessors( elemManager, solverName ); - typename kernelType::ThermalSinglePhaseFluidAccessors thermalSinglePhaseFluidAccessors( elemManager, solverName ); - typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); - typename kernelType::ThermalConductivityAccessors thermalConductivityAccessors( elemManager, solverName ); - - kernelType kernel( rankOffset, - faceManager, - stencilWrapper, - fluidWrapper, - dofNumberAccessor, - singlePhaseFlowAccessors, - thermalSinglePhaseFlowAccessors, - singlePhaseFluidAccessors, - thermalSinglePhaseFluidAccessors, - permeabilityAccessors, - thermalConductivityAccessors, - dt, - localMatrix, - localRhs ); - - kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); - } ); - } - -}; - } // namespace thermalSinglePhaseFVMKernels } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALSINGLEPHASEFVMKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index 8993448718d..5befe3e9aa7 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" @@ -31,7 +31,7 @@ namespace singlePhasePoromechanicsConformingFracturesKernels { template< integer NUM_EQN, integer NUM_DOF > -class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper > +class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper > { public: @@ -44,7 +44,7 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using AbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; + using AbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = AbstractBase::DofNumberAccessor; using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; @@ -64,7 +64,7 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse using AbstractBase::m_dens; using AbstractBase::m_dDens_dPres; - using Base = singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; + using Base = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; using Base::numDof; using Base::numEqn; using Base::maxNumElems; diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index c7ee034779b..654ee0b3594 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_SINGLEPHASEPOROMECHANICSEMBEDDEDFRACTURES_HPP -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" @@ -31,7 +31,7 @@ namespace singlePhasePoromechanicsEmbeddedFracturesKernels { template< integer NUM_EQN, integer NUM_DOF > -class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper > +class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper > { public: @@ -44,7 +44,7 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using AbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; + using AbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = AbstractBase::DofNumberAccessor; using SinglePhaseFlowAccessors = AbstractBase::SinglePhaseFlowAccessors; using SinglePhaseFluidAccessors = AbstractBase::SinglePhaseFluidAccessors; @@ -63,7 +63,7 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FaceBasedAsse using AbstractBase::m_dens; using AbstractBase::m_dDens_dPres; - using Base = singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; + using Base = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; using Base::numDof; using Base::numEqn; using Base::maxNumElems; diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp index afbf536027a..e82a918fa09 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp @@ -21,6 +21,7 @@ #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_THERMALSINGLEPHASEPOROMECHANICSCONFORMINGFRACTURES_HPP #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp" namespace geos { @@ -42,7 +43,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsConformingFr template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using SinglePhaseFVMAbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; + using SinglePhaseFVMAbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = SinglePhaseFVMAbstractBase::DofNumberAccessor; using SinglePhaseFlowAccessors = SinglePhaseFVMAbstractBase::SinglePhaseFlowAccessors; using SinglePhaseFluidAccessors = SinglePhaseFVMAbstractBase::SinglePhaseFluidAccessors; @@ -56,7 +57,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsConformingFr using SinglePhaseFVMAbstractBase::m_mob; using SinglePhaseFVMAbstractBase::m_dens; - using SinglePhaseFVMBase = singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; + using SinglePhaseFVMBase = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; using SinglePhaseFVMBase::numDof; using SinglePhaseFVMBase::numEqn; using SinglePhaseFVMBase::maxNumElems; diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp index 12fe7e99a35..1b39b1b44cb 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp @@ -42,7 +42,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsEmbeddedFrac template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using SinglePhaseFVMAbstractBase = singlePhaseFVMKernels::FaceBasedAssemblyKernelBase; + using SinglePhaseFVMAbstractBase = singlePhaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = SinglePhaseFVMAbstractBase::DofNumberAccessor; using SinglePhaseFlowAccessors = SinglePhaseFVMAbstractBase::SinglePhaseFlowAccessors; using SinglePhaseFluidAccessors = SinglePhaseFVMAbstractBase::SinglePhaseFluidAccessors; @@ -56,7 +56,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsEmbeddedFrac using SinglePhaseFVMAbstractBase::m_mob; using SinglePhaseFVMAbstractBase::m_dens; - using SinglePhaseFVMBase = singlePhaseFVMKernels::FaceBasedAssemblyKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; + using SinglePhaseFVMBase = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, SurfaceElementStencilWrapper >; using SinglePhaseFVMBase::numDof; using SinglePhaseFVMBase::numEqn; using SinglePhaseFVMBase::maxNumElems; diff --git a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseMobilityKernel.cpp b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseMobilityKernel.cpp index 60704c53b9f..b48cb9d4cf8 100644 --- a/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseMobilityKernel.cpp +++ b/src/coreComponents/unitTests/fluidFlowTests/testSinglePhaseMobilityKernel.cpp @@ -15,7 +15,7 @@ // Source includes #include "mainInterface/initialization.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" // TPL includes #include From 616724aefc949857a55df7ca2868005f408376ee Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 17:02:32 -0500 Subject: [PATCH 11/47] last things --- .../constitutive/CMakeLists.txt | 1 - .../SinglePhaseThermalConductivityBase.cpp | 1 - .../SinglePhaseThermalConductivityFields.hpp | 49 ----------- .../physicsSolvers/fluidFlow/CMakeLists.txt | 82 ++++++++++--------- .../fluidFlow/SinglePhaseFVM.cpp | 2 +- .../fluidFlow/SinglePhaseProppantBase.cpp | 2 +- .../DirichletFluxComputeKernel.hpp | 11 --- .../kernels/singlePhase/FluxComputeKernel.hpp | 20 ----- .../singlePhase/FluxComputeKernelBase.hpp | 6 -- .../singlePhase/HydrostaticPressureKernel.hpp | 1 - .../singlePhase/SolutionCheckKernel.hpp | 1 - .../singlePhase/SolutionScalingKernel.hpp | 1 - .../ThermalDirichletFluxComputeKernel.hpp | 1 - .../singlePhase/ThermalFluxComputeKernel.hpp | 1 - .../ProppantBaseKernels.hpp} | 0 .../ProppantFluxKernels.cpp} | 4 +- .../ProppantFluxKernels.hpp} | 0 17 files changed, 48 insertions(+), 135 deletions(-) delete mode 100644 src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseProppantBaseKernels.hpp => proppant/ProppantBaseKernels.hpp} (100%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseProppantFluxKernels.cpp => proppant/ProppantFluxKernels.cpp} (99%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/{SinglePhaseProppantFluxKernels.hpp => proppant/ProppantFluxKernels.hpp} (100%) diff --git a/src/coreComponents/constitutive/CMakeLists.txt b/src/coreComponents/constitutive/CMakeLists.txt index 69a953f361a..7f641f6b4dd 100644 --- a/src/coreComponents/constitutive/CMakeLists.txt +++ b/src/coreComponents/constitutive/CMakeLists.txt @@ -171,7 +171,6 @@ set( constitutive_headers thermalConductivity/MultiPhaseVolumeWeightedThermalConductivity.hpp thermalConductivity/SinglePhaseThermalConductivity.hpp thermalConductivity/SinglePhaseThermalConductivityBase.hpp - thermalConductivity/SinglePhaseThermalConductivityFields.hpp thermalConductivity/SinglePhaseThermalConductivitySelector.hpp thermalConductivity/ThermalConductivityFields.hpp ) diff --git a/src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.cpp b/src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.cpp index d4760a4d871..2ee0fa4a908 100644 --- a/src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.cpp +++ b/src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.cpp @@ -19,7 +19,6 @@ #include "SinglePhaseThermalConductivityBase.hpp" #include "ThermalConductivityFields.hpp" -#include "SinglePhaseThermalConductivityFields.hpp" namespace geos { diff --git a/src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp b/src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp deleted file mode 100644 index 267183f85c3..00000000000 --- a/src/coreComponents/constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 SinglePhaseThermalConductivityFields.hpp - */ - -#ifndef GEOS_CONSTITUTIVE_SINGLEPHASE_THERMALCONDUCTIVITY_THERMALCONDUCTIVITYFIELDS_HPP_ -#define GEOS_CONSTITUTIVE_SINGLEPHASE_THERMALCONDUCTIVITY_THERMALCONDUCTIVITYFIELDS_HPP_ - -#include "constitutive/relativePermeability/layouts.hpp" -#include "mesh/MeshFields.hpp" - -namespace geos -{ - -namespace fields -{ - -namespace thermalconductivity -{ - -DECLARE_FIELD( dEffectiveConductivity_dPorosity, - "dEffectiveConductivity_dPorosity", - array3d< real64 >, - 0, - NOPLOT, - NO_WRITE, - "Derivative of effective conductivity with respect to porosity" ); - -} - -} - -} - -#endif // GEOS_CONSTITUTIVE_SINGLEPHASE_THERMALCONDUCTIVITY_THERMALCONDUCTIVITYFIELDS_HPP_ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index e36299701e7..e808dbd9fdb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -1,64 +1,70 @@ # Specify solver headers set( physicsSolvers_headers ${physicsSolvers_headers} + fluidFlow/FlowSolverBase.hpp + fluidFlow/FlowSolverBaseFields.hpp fluidFlow/CompositionalMultiphaseBase.hpp fluidFlow/CompositionalMultiphaseBaseFields.hpp fluidFlow/CompositionalMultiphaseStatistics.hpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp - fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp fluidFlow/CompositionalMultiphaseFVM.hpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp - fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp fluidFlow/CompositionalMultiphaseHybridFVM.hpp - fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp fluidFlow/CompositionalMultiphaseUtilities.hpp fluidFlow/ReactiveCompositionalMultiphaseOBL.hpp fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp - fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp - fluidFlow/FlowSolverBase.hpp - fluidFlow/FlowSolverBaseFields.hpp - fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp - fluidFlow/kernels/StencilWeightsUpdateKernel.hpp - fluidFlow/kernels/singlePhase/SinglePhaseFluxKernelsHelper.hpp - fluidFlow/kernels/HybridFVMHelperKernels.hpp fluidFlow/SourceFluxStatistics.hpp - fluidFlow/proppantTransport/ProppantTransport.hpp - fluidFlow/proppantTransport/ProppantTransportFields.hpp - fluidFlow/proppantTransport/ProppantTransportKernels.hpp fluidFlow/SinglePhaseBase.hpp fluidFlow/SinglePhaseBaseFields.hpp - fluidFlow/kernels/singlePhase/SinglePhaseAccumulationKernels.hpp - fluidFlow/kernels/singlePhase/SinglePhaseMobilityKernel.hpp - fluidFlow/kernels/singlePhase/SinglePhaseSolutionCheckKernel.hpp - fluidFlow/kernels/singlePhase/SinglePhaseSolutionScalingKernel.hpp - fluidFlow/kernels/singlePhase/SinglePhaseResidualNormKernel.hpp - fluidFlow/kernels/singlePhase/SinglePhaseStatisticsKernel.hpp - fluidFlow/kernels/singlePhase/SinglePhaseHydrostaticPressureKernel.hpp fluidFlow/SinglePhaseStatistics.hpp fluidFlow/SinglePhaseFVM.hpp - fluidFlow/kernels/singlePhase/SinglePhaseFVMKernels.hpp fluidFlow/SinglePhaseHybridFVM.hpp - fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp fluidFlow/SinglePhaseProppantBase.hpp - fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp - fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp - fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp - fluidFlow/kernels/singlePhase/StabilizedSinglePhaseFVMKernels.hpp fluidFlow/StencilAccessors.hpp fluidFlow/StencilDataCollection.hpp - fluidFlow/kernels/singlePhase/ThermalSinglePhaseBaseKernels.hpp - fluidFlow/kernels/singlePhase/ThermalSinglePhaseFVMKernels.hpp + fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp + fluidFlow/kernels/StencilWeightsUpdateKernel.hpp + fluidFlow/kernels/HybridFVMHelperKernels.hpp + fluidFlow/kernels/singlePhase/AccumulationKernels.hpp + fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp + fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp + fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp + fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp + fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp + fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp + fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp + fluidFlow/kernels/singlePhase/MobilityKernel.hpp + fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp + fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp + fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp + fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp + fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp + fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp + fluidFlow/kernels/singlePhase/StatisticsKernel.hpp + fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp + fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp + fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp + fluidFlow/kernels/singlePhase/proppant/ProppantBaseKernels.hpp + fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.hpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp + fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp + fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp + fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp fluidFlow/wells/CompositionalMultiphaseWell.hpp fluidFlow/wells/CompositionalMultiphaseWellFields.hpp - fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp fluidFlow/wells/SinglePhaseWell.hpp fluidFlow/wells/SinglePhaseWellFields.hpp - fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp fluidFlow/wells/WellConstants.hpp fluidFlow/wells/WellControls.hpp fluidFlow/wells/WellSolverBase.hpp fluidFlow/wells/WellSolverBaseFields.hpp + fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp + fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp + fluidFlow/proppantTransport/ProppantTransport.hpp + fluidFlow/proppantTransport/ProppantTransportFields.hpp + fluidFlow/proppantTransport/ProppantTransportKernels.hpp PARENT_SCOPE ) # Specify solver sources @@ -67,27 +73,27 @@ set( physicsSolvers_sources fluidFlow/CompositionalMultiphaseBase.cpp fluidFlow/CompositionalMultiphaseFVM.cpp fluidFlow/CompositionalMultiphaseStatistics.cpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp fluidFlow/CompositionalMultiphaseHybridFVM.cpp - fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.cpp fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp fluidFlow/FlowSolverBase.cpp - fluidFlow/proppantTransport/ProppantTransport.cpp - fluidFlow/proppantTransport/ProppantTransportKernels.cpp fluidFlow/SinglePhaseBase.cpp fluidFlow/SinglePhaseStatistics.cpp fluidFlow/SinglePhaseFVM.cpp fluidFlow/SinglePhaseHybridFVM.cpp fluidFlow/SinglePhaseProppantBase.cpp - fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp fluidFlow/SourceFluxStatistics.cpp fluidFlow/StencilDataCollection.cpp + fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.cpp + fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp + fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.cpp fluidFlow/wells/CompositionalMultiphaseWell.cpp fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.cpp fluidFlow/wells/SinglePhaseWell.cpp fluidFlow/wells/kernels/SinglePhaseWellKernels.cpp fluidFlow/wells/WellControls.cpp fluidFlow/wells/WellSolverBase.cpp + fluidFlow/proppantTransport/ProppantTransport.cpp + fluidFlow/proppantTransport/ProppantTransportKernels.cpp PARENT_SCOPE ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index 5bff8f4cfcf..75a397a82bc 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -41,8 +41,8 @@ #include "physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp" #include "physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp index 0e936987446..9129d290d2c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseProppantBase.cpp @@ -28,7 +28,7 @@ #include "constitutive/solid/ProppantSolid.hpp" #include "constitutive/solid/porosity/ProppantPorosity.hpp" #include "physicsSolvers/fluidFlow/proppantTransport/ProppantTransportFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantBaseKernels.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp index 16bb9e89848..43f4238bb4b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp @@ -24,21 +24,10 @@ #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" -#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" -#include "constitutive/fluid/singlefluid/SlurryFluidBase.hpp" -#include "constitutive/fluid/singlefluid/SlurryFluidFields.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" #include "finiteVolume/BoundaryStencil.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "linearAlgebra/interfaces/InterfaceTypes.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" #include "codingUtilities/Utilities.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp index 2b87d98b83d..9c83bee7e96 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp @@ -22,26 +22,6 @@ #include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp" -#include "common/DataLayouts.hpp" -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" -#include "constitutive/fluid/singlefluid/SingleFluidFields.hpp" -#include "constitutive/fluid/singlefluid/SlurryFluidBase.hpp" -#include "constitutive/fluid/singlefluid/SlurryFluidFields.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/BoundaryStencil.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "linearAlgebra/interfaces/InterfaceTypes.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" -#include "codingUtilities/Utilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp index 0c9f0544413..4c4d9853fbf 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp @@ -29,17 +29,11 @@ #include "constitutive/fluid/singlefluid/SlurryFluidFields.hpp" #include "constitutive/permeability/PermeabilityBase.hpp" #include "constitutive/permeability/PermeabilityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/BoundaryStencil.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" #include "linearAlgebra/interfaces/InterfaceTypes.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SinglePhaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/MobilityKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" -#include "codingUtilities/Utilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp index a988df8fd38..fe08f309833 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp @@ -23,7 +23,6 @@ #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp" -#include "codingUtilities/Utilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp index 2ed64c55344..29a22e422f7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp @@ -22,7 +22,6 @@ #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "codingUtilities/Utilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp index a0b1e3c84d4..5994d972e3b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp @@ -22,7 +22,6 @@ #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "codingUtilities/Utilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp index ad8751eebd1..f59dc9d7e35 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp @@ -24,7 +24,6 @@ #include "constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" -#include "constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp index 89615d7eb3e..911b7ac1c45 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp @@ -24,7 +24,6 @@ #include "constitutive/thermalConductivity/SinglePhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" -#include "constitutive/thermalConductivity/SinglePhaseThermalConductivityFields.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantBaseKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantBaseKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.cpp similarity index 99% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.cpp index f1fa159957e..22dec62d10f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.cpp @@ -14,10 +14,10 @@ */ /** - * @file SinglePhaseProppantFluxKernels.cpp + * @file ProppantFluxKernels.cpp */ -#include "SinglePhaseProppantFluxKernels.hpp" +#include "ProppantFluxKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SinglePhaseProppantFluxKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.hpp From 9f133ea210745a7627e1c511943858ece4a63779 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 17:24:37 -0500 Subject: [PATCH 12/47] remove --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 2 - .../fluidFlow/SinglePhaseBase.cpp | 16 ++++-- .../kernels/singlePhase/FluidUpdateKernel.hpp | 55 ------------------- .../SolidInternalEnergyUpdateKernel.hpp | 54 ------------------ .../fluidFlow/wells/SinglePhaseWell.cpp | 9 ++- 5 files changed, 19 insertions(+), 117 deletions(-) delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index e808dbd9fdb..d160e80bd21 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -26,7 +26,6 @@ set( physicsSolvers_headers fluidFlow/kernels/singlePhase/AccumulationKernels.hpp fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp - fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp @@ -34,7 +33,6 @@ set( physicsSolvers_headers fluidFlow/kernels/singlePhase/MobilityKernel.hpp fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp - fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index ce476dd00ea..f73a7b01274 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -47,8 +47,6 @@ #include "physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp" namespace geos @@ -265,7 +263,14 @@ void SinglePhaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const constitutiveUpdatePassThru( fluid, [&]( auto & castedFluid ) { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - singlePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); + + forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) + { + fluidWrapper.update( k, q, pres[k], temp[k] ); + } + } ); } ); } @@ -332,7 +337,10 @@ void SinglePhaseBase::updateSolidInternalEnergyModel( ObjectManagerBase & dataGr SolidInternalEnergy::KernelWrapper solidInternalEnergyWrapper = solidInternalEnergy.createKernelUpdates(); - thermalSinglePhaseBaseKernels::SolidInternalEnergyUpdateKernel::launch< parallelDevicePolicy<> >( dataGroup.size(), solidInternalEnergyWrapper, temperature ); + forAll< parallelDevicePolicy<> >( dataGroup.size(), [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + solidInternalEnergyWrapper.update( k, temperature[k] ); + } ); } void SinglePhaseBase::updateThermalConductivity( ElementSubRegionBase & subRegion ) const diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp deleted file mode 100644 index 9ee7550c9b7..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 FluidUpdateKernel.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP - -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" - -namespace geos -{ - -namespace singlePhaseBaseKernels -{ - -/******************************** FluidUpdateKernel ********************************/ - -struct FluidUpdateKernel -{ - template< typename FLUID_WRAPPER > - static void launch( FLUID_WRAPPER const & fluidWrapper, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & temp ) - { - forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) - { - fluidWrapper.update( k, q, pres[k], temp[k] ); - } - } ); - } -}; - -} // namespace singlePhaseBaseKernels - -} // namespace geos - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp deleted file mode 100644 index 4ed3658e569..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 SolidInternalEnergyUpdateKernel.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP - -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" - -namespace geos -{ - -namespace thermalSinglePhaseBaseKernels -{ - -/******************************** SolidInternalEnergyUpdateKernel ********************************/ - -struct SolidInternalEnergyUpdateKernel -{ - - template< typename POLICY, typename SOLID_INTERNAL_ENERGY_WRAPPER > - static void - launch( localIndex const size, - SOLID_INTERNAL_ENERGY_WRAPPER const & solidInternalEnergyWrapper, - arrayView1d< real64 const > const & temp ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - solidInternalEnergyWrapper.update( k, temp[k] ); - } ); - } -}; - -} // namespace thermalSinglePhaseBaseKernels - -} // namespace geos - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index ebcc83b1172..1a756621bed 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -36,7 +36,6 @@ #include "physicsSolvers/fluidFlow/wells/SinglePhaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp" namespace geos { @@ -307,7 +306,13 @@ void SinglePhaseWell::updateFluidModel( WellElementSubRegion & subRegion ) const constitutiveUpdatePassThru( fluid, [&]( auto & castedFluid ) { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - singlePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); + forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) + { + fluidWrapper.update( k, q, pres[k], temp[k] ); + } + } ); } ); } From 93f76ef85967466fec098a280c9be8cc97ab3186 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 17:30:24 -0500 Subject: [PATCH 13/47] missing file --- .../kernels/StencilWeightsUpdateKernel.hpp | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp new file mode 100644 index 00000000000..d61b9d379dd --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/StencilWeightsUpdateKernel.hpp @@ -0,0 +1,79 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 StencilWeightsUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_STENCILWEIGHTSUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STENCILWEIGHTSUPDATEKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "mesh/ElementRegionManager.hpp" + +namespace geos +{ + +namespace flowSolverBaseKernels +{ + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +/** + * @brief + * + * @tparam STENCILWRAPPER + */ +template< typename STENCILWRAPPER > +struct stencilWeightsUpdateKernel +{ + /** + * @brief + * + * @param stencilWrappper + * @param hydraulicAperture + */ + inline static void prepareStencilWeights( STENCILWRAPPER & stencilWrapper, + ElementViewConst< arrayView1d< real64 const > > const hydraulicAperture ) + { + forAll< parallelDevicePolicy<> >( stencilWrapper.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + stencilWrapper.removeHydraulicApertureContribution( iconn, hydraulicAperture ); + } ); + } + + /** + * @brief + * + * @param stencilWrappper + * @param hydraulicAperture + */ + inline static void updateStencilWeights( STENCILWRAPPER & stencilWrapper, + ElementViewConst< arrayView1d< real64 const > > const hydraulicAperture ) + { + forAll< parallelDevicePolicy<> >( stencilWrapper.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + stencilWrapper.addHydraulicApertureContribution( iconn, hydraulicAperture ); + } ); + } +}; + +} // namespace flowSolverBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_STENCILWEIGHTSUPDATEKERNEL_HPP From 3cc1446e780a36fb12c3a94f89fa2c0910e157ff Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 17:37:26 -0500 Subject: [PATCH 14/47] code style --- .../fluidFlow/SinglePhaseBase.cpp | 2 +- .../fluidFlow/SinglePhaseFVM.cpp | 98 +++++++++---------- .../MinPoreVolumeMaxPorosityKernel.hpp | 2 +- .../DirichletFluxComputeKernel.hpp | 24 ++--- .../kernels/singlePhase/FluxComputeKernel.hpp | 30 +++--- .../singlePhase/FluxComputeKernelBase.hpp | 14 +-- .../singlePhase/ResidualNormKernel.hpp | 20 ++-- .../StabilizedFluxComputeKernel.hpp | 20 ++-- .../ThermalAccumulationKernels.hpp | 24 ++--- .../ThermalDirichletFluxComputeKernel.hpp | 26 ++--- .../singlePhase/ThermalFluxComputeKernel.hpp | 22 ++--- 11 files changed, 141 insertions(+), 141 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index f73a7b01274..36cd14c60c8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -263,7 +263,7 @@ void SinglePhaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const constitutiveUpdatePassThru( fluid, [&]( auto & castedFluid ) { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - + forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) { for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index 75a397a82bc..f99b68987d7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -329,25 +329,25 @@ void SinglePhaseFVM<>::assembleFluxTerms( real64 const dt, { thermalSinglePhaseFVMKernels:: FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), - dofKey, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + dofKey, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); } else { singlePhaseFVMKernels:: FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), - dofKey, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + dofKey, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); } @@ -382,13 +382,13 @@ void SinglePhaseFVM< SinglePhaseBase >::assembleStabilizedFluxTerms( real64 cons // No thermal support yet stabilizedSinglePhaseFVMKernels::FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), - dofKey, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + dofKey, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); } ); } ); @@ -491,25 +491,25 @@ void SinglePhaseFVM< BASE >::assembleEDFMFluxTerms( real64 const GEOS_UNUSED_PAR { thermalSinglePhaseFVMKernels:: FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), - dofKey, - this->getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + dofKey, + this->getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); } else { singlePhaseFVMKernels:: FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), - dofKey, - this->getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + dofKey, + this->getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); } } ); @@ -580,25 +580,25 @@ void SinglePhaseFVM< BASE >::assembleHydrofracFluxTerms( real64 const GEOS_UNUSE { thermalSinglePhaseFVMKernels:: FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), - dofKey, - this->getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + dofKey, + this->getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); } else { singlePhaseFVMKernels:: FluxComputeKernelFactory::createAndLaunch< parallelDevicePolicy<> >( dofManager.rankOffset(), - dofKey, - this->getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + dofKey, + this->getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); } } ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp index 36f286b707c..6d930e5d592 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/MinPoreVolumeMaxPorosityKernel.hpp @@ -107,4 +107,4 @@ struct MinPoreVolumeMaxPorosityKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_MINPOREVOLUMEMAXPOROSITYKERNEL_HPP \ No newline at end of file +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_MINPOREVOLUMEMAXPOROSITYKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp index 43f4238bb4b..e2a33419262 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp @@ -45,7 +45,7 @@ namespace singlePhaseFVMKernels */ template< integer NUM_EQN, integer NUM_DOF, typename FLUIDWRAPPER > class DirichletFluxComputeKernel : public FluxComputeKernel< NUM_EQN, NUM_DOF, - BoundaryStencilWrapper > + BoundaryStencilWrapper > { public: @@ -70,7 +70,7 @@ class DirichletFluxComputeKernel : public FluxComputeKernel< NUM_EQN, NUM_DOF, using AbstractBase::m_localRhs; using Base = singlePhaseFVMKernels::FluxComputeKernel< NUM_EQN, NUM_DOF, - BoundaryStencilWrapper >; + BoundaryStencilWrapper >; using Base::numDof; using Base::numEqn; using Base::m_stencilWrapper; @@ -93,16 +93,16 @@ class DirichletFluxComputeKernel : public FluxComputeKernel< NUM_EQN, NUM_DOF, * @param[inout] localRhs the local right-hand side vector */ DirichletFluxComputeKernel( globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : Base( rankOffset, stencilWrapper, dofNumberAccessor, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp index 9c83bee7e96..8083ad10746 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp @@ -68,22 +68,22 @@ class FluxComputeKernel : public FluxComputeKernelBase * @param[inout] localRhs the local right-hand side vector */ FluxComputeKernel( globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : FluxComputeKernelBase( rankOffset, - dofNumberAccessor, - singlePhaseFlowAccessors, - singlePhaseFluidAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs ), + dofNumberAccessor, + singlePhaseFlowAccessors, + singlePhaseFluidAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs ), m_stencilWrapper( stencilWrapper ), m_seri( stencilWrapper.getElementRegionIndices() ), m_sesri( stencilWrapper.getElementSubRegionIndices() ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp index 4c4d9853fbf..5a3896fdd79 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp @@ -104,13 +104,13 @@ class FluxComputeKernelBase * @param[inout] localRhs the local right-hand side vector */ FluxComputeKernelBase( globalIndex const rankOffset, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : m_rankOffset( rankOffset ), m_dt( dt ), m_dofNumber( dofNumberAccessor.toNestedViewConst() ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp index 7293104cf2b..e5f07d5d20a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp @@ -44,11 +44,11 @@ class IsothermalResidualNormKernel : public solverBaseKernels::ResidualNormKerne using Base::m_dofNumber; IsothermalResidualNormKernel( globalIndex const rankOffset, - arrayView1d< real64 const > const & localResidual, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< localIndex const > const & ghostRank, - ElementSubRegionBase const & subRegion, - real64 const minNormalizer ) + arrayView1d< real64 const > const & localResidual, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< localIndex const > const & ghostRank, + ElementSubRegionBase const & subRegion, + real64 const minNormalizer ) : Base( rankOffset, localResidual, dofNumber, @@ -100,11 +100,11 @@ class ThermalResidualNormKernel : public solverBaseKernels::ResidualNormKernelBa using Base::m_dofNumber; ThermalResidualNormKernel( globalIndex const rankOffset, - arrayView1d< real64 const > const & localResidual, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< localIndex const > const & ghostRank, - ElementSubRegionBase const & subRegion, - real64 const minNormalizer ) + arrayView1d< real64 const > const & localResidual, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< localIndex const > const & ghostRank, + ElementSubRegionBase const & subRegion, + real64 const minNormalizer ) : Base( rankOffset, localResidual, dofNumber, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp index c1e1909e00b..88d4cc4ce73 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp @@ -92,16 +92,16 @@ class FluxComputeKernel : public singlePhaseFVMKernels::FluxComputeKernel< NUM_E * @param[inout] localRhs the local right-hand side vector */ FluxComputeKernel( globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - StabSinglePhaseFlowAccessors const & stabSinglePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - StabSinglePhaseFluidAccessors const & stabSinglePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + StabSinglePhaseFlowAccessors const & stabSinglePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + StabSinglePhaseFluidAccessors const & stabSinglePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : Base( rankOffset, stencilWrapper, dofNumberAccessor, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp index 553465d3066..8004ce4d973 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp @@ -66,12 +66,12 @@ class AccumulationKernel : public singlePhaseBaseKernels::AccumulationKernel< SU * @param[inout] localRhs the local right-hand side vector */ AccumulationKernel( globalIndex const rankOffset, - string const dofKey, - SUBREGION_TYPE const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + string const dofKey, + SUBREGION_TYPE const & subRegion, + constitutive::SingleFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : Base( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ), m_dDensity_dTemp( fluid.dDensity_dTemperature() ), m_dPoro_dTemp( solid.getDporosity_dTemperature() ), @@ -250,12 +250,12 @@ class SurfaceElementAccumulationKernel : public AccumulationKernel< SurfaceEleme * @param[inout] localRhs the local right-hand side vector */ SurfaceElementAccumulationKernel( globalIndex const rankOffset, - string const dofKey, - SurfaceElementSubRegion const & subRegion, - constitutive::SingleFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + string const dofKey, + SurfaceElementSubRegion const & subRegion, + constitutive::SingleFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : Base( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ), m_creationMass( subRegion.getField< fields::flow::massCreated >() ) {} diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp index f59dc9d7e35..8e6bc1ba8fe 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalDirichletFluxComputeKernel.hpp @@ -115,19 +115,19 @@ class DirichletFluxComputeKernel : public singlePhaseFVMKernels::DirichletFluxCo * @param[inout] localRhs the local right-hand side vector */ DirichletFluxComputeKernel( globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - ThermalSinglePhaseFlowAccessors const & thermalSinglePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - ThermalSinglePhaseFluidAccessors const & thermalSinglePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - ThermalConductivityAccessors const & thermalConductivityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + ThermalSinglePhaseFlowAccessors const & thermalSinglePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + ThermalSinglePhaseFluidAccessors const & thermalSinglePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + ThermalConductivityAccessors const & thermalConductivityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : Base( rankOffset, faceManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp index 911b7ac1c45..cba7c440e09 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp @@ -109,17 +109,17 @@ class FluxComputeKernel : public singlePhaseFVMKernels::FluxComputeKernel< NUM_E * @param[inout] localRhs the local right-hand side vector */ FluxComputeKernel( globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, - ThermalSinglePhaseFlowAccessors const & thermalSinglePhaseFlowAccessors, - SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, - ThermalSinglePhaseFluidAccessors const & thermalSinglePhaseFluidAccessors, - PermeabilityAccessors const & permeabilityAccessors, - ThermalConductivityAccessors const & thermalConductivityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + SinglePhaseFlowAccessors const & singlePhaseFlowAccessors, + ThermalSinglePhaseFlowAccessors const & thermalSinglePhaseFlowAccessors, + SinglePhaseFluidAccessors const & singlePhaseFluidAccessors, + ThermalSinglePhaseFluidAccessors const & thermalSinglePhaseFluidAccessors, + PermeabilityAccessors const & permeabilityAccessors, + ThermalConductivityAccessors const & thermalConductivityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : Base( rankOffset, stencilWrapper, dofNumberAccessor, From 3e6c23813d0013a67c7ccbb706e3191cc03f77d6 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 17:44:28 -0500 Subject: [PATCH 15/47] unused --- src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp index f99b68987d7..7ecdb2d47db 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseFVM.cpp @@ -152,9 +152,6 @@ real64 SinglePhaseFVM< BASE >::calculateResidualNorm( real64 const & GEOS_UNUSED real64 subRegionResidualNorm[numNorm]{}; real64 subRegionResidualNormalizer[numNorm]{}; - string const & fluidName = subRegion.template getReference< string >( BASE::viewKeyStruct::fluidNamesString() ); - SingleFluidBase const & fluid = SolverBase::getConstitutiveModel< SingleFluidBase >( subRegion, fluidName ); - // step 1: compute the norm in the subRegion if( m_isThermal ) From 8527f35686236963df848d4e665d0ec13c39e3f2 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 26 Sep 2024 17:58:11 -0500 Subject: [PATCH 16/47] unused --- .../fluidFlow/kernels/singlePhase/AccumulationKernels.hpp | 1 + .../fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp index 922d94afd29..6db441298fe 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp @@ -347,6 +347,7 @@ class AccumulationKernelFactory } else { + GEOS_UNUSED_VAR( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); GEOS_ERROR( "Unsupported subregion type: " << typeid(SUBREGION_TYPE).name() ); } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp index 8004ce4d973..c912c8a1e63 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp @@ -324,6 +324,7 @@ class AccumulationKernelFactory } else { + GEOS_UNUSED_VAR( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); GEOS_ERROR( "Unsupported subregion type: " << typeid(SUBREGION_TYPE).name() ); } } From 2ba3f8eaa6d00c81275ad35f12e783d4d67796b5 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 27 Sep 2024 14:12:55 -0500 Subject: [PATCH 17/47] cuda build --- .../physicsSolvers/fluidFlow/FlowSolverBase.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp index bfe3fd5ef60..4262336b0bc 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp @@ -165,6 +165,14 @@ class FlowSolverBase : public SolverBase void enableLaggingFractureStencilWeightsUpdate(){ m_isLaggingFractureStencilWeightsUpdate = 1; }; + real64 sumAquiferFluxes( BoundaryStencil const & stencil, + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & presOld, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + real64 const & timeAtBeginningOfStep, + real64 const & dt ); + protected: /** @@ -201,14 +209,6 @@ class FlowSolverBase : public SolverBase virtual void setConstitutiveNamesCallSuper( ElementSubRegionBase & subRegion ) const override; - real64 sumAquiferFluxes( BoundaryStencil const & stencil, - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & presOld, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - real64 const & timeAtBeginningOfStep, - real64 const & dt ); - /// the number of Degrees of Freedom per cell integer m_numDofPerCell; From 4e9ffab5ddfb9bc5de2756595949376382cf53d1 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 27 Sep 2024 14:57:46 -0500 Subject: [PATCH 18/47] try this --- .../physicsSolvers/fluidFlow/SinglePhaseBase.cpp | 8 +------- .../physicsSolvers/fluidFlow/SinglePhaseBase.hpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index 36cd14c60c8..aaf577faf64 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -264,13 +264,7 @@ void SinglePhaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) - { - fluidWrapper.update( k, q, pres[k], temp[k] ); - } - } ); + updateFluid( fluidWrapper, pres, temp ); } ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp index 72d7d3e6614..34c94282a1a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp @@ -298,6 +298,20 @@ class SinglePhaseBase : public FlowSolverBase virtual void updateFluidModel( ObjectManagerBase & dataGroup ) const; + template< typename FLUID_WRAPPER > + void updateFluid( FLUID_WRAPPER const & fluidWrapper, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & temp ) const + { + forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) + { + fluidWrapper.update( k, q, pres[k], temp[k] ); + } + } ); + } + /** * @brief Function to update fluid mass * @param subRegion subregion that contains the fields From e4edeeb1287b29dbb907d81b38a74cd8349f9c3e Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 27 Sep 2024 15:39:37 -0500 Subject: [PATCH 19/47] revert to avoid cuda errors --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 2 + .../fluidFlow/SinglePhaseBase.cpp | 10 ++-- .../fluidFlow/SinglePhaseBase.hpp | 14 ----- .../kernels/singlePhase/FluidUpdateKernel.hpp | 55 +++++++++++++++++++ .../SolidInternalEnergyUpdateKernel.hpp | 54 ++++++++++++++++++ .../fluidFlow/wells/SinglePhaseWell.cpp | 9 +-- 6 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index d160e80bd21..e808dbd9fdb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -26,6 +26,7 @@ set( physicsSolvers_headers fluidFlow/kernels/singlePhase/AccumulationKernels.hpp fluidFlow/kernels/singlePhase/AquiferBCKernel.hpp fluidFlow/kernels/singlePhase/DirichletFluxComputeKernel.hpp + fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp fluidFlow/kernels/singlePhase/FluxComputeKernel.hpp fluidFlow/kernels/singlePhase/FluxComputeKernelBase.hpp fluidFlow/kernels/singlePhase/FluxKernelsHelper.hpp @@ -33,6 +34,7 @@ set( physicsSolvers_headers fluidFlow/kernels/singlePhase/MobilityKernel.hpp fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp fluidFlow/kernels/singlePhase/SinglePhaseHybridFVMKernels.hpp + fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp fluidFlow/kernels/singlePhase/StabilizedFluxComputeKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index aaf577faf64..ce476dd00ea 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -47,6 +47,8 @@ #include "physicsSolvers/fluidFlow/kernels/singlePhase/SolutionScalingKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/StatisticsKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/HydrostaticPressureKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp" namespace geos @@ -263,8 +265,7 @@ void SinglePhaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const constitutiveUpdatePassThru( fluid, [&]( auto & castedFluid ) { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - - updateFluid( fluidWrapper, pres, temp ); + singlePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); } ); } @@ -331,10 +332,7 @@ void SinglePhaseBase::updateSolidInternalEnergyModel( ObjectManagerBase & dataGr SolidInternalEnergy::KernelWrapper solidInternalEnergyWrapper = solidInternalEnergy.createKernelUpdates(); - forAll< parallelDevicePolicy<> >( dataGroup.size(), [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - solidInternalEnergyWrapper.update( k, temperature[k] ); - } ); + thermalSinglePhaseBaseKernels::SolidInternalEnergyUpdateKernel::launch< parallelDevicePolicy<> >( dataGroup.size(), solidInternalEnergyWrapper, temperature ); } void SinglePhaseBase::updateThermalConductivity( ElementSubRegionBase & subRegion ) const diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp index 34c94282a1a..72d7d3e6614 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.hpp @@ -298,20 +298,6 @@ class SinglePhaseBase : public FlowSolverBase virtual void updateFluidModel( ObjectManagerBase & dataGroup ) const; - template< typename FLUID_WRAPPER > - void updateFluid( FLUID_WRAPPER const & fluidWrapper, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & temp ) const - { - forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) - { - fluidWrapper.update( k, q, pres[k], temp[k] ); - } - } ); - } - /** * @brief Function to update fluid mass * @param subRegion subregion that contains the fields diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp new file mode 100644 index 00000000000..9ee7550c9b7 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp @@ -0,0 +1,55 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluidUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + +namespace geos +{ + +namespace singlePhaseBaseKernels +{ + +/******************************** FluidUpdateKernel ********************************/ + +struct FluidUpdateKernel +{ + template< typename FLUID_WRAPPER > + static void launch( FLUID_WRAPPER const & fluidWrapper, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & temp ) + { + forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) + { + fluidWrapper.update( k, q, pres[k], temp[k] ); + } + } ); + } +}; + +} // namespace singlePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_FLUIDUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp new file mode 100644 index 00000000000..4ed3658e569 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/SolidInternalEnergyUpdateKernel.hpp @@ -0,0 +1,54 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SolidInternalEnergyUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + +namespace geos +{ + +namespace thermalSinglePhaseBaseKernels +{ + +/******************************** SolidInternalEnergyUpdateKernel ********************************/ + +struct SolidInternalEnergyUpdateKernel +{ + + template< typename POLICY, typename SOLID_INTERNAL_ENERGY_WRAPPER > + static void + launch( localIndex const size, + SOLID_INTERNAL_ENERGY_WRAPPER const & solidInternalEnergyWrapper, + arrayView1d< real64 const > const & temp ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + solidInternalEnergyWrapper.update( k, temp[k] ); + } ); + } +}; + +} // namespace thermalSinglePhaseBaseKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SOLIDINTERNALENERGYUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index 1a756621bed..ebcc83b1172 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -36,6 +36,7 @@ #include "physicsSolvers/fluidFlow/wells/SinglePhaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp" namespace geos { @@ -306,13 +307,7 @@ void SinglePhaseWell::updateFluidModel( WellElementSubRegion & subRegion ) const constitutiveUpdatePassThru( fluid, [&]( auto & castedFluid ) { typename TYPEOFREF( castedFluid ) ::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper(); - forAll< parallelDevicePolicy<> >( fluidWrapper.numElems(), [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) - { - fluidWrapper.update( k, q, pres[k], temp[k] ); - } - } ); + singlePhaseBaseKernels::FluidUpdateKernel::launch( fluidWrapper, pres, temp ); } ); } From 7255e9d6f8ab68cf880d1699f0afbaf3b002718e Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 27 Sep 2024 19:00:48 -0500 Subject: [PATCH 20/47] first pass for compositional --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 5 + .../fluidFlow/CompositionalMultiphaseFVM.cpp | 6 +- .../CompositionalMultiphaseHybridFVM.cpp | 5 +- .../CompositionalMultiphaseStatistics.cpp | 1 + .../CapillaryPressureUpdateKernel.hpp | 73 + ...ompositionalMultiphaseHybridFVMKernels.hpp | 1 + .../GlobalComponentFractionKernel.hpp | 144 + .../HydrostaticPressureKernel.hpp | 365 +++ ...rmalCompositionalMultiphaseBaseKernels.hpp | 2507 ++--------------- ...ermalCompositionalMultiphaseFVMKernels.hpp | 206 -- .../compositional/KernelLaunchSelector.hpp | 111 + .../compositional/PhaseMobilityKernel.hpp | 241 ++ .../PhaseVolumeFractionKernel.hpp | 256 ++ .../compositional/PropertyKernelBase.hpp | 103 + .../RelativePermeabilityUpdateKernel.hpp | 85 + .../compositional/ResidualNormKernel.hpp | 204 ++ ...ingAndCheckingSystemSolutionKernelBase.hpp | 192 ++ .../compositional/SolutionCheckKernel.hpp | 350 +++ .../compositional/SolutionScalingKernel.hpp | 386 +++ .../compositional/StatisticsKernel.hpp | 203 ++ ...rmalCompositionalMultiphaseBaseKernels.hpp | 30 +- .../wells/CompositionalMultiphaseWell.cpp | 3 +- .../CompositionalMultiphaseWellKernels.hpp | 15 +- 23 files changed, 3041 insertions(+), 2451 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 613f662eef6..2fa3871cb21 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -44,6 +44,11 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" // TODO this should not be here #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 3afb697fd11..1afb7d70e19 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -40,6 +40,8 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" namespace geos { @@ -483,7 +485,7 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d auto const subRegionData = m_isThermal ? thermalCompositionalMultiphaseBaseKernels:: - ScalingForSystemSolutionKernelFactory:: + SolutionScalingKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, m_maxAbsolutePresChange, m_maxRelativeTempChange, @@ -495,7 +497,7 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d subRegion, localSolution ) : isothermalCompositionalMultiphaseBaseKernels:: - ScalingForSystemSolutionKernelFactory:: + SolutionScalingKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, m_maxAbsolutePresChange, m_maxCompFracChange, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index d085adaf4f2..b8b1c8090ca 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -32,6 +32,9 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp" /** * @namespace the geos namespace that encapsulates the majority of the code @@ -447,7 +450,7 @@ real64 CompositionalMultiphaseHybridFVM::scalingForSystemSolution( DomainPartiti { auto const subRegionData = isothermalCompositionalMultiphaseBaseKernels:: - ScalingForSystemSolutionKernelFactory:: + SolutionScalingKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, m_maxAbsolutePresChange, m_maxCompFracChange, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp index 2cd57096c5f..0aaea3ab9fb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp @@ -32,6 +32,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp new file mode 100644 index 00000000000..7842c859189 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp @@ -0,0 +1,73 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 CapillaryPressureUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CAPILLARYPRESSUREUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CAPILLARYPRESSUREUPDATEKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** CapillaryPressureUpdateKernel ********************************/ + +struct CapillaryPressureUpdateKernel +{ + template< typename POLICY, typename CAPPRES_WRAPPER > + static void + launch( localIndex const size, + CAPPRES_WRAPPER const & capPresWrapper, + arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < capPresWrapper.numGauss(); ++q ) + { + capPresWrapper.update( k, q, phaseVolFrac[k] ); + } + } ); + } + + template< typename POLICY, typename CAPPRES_WRAPPER > + static void + launch( SortedArrayView< localIndex const > const & targetSet, + CAPPRES_WRAPPER const & capPresWrapper, + arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) + { + forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) + { + localIndex const k = targetSet[a]; + for( localIndex q = 0; q < capPresWrapper.numGauss(); ++q ) + { + capPresWrapper.update( k, q, phaseVolFrac[k] ); + } + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CAPILLARYPRESSUREUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp index 89996316dac..fb236b0fa4f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp @@ -33,6 +33,7 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp new file mode 100644 index 00000000000..e8d53a625ba --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp @@ -0,0 +1,144 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 GlobalComponentFractionKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** GlobalComponentFractionKernel ********************************/ + +/** + * @class GlobalComponentFractionKernel + * @tparam NUM_COMP number of fluid components + * @brief Define the interface for the update kernel in charge of computing the phase volume fractions + */ +template< integer NUM_COMP > +class GlobalComponentFractionKernel : public PropertyKernelBase< NUM_COMP > +{ +public: + + using Base = PropertyKernelBase< NUM_COMP >; + using Base::numComp; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + GlobalComponentFractionKernel( ObjectManagerBase & subRegion ) + : Base(), + m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), + m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ), + m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ) + {} + + /** + * @brief Compute the phase volume fractions in an element + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[in] phaseVolFractionKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void compute( localIndex const ei, + FUNC && compFractionKernelOp = NoOpFunc{} ) const + { + arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; + arraySlice1d< real64, compflow::USD_COMP - 1 > const compFrac = m_compFrac[ei]; + arraySlice2d< real64, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; + + real64 totalDensity = 0.0; + + for( integer ic = 0; ic < numComp; ++ic ) + { + totalDensity += compDens[ic]; + } + + real64 const totalDensityInv = 1.0 / totalDensity; + + for( integer ic = 0; ic < numComp; ++ic ) + { + compFrac[ic] = compDens[ic] * totalDensityInv; + for( integer jc = 0; jc < numComp; ++jc ) + { + dCompFrac_dCompDens[ic][jc] = -compFrac[ic] * totalDensityInv; + } + dCompFrac_dCompDens[ic][ic] += totalDensityInv; + } + + compFractionKernelOp( compFrac, dCompFrac_dCompDens ); + } + +protected: + + // inputs + + // Views on component densities + arrayView2d< real64 const, compflow::USD_COMP > m_compDens; + + // outputs + + // Views on component fraction + arrayView2d< real64, compflow::USD_COMP > m_compFrac; + arrayView3d< real64, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; + +}; + +/** + * @class GlobalComponentFractionKernelFactory + */ +class GlobalComponentFractionKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComp, + ObjectManagerBase & subRegion ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + GlobalComponentFractionKernel< NUM_COMP > kernel( subRegion ); + GlobalComponentFractionKernel< NUM_COMP >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp new file mode 100644 index 00000000000..e835d88b734 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp @@ -0,0 +1,365 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 HydrostaticPressureKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_HYDROSTATICPRESSUREKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_HYDROSTATICPRESSUREKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "functions/TableFunction.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** HydrostaticPressureKernel ********************************/ + +struct HydrostaticPressureKernel +{ + + // TODO: this type of constants should be centralized somewhere or provided by fluid model + static real64 constexpr MIN_FOR_PHASE_PRESENCE = 1e-12; + + enum class ReturnType : integer + { + FAILED_TO_CONVERGE = 0, + DETECTED_MULTIPHASE_FLOW = 1, + SUCCESS = 2 + }; + + template< typename FLUID_WRAPPER > + static ReturnType + computeHydrostaticPressure( integer const numComps, + integer const numPhases, + integer const ipInit, + integer const maxNumEquilIterations, + real64 const & equilTolerance, + real64 const (&gravVector)[ 3 ], + FLUID_WRAPPER fluidWrapper, + arrayView1d< TableFunction::KernelWrapper const > compFracTableWrappers, + TableFunction::KernelWrapper tempTableWrapper, + real64 const & refElevation, + real64 const & refPres, + arraySlice1d< real64 const > const & refPhaseMassDens, + real64 const & newElevation, + real64 & newPres, + arraySlice1d< real64 > const & newPhaseMassDens ) + { + // fluid properties at this elevation + StackArray< real64, 2, constitutive::MultiFluidBase::MAX_NUM_COMPONENTS, compflow::LAYOUT_COMP > compFrac( 1, numComps ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseFrac( 1, 1, numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseDens( 1, 1, numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseMassDens( 1, 1, numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseVisc( 1, 1, numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseEnthalpy( 1, 1, numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseInternalEnergy( 1, 1, numPhases ); + StackArray< real64, 4, constitutive::MultiFluidBase::MAX_NUM_PHASES *constitutive::MultiFluidBase::MAX_NUM_COMPONENTS, + constitutive::multifluid::LAYOUT_PHASE_COMP > phaseCompFrac( 1, 1, numPhases, numComps ); + real64 totalDens = 0.0; + + bool isSinglePhaseFlow = true; + + // Step 1: compute the hydrostatic pressure at the current elevation + + real64 const gravCoef = gravVector[2] * ( refElevation - newElevation ); + real64 const temp = tempTableWrapper.compute( &newElevation ); + for( integer ic = 0; ic < numComps; ++ic ) + { + compFrac[0][ic] = compFracTableWrappers[ic].compute( &newElevation ); + } + + // Step 2: guess the pressure with the refPhaseMassDensity + + real64 pres0 = refPres - refPhaseMassDens[ipInit] * gravCoef; + real64 pres1 = 0.0; + + // Step 3: compute the mass density at this elevation using the guess, and update pressure + + constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper, + pres0, + temp, + compFrac[0], + phaseFrac[0][0], + phaseDens[0][0], + phaseMassDens[0][0], + phaseVisc[0][0], + phaseEnthalpy[0][0], + phaseInternalEnergy[0][0], + phaseCompFrac[0][0], + totalDens ); + pres1 = refPres - 0.5 * ( refPhaseMassDens[ipInit] + phaseMassDens[0][0][ipInit] ) * gravCoef; + + // Step 4: fixed-point iteration until convergence + + bool equilHasConverged = false; + for( integer eqIter = 0; eqIter < maxNumEquilIterations; ++eqIter ) + { + + // check convergence + equilHasConverged = ( LvArray::math::abs( pres0 - pres1 ) < equilTolerance ); + pres0 = pres1; + + // if converged, check number of phases and move on + if( equilHasConverged ) + { + // make sure that the fluid is single-phase, other we have to issue a warning (for now) + // if only one phase is mobile, we are in good shape (unfortunately it is hard to access relperm from here) + localIndex numberOfPhases = 0; + for( integer ip = 0; ip < numPhases; ++ip ) + { + if( phaseFrac[0][0][ip] > MIN_FOR_PHASE_PRESENCE ) + { + numberOfPhases++; + } + } + if( numberOfPhases > 1 ) + { + isSinglePhaseFlow = false; + } + + break; + } + + // compute the mass density at this elevation using the previous pressure, and compute the new pressure + constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper, + pres0, + temp, + compFrac[0], + phaseFrac[0][0], + phaseDens[0][0], + phaseMassDens[0][0], + phaseVisc[0][0], + phaseEnthalpy[0][0], + phaseInternalEnergy[0][0], + phaseCompFrac[0][0], + totalDens ); + pres1 = refPres - 0.5 * ( refPhaseMassDens[ipInit] + phaseMassDens[0][0][ipInit] ) * gravCoef; + } + + // Step 5: save the hydrostatic pressure and the corresponding density + + newPres = pres1; + for( integer ip = 0; ip < numPhases; ++ip ) + { + newPhaseMassDens[ip] = phaseMassDens[0][0][ip]; + } + + if( !equilHasConverged ) + { + return ReturnType::FAILED_TO_CONVERGE; + } + else if( !isSinglePhaseFlow ) + { + return ReturnType::DETECTED_MULTIPHASE_FLOW; + } + else + { + return ReturnType::SUCCESS; + } + } + + template< typename FLUID_WRAPPER > + static ReturnType + launch( localIndex const size, + integer const numComps, + integer const numPhases, + integer const ipInit, + integer const maxNumEquilIterations, + real64 const equilTolerance, + real64 const (&gravVector)[ 3 ], + real64 const & minElevation, + real64 const & elevationIncrement, + real64 const & datumElevation, + real64 const & datumPres, + FLUID_WRAPPER fluidWrapper, + arrayView1d< TableFunction::KernelWrapper const > compFracTableWrappers, + TableFunction::KernelWrapper tempTableWrapper, + arrayView1d< arrayView1d< real64 > const > elevationValues, + arrayView1d< real64 > pressureValues ) + { + + ReturnType returnVal = ReturnType::SUCCESS; + + // Step 1: compute the phase mass densities at datum + + // datum fluid properties + array2d< real64, compflow::LAYOUT_COMP > datumCompFrac( 1, numComps ); + array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseFrac( 1, 1, numPhases ); + array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseDens( 1, 1, numPhases ); + array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseMassDens( 1, 1, numPhases ); + array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseVisc( 1, 1, numPhases ); + array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseEnthalpy( 1, 1, numPhases ); + array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseInternalEnergy( 1, 1, numPhases ); + array4d< real64, constitutive::multifluid::LAYOUT_PHASE_COMP > datumPhaseCompFrac( 1, 1, numPhases, numComps ); + real64 datumTotalDens = 0.0; + + real64 const datumTemp = tempTableWrapper.compute( &datumElevation ); + for( integer ic = 0; ic < numComps; ++ic ) + { + datumCompFrac[0][ic] = compFracTableWrappers[ic].compute( &datumElevation ); + } + constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper, + datumPres, + datumTemp, + datumCompFrac[0], + datumPhaseFrac[0][0], + datumPhaseDens[0][0], + datumPhaseMassDens[0][0], + datumPhaseVisc[0][0], + datumPhaseEnthalpy[0][0], + datumPhaseInternalEnergy[0][0], + datumPhaseCompFrac[0][0], + datumTotalDens ); + + // Step 2: find the closest elevation to datumElevation + + forAll< parallelHostPolicy >( size, [=] ( localIndex const i ) + { + real64 const elevation = minElevation + i * elevationIncrement; + elevationValues[0][i] = elevation; + } ); + integer const iRef = LvArray::sortedArrayManipulation::find( elevationValues[0].begin(), + elevationValues[0].size(), + datumElevation ); + + // Step 3: compute the mass density and pressure at the reference elevation + + array2d< real64 > phaseMassDens( pressureValues.size(), numPhases ); + // temporary array without permutation to compile on Lassen + array1d< real64 > datumPhaseMassDensTmp( numPhases ); + for( integer ip = 0; ip < numPhases; ++ip ) + { + datumPhaseMassDensTmp[ip] = datumPhaseMassDens[0][0][ip]; + } + + ReturnType const refReturnVal = + computeHydrostaticPressure( numComps, + numPhases, + ipInit, + maxNumEquilIterations, + equilTolerance, + gravVector, + fluidWrapper, + compFracTableWrappers, + tempTableWrapper, + datumElevation, + datumPres, + datumPhaseMassDensTmp, + elevationValues[0][iRef], + pressureValues[iRef], + phaseMassDens[iRef] ); + if( refReturnVal == ReturnType::FAILED_TO_CONVERGE ) + { + return ReturnType::FAILED_TO_CONVERGE; + } + else if( refReturnVal == ReturnType::DETECTED_MULTIPHASE_FLOW ) + { + returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW; + } + + // Step 4: for each elevation above the reference elevation, compute the pressure + + localIndex const numEntriesAboveRef = size - iRef - 1; + forAll< serialPolicy >( numEntriesAboveRef, [=, &returnVal] ( localIndex const i ) + { + ReturnType const returnValAboveRef = + computeHydrostaticPressure( numComps, + numPhases, + ipInit, + maxNumEquilIterations, + equilTolerance, + gravVector, + fluidWrapper, + compFracTableWrappers, + tempTableWrapper, + elevationValues[0][iRef+i], + pressureValues[iRef+i], + phaseMassDens[iRef+i], + elevationValues[0][iRef+i+1], + pressureValues[iRef+i+1], + phaseMassDens[iRef+i+1] ); + if( returnValAboveRef == ReturnType::FAILED_TO_CONVERGE ) + { + returnVal = ReturnType::FAILED_TO_CONVERGE; + } + else if( ( returnValAboveRef == ReturnType::DETECTED_MULTIPHASE_FLOW ) && + ( returnVal != ReturnType::FAILED_TO_CONVERGE ) ) + { + returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW; + } + + } ); + + // Step 5: for each elevation below the reference elevation, compute the pressure + + localIndex const numEntriesBelowRef = iRef; + forAll< serialPolicy >( numEntriesBelowRef, [=, &returnVal] ( localIndex const i ) + { + ReturnType const returnValBelowRef = + computeHydrostaticPressure( numComps, + numPhases, + ipInit, + maxNumEquilIterations, + equilTolerance, + gravVector, + fluidWrapper, + compFracTableWrappers, + tempTableWrapper, + elevationValues[0][iRef-i], + pressureValues[iRef-i], + phaseMassDens[iRef-i], + elevationValues[0][iRef-i-1], + pressureValues[iRef-i-1], + phaseMassDens[iRef-i-1] ); + if( returnValBelowRef == ReturnType::FAILED_TO_CONVERGE ) + { + returnVal = ReturnType::FAILED_TO_CONVERGE; + } + else if( ( returnValBelowRef == ReturnType::DETECTED_MULTIPHASE_FLOW ) && + ( returnVal != ReturnType::FAILED_TO_CONVERGE ) ) + { + returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW; + } + + } ); + + return returnVal; + } + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_HYDROSTATICPRESSUREKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp index 951a58fcbba..783aae6f0c5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp @@ -34,6 +34,7 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" namespace geos { @@ -43,7 +44,7 @@ namespace isothermalCompositionalMultiphaseBaseKernels static constexpr real64 minDensForDivision = 1e-10; -enum class ElementBasedAssemblyKernelFlags +enum class AccumulationKernelFlags { SimpleAccumulation = 1 << 0, // 1 TotalMassEquation = 1 << 1, // 2 @@ -56,2393 +57,455 @@ enum class ElementBasedAssemblyKernelFlags // Flag8 = 1 << 7 //128 }; -/******************************** PropertyKernelBase ********************************/ +/******************************** ElementBasedAssemblyKernel ********************************/ /** - * @class PropertyKernelBase + * @class ElementBasedAssemblyKernel * @tparam NUM_COMP number of fluid components - * @brief Define the base interface for the property update kernels + * @tparam NUM_DOF number of degrees of freedom + * @brief Define the interface for the assembly kernel in charge of accumulation and volume balance */ -template< integer NUM_COMP > -class PropertyKernelBase +template< integer NUM_COMP, integer NUM_DOF > +class ElementBasedAssemblyKernel { public: /// Compile time value for the number of components static constexpr integer numComp = NUM_COMP; - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numElems the number of elements - * @param[inout] kernelComponent the kernel component providing access to the compute function - */ - template< typename POLICY, typename KERNEL_TYPE > - static void - launch( localIndex const numElems, - KERNEL_TYPE const & kernelComponent ) - { - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - kernelComponent.compute( ei ); - } ); - } - - /** - * @brief Performs the kernel launch on a sorted array - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] targetSet the indices of the elements in which we compute the property - * @param[inout] kernelComponent the kernel component providing access to the compute function - */ - template< typename POLICY, typename KERNEL_TYPE > - static void - launch( SortedArrayView< localIndex const > const & targetSet, - KERNEL_TYPE const & kernelComponent ) - { - forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const i ) - { - localIndex const ei = targetSet[ i ]; - kernelComponent.compute( ei ); - } ); - } - -}; - -namespace internal -{ - -template< typename T, typename LAMBDA > -void kernelLaunchSelectorCompSwitch( T value, LAMBDA && lambda ) -{ - static_assert( std::is_integral< T >::value, "kernelLaunchSelectorCompSwitch: type should be integral" ); - - switch( value ) - { - case 1: - { lambda( std::integral_constant< T, 1 >() ); return; } - case 2: - { lambda( std::integral_constant< T, 2 >() ); return; } - case 3: - { lambda( std::integral_constant< T, 3 >() ); return; } - case 4: - { lambda( std::integral_constant< T, 4 >() ); return; } - case 5: - { lambda( std::integral_constant< T, 5 >() ); return; } - default: - { GEOS_ERROR( "Unsupported number of components: " << value ); } - } -} - -} // namespace internal - - -/******************************** GlobalComponentFractionKernel ********************************/ - -/** - * @class GlobalComponentFractionKernel - * @tparam NUM_COMP number of fluid components - * @brief Define the interface for the update kernel in charge of computing the phase volume fractions - */ -template< integer NUM_COMP > -class GlobalComponentFractionKernel : public PropertyKernelBase< NUM_COMP > -{ -public: + /// Compute time value for the number of degrees of freedom + static constexpr integer numDof = NUM_DOF; - using Base = PropertyKernelBase< NUM_COMP >; - using Base::numComp; + /// Compute time value for the number of equations + static constexpr integer numEqn = NUM_DOF; /** * @brief Constructor + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers * @param[in] subRegion the element subregion * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector */ - GlobalComponentFractionKernel( ObjectManagerBase & subRegion ) - : Base(), + ElementBasedAssemblyKernel( localIndex const numPhases, + globalIndex const rankOffset, + string const dofKey, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< AccumulationKernelFlags > const kernelFlags ) + : m_numPhases( numPhases ), + m_rankOffset( rankOffset ), + m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), + m_elemGhostRank( subRegion.ghostRank() ), + m_volume( subRegion.getElementVolume() ), + m_porosity( solid.getPorosity() ), + m_dPoro_dPres( solid.getDporosity_dPressure() ), + m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), + m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), + m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), + m_phaseDens( fluid.phaseDensity() ), + m_dPhaseDens( fluid.dPhaseDensity() ), + m_phaseCompFrac( fluid.phaseCompFraction() ), + m_dPhaseCompFrac( fluid.dPhaseCompFraction() ), m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), - m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ), - m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ) + m_compAmount_n( subRegion.getField< fields::flow::compAmount_n >() ), + m_localMatrix( localMatrix ), + m_localRhs( localRhs ), + m_kernelFlags( kernelFlags ) {} /** - * @brief Compute the phase volume fractions in an element - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[in] phaseVolFractionKernelOp the function used to customize the kernel + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void compute( localIndex const ei, - FUNC && compFractionKernelOp = NoOpFunc{} ) const + struct StackVariables { - arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; - arraySlice1d< real64, compflow::USD_COMP - 1 > const compFrac = m_compFrac[ei]; - arraySlice2d< real64, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; - - real64 totalDensity = 0.0; +public: - for( integer ic = 0; ic < numComp; ++ic ) - { - totalDensity += compDens[ic]; - } + // Pore volume information (used by both accumulation and volume balance) - real64 const totalDensityInv = 1.0 / totalDensity; + /// Pore volume at time n+1 + real64 poreVolume = 0.0; - for( integer ic = 0; ic < numComp; ++ic ) - { - compFrac[ic] = compDens[ic] * totalDensityInv; - for( integer jc = 0; jc < numComp; ++jc ) - { - dCompFrac_dCompDens[ic][jc] = -compFrac[ic] * totalDensityInv; - } - dCompFrac_dCompDens[ic][ic] += totalDensityInv; - } + /// Derivative of pore volume with respect to pressure + real64 dPoreVolume_dPres = 0.0; - compFractionKernelOp( compFrac, dCompFrac_dCompDens ); - } + // Residual information -protected: + /// Index of the local row corresponding to this element + localIndex localRow = -1; - // inputs + /// Indices of the matrix rows/columns corresponding to the dofs in this element + globalIndex dofIndices[numDof]{}; - // Views on component densities - arrayView2d< real64 const, compflow::USD_COMP > m_compDens; + /// C-array storage for the element local residual vector (all equations except volume balance) + real64 localResidual[numEqn]{}; - // outputs + /// C-array storage for the element local Jacobian matrix (all equations except volume balance, all dofs) + real64 localJacobian[numEqn][numDof]{}; - // Views on component fraction - arrayView2d< real64, compflow::USD_COMP > m_compFrac; - arrayView3d< real64, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; + }; -}; + /** + * @brief Getter for the ghost rank of an element + * @param[in] ei the element index + * @return the ghost rank of the element + */ + GEOS_HOST_DEVICE + integer elemGhostRank( localIndex const ei ) const + { return m_elemGhostRank( ei ); } -/** - * @class GlobalComponentFractionKernelFactory - */ -class GlobalComponentFractionKernelFactory -{ -public: /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComp the number of fluid components - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model + * @brief Performs the setup phase for the kernel. + * @param[in] ei the element index + * @param[in] stack the stack variables */ - template< typename POLICY > - static void - createAndLaunch( integer const numComp, - ObjectManagerBase & subRegion ) + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const { - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + // initialize the pore volume + stack.poreVolume = m_volume[ei] * m_porosity[ei][0]; + stack.dPoreVolume_dPres = m_volume[ei] * m_dPoro_dPres[ei][0]; + + // set row index and degrees of freedom indices for this element + stack.localRow = m_dofNumber[ei] - m_rankOffset; + for( integer idof = 0; idof < numDof; ++idof ) { - integer constexpr NUM_COMP = NC(); - GlobalComponentFractionKernel< NUM_COMP > kernel( subRegion ); - GlobalComponentFractionKernel< NUM_COMP >::template launch< POLICY >( subRegion.size(), kernel ); - } ); + stack.dofIndices[idof] = m_dofNumber[ei] + idof; + } } -}; - -/******************************** PhaseVolumeFractionKernel ********************************/ - -/** - * @class PhaseVolumeFractionKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_PHASE number of fluid phases - * @brief Define the interface for the property kernel in charge of computing the phase volume fractions - */ -template< integer NUM_COMP, integer NUM_PHASE > -class PhaseVolumeFractionKernel : public PropertyKernelBase< NUM_COMP > -{ -public: - - using Base = PropertyKernelBase< NUM_COMP >; - using Base::numComp; - - /// Compile time value for the number of phases - static constexpr integer numPhase = NUM_PHASE; - - /** - * @brief Constructor - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - */ - PhaseVolumeFractionKernel( ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid ) - : Base(), - m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), - m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), - m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), - m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), - m_phaseFrac( fluid.phaseFraction() ), - m_dPhaseFrac( fluid.dPhaseFraction() ), - m_phaseDens( fluid.phaseDensity() ), - m_dPhaseDens( fluid.dPhaseDensity() ) - {} - /** - * @brief Compute the phase volume fractions in an element + * @brief Compute the local accumulation contributions to the residual and Jacobian * @tparam FUNC the type of the function that can be used to customize the kernel * @param[in] ei the element index - * @param[in] phaseVolFractionKernelOp the function used to customize the kernel + * @param[inout] stack the stack variables + * @param[in] phaseAmountKernelOp the function used to customize the kernel */ template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE - real64 compute( localIndex const ei, - FUNC && phaseVolFractionKernelOp = NoOpFunc{} ) const + void computeAccumulation( localIndex const ei, + StackVariables & stack, + FUNC && phaseAmountKernelOp = NoOpFunc{} ) const { - using Deriv = constitutive::multifluid::DerivativeOffset; - - arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; - arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; - arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; - - real64 work[numComp]{}; - - // compute total density from component partial densities - real64 totalDensity = 0.0; - real64 const dTotalDens_dCompDens = 1.0; - for( integer ic = 0; ic < numComp; ++ic ) + if( m_kernelFlags.isSet( AccumulationKernelFlags::SimpleAccumulation ) ) { - totalDensity += compDens[ic]; - } + // ic - index of component whose conservation equation is assembled + // (i.e. row number in local matrix) + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const compAmount = stack.poreVolume * m_compDens[ei][ic]; + real64 const compAmount_n = m_compAmount_n[ei][ic]; - real64 maxDeltaPhaseVolFrac = 0.0; + stack.localResidual[ic] += compAmount - compAmount_n; - for( integer ip = 0; ip < numPhase; ++ip ) - { + // Pavel: commented below is some experiment, needs to be re-tested + //real64 const compDens = (ic == 0 && m_compDens[ei][ic] < 1e-6) ? 1e-3 : m_compDens[ei][ic]; + real64 const dCompAmount_dP = stack.dPoreVolume_dPres * m_compDens[ei][ic]; + stack.localJacobian[ic][0] += dCompAmount_dP; - // set the saturation to zero if the phase is absent - bool const phaseExists = (phaseFrac[ip] > 0); - if( !phaseExists ) - { - phaseVolFrac[ip] = 0.; - for( integer jc = 0; jc < numComp+2; ++jc ) - { - dPhaseVolFrac[ip][jc] = 0.; - } - continue; + real64 const dCompAmount_dC = stack.poreVolume; + stack.localJacobian[ic][ic + 1] += dCompAmount_dC; } + } + else + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + // construct the slices for variables accessed multiple times + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; - // Expression for volume fractions: S_p = (nu_p / rho_p) * rho_t - real64 const phaseDensInv = 1.0 / phaseDens[ip]; + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac = m_phaseVolFrac[ei]; + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; - // store old saturation to compute change later - real64 const satOld = phaseVolFrac[ip]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseDens = m_dPhaseDens[ei][0]; - // compute saturation and derivatives except multiplying by the total density - phaseVolFrac[ip] = phaseFrac[ip] * phaseDensInv; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 2 > phaseCompFrac = m_phaseCompFrac[ei][0]; + arraySlice3d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac = m_dPhaseCompFrac[ei][0]; - dPhaseVolFrac[ip][Deriv::dP] = - (dPhaseFrac[ip][Deriv::dP] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dP]) * phaseDensInv; + // temporary work arrays + real64 dPhaseAmount_dC[numComp]{}; + real64 dPhaseCompFrac_dC[numComp]{}; - for( integer jc = 0; jc < numComp; ++jc ) + // start with old time step values + for( integer ic = 0; ic < numComp; ++ic ) { - dPhaseVolFrac[ip][Deriv::dC+jc] = - (dPhaseFrac[ip][Deriv::dC+jc] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dC+jc]) * phaseDensInv; + stack.localResidual[ic] = -m_compAmount_n[ei][ic]; } - // apply chain rule to convert derivatives from global component fractions to densities - applyChainRuleInPlace( numComp, dCompFrac_dCompDens, dPhaseVolFrac[ip], work, Deriv::dC ); + // sum contributions to component accumulation from each phase + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + real64 const phaseAmount = stack.poreVolume * phaseVolFrac[ip] * phaseDens[ip]; - // call the lambda in the phase loop to allow the reuse of the phaseVolFrac and totalDensity - // possible use: assemble the derivatives wrt temperature - phaseVolFractionKernelOp( ip, phaseVolFrac[ip], phaseDensInv, totalDensity ); + real64 const dPhaseAmount_dP = stack.dPoreVolume_dPres * phaseVolFrac[ip] * phaseDens[ip] + + stack.poreVolume * ( dPhaseVolFrac[ip][Deriv::dP] * phaseDens[ip] + + phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dP] ); - // now finalize the computation by multiplying by total density - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseVolFrac[ip][Deriv::dC+jc] *= totalDensity; - dPhaseVolFrac[ip][Deriv::dC+jc] += phaseVolFrac[ip] * dTotalDens_dCompDens; - } + // assemble density dependence + applyChainRule( numComp, dCompFrac_dCompDens, dPhaseDens[ip], dPhaseAmount_dC, Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseAmount_dC[jc] = dPhaseAmount_dC[jc] * phaseVolFrac[ip] + + phaseDens[ip] * dPhaseVolFrac[ip][Deriv::dC + jc]; + dPhaseAmount_dC[jc] *= stack.poreVolume; + } - phaseVolFrac[ip] *= totalDensity; - dPhaseVolFrac[ip][Deriv::dP] *= totalDensity; + // ic - index of component whose conservation equation is assembled + // (i.e. row number in local matrix) + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const phaseCompAmount = phaseAmount * phaseCompFrac[ip][ic]; - real64 const deltaPhaseVolFrac = LvArray::math::abs( phaseVolFrac[ip] - satOld ); - if( maxDeltaPhaseVolFrac < deltaPhaseVolFrac ) - { - maxDeltaPhaseVolFrac = deltaPhaseVolFrac; - } - } - return maxDeltaPhaseVolFrac; - } + real64 const dPhaseCompAmount_dP = dPhaseAmount_dP * phaseCompFrac[ip][ic] + + phaseAmount * dPhaseCompFrac[ip][ic][Deriv::dP]; - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numElems the number of elements - * @param[inout] kernelComponent the kernel component providing access to the compute function - */ - template< typename POLICY, typename KERNEL_TYPE > - static real64 - launch( localIndex const numElems, - KERNEL_TYPE const & kernelComponent ) - { - RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPhaseVolFrac( 0.0 ); - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - real64 const deltaPhaseVolFrac = kernelComponent.compute( ei ); - maxDeltaPhaseVolFrac.max( deltaPhaseVolFrac ); - } ); - return maxDeltaPhaseVolFrac.get(); - } - -protected: - - // outputs - - /// Views on phase volume fractions - arrayView2d< real64, compflow::USD_PHASE > m_phaseVolFrac; - arrayView3d< real64, compflow::USD_PHASE_DC > m_dPhaseVolFrac; - - // inputs - - /// Views on component densities - arrayView2d< real64 const, compflow::USD_COMP > m_compDens; - arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; - - /// Views on phase fractions - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseFrac; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseFrac; - - /// Views on phase densities - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseDens; - -}; - -/** - * @class PhaseVolumeFractionKernelFactory - */ -class PhaseVolumeFractionKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComp the number of fluid components - * @param[in] numPhase the number of fluid phases - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - */ - template< typename POLICY > - static real64 - createAndLaunch( integer const numComp, - integer const numPhase, - ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid ) - { - real64 maxDeltaPhaseVolFrac = 0.0; - if( numPhase == 2 ) - { - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseVolumeFractionKernel< NUM_COMP, 2 > kernel( subRegion, fluid ); - maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - else if( numPhase == 3 ) - { - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseVolumeFractionKernel< NUM_COMP, 3 > kernel( subRegion, fluid ); - maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - return maxDeltaPhaseVolFrac; - } -}; - - -/******************************** RelativePermeabilityUpdateKernel ********************************/ - -struct RelativePermeabilityUpdateKernel -{ - template< typename POLICY, typename RELPERM_WRAPPER > - static void - launch( localIndex const size, - RELPERM_WRAPPER const & relPermWrapper, - arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < relPermWrapper.numGauss(); ++q ) - { - relPermWrapper.update( k, q, phaseVolFrac[k] ); - } - } ); - } - - template< typename POLICY, typename RELPERM_WRAPPER > - static void - launch( SortedArrayView< localIndex const > const & targetSet, - RELPERM_WRAPPER const & relPermWrapper, - arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) - { - forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) - { - localIndex const k = targetSet[a]; - for( localIndex q = 0; q < relPermWrapper.numGauss(); ++q ) - { - relPermWrapper.update( k, q, phaseVolFrac[k] ); - } - } ); - } -}; - -/******************************** CapillaryPressureUpdateKernel ********************************/ - -struct CapillaryPressureUpdateKernel -{ - template< typename POLICY, typename CAPPRES_WRAPPER > - static void - launch( localIndex const size, - CAPPRES_WRAPPER const & capPresWrapper, - arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < capPresWrapper.numGauss(); ++q ) - { - capPresWrapper.update( k, q, phaseVolFrac[k] ); - } - } ); - } - - template< typename POLICY, typename CAPPRES_WRAPPER > - static void - launch( SortedArrayView< localIndex const > const & targetSet, - CAPPRES_WRAPPER const & capPresWrapper, - arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) - { - forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) - { - localIndex const k = targetSet[a]; - for( localIndex q = 0; q < capPresWrapper.numGauss(); ++q ) - { - capPresWrapper.update( k, q, phaseVolFrac[k] ); - } - } ); - } -}; - -/******************************** ElementBasedAssemblyKernel ********************************/ - -/** - * @class ElementBasedAssemblyKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @brief Define the interface for the assembly kernel in charge of accumulation and volume balance - */ -template< integer NUM_COMP, integer NUM_DOF > -class ElementBasedAssemblyKernel -{ -public: - - /// Compile time value for the number of components - static constexpr integer numComp = NUM_COMP; - - /// Compute time value for the number of degrees of freedom - static constexpr integer numDof = NUM_DOF; - - /// Compute time value for the number of equations - static constexpr integer numEqn = NUM_DOF; - - /** - * @brief Constructor - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - ElementBasedAssemblyKernel( localIndex const numPhases, - globalIndex const rankOffset, - string const dofKey, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< ElementBasedAssemblyKernelFlags > const kernelFlags ) - : m_numPhases( numPhases ), - m_rankOffset( rankOffset ), - m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), - m_elemGhostRank( subRegion.ghostRank() ), - m_volume( subRegion.getElementVolume() ), - m_porosity( solid.getPorosity() ), - m_dPoro_dPres( solid.getDporosity_dPressure() ), - m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), - m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), - m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), - m_phaseDens( fluid.phaseDensity() ), - m_dPhaseDens( fluid.dPhaseDensity() ), - m_phaseCompFrac( fluid.phaseCompFraction() ), - m_dPhaseCompFrac( fluid.dPhaseCompFraction() ), - m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), - m_compAmount_n( subRegion.getField< fields::flow::compAmount_n >() ), - m_localMatrix( localMatrix ), - m_localRhs( localRhs ), - m_kernelFlags( kernelFlags ) - {} - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables - { -public: - - // Pore volume information (used by both accumulation and volume balance) - - /// Pore volume at time n+1 - real64 poreVolume = 0.0; - - /// Derivative of pore volume with respect to pressure - real64 dPoreVolume_dPres = 0.0; - - // Residual information - - /// Index of the local row corresponding to this element - localIndex localRow = -1; - - /// Indices of the matrix rows/columns corresponding to the dofs in this element - globalIndex dofIndices[numDof]{}; - - /// C-array storage for the element local residual vector (all equations except volume balance) - real64 localResidual[numEqn]{}; - - /// C-array storage for the element local Jacobian matrix (all equations except volume balance, all dofs) - real64 localJacobian[numEqn][numDof]{}; - - }; - - /** - * @brief Getter for the ghost rank of an element - * @param[in] ei the element index - * @return the ghost rank of the element - */ - GEOS_HOST_DEVICE - integer elemGhostRank( localIndex const ei ) const - { return m_elemGhostRank( ei ); } - - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] ei the element index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - void setup( localIndex const ei, - StackVariables & stack ) const - { - // initialize the pore volume - stack.poreVolume = m_volume[ei] * m_porosity[ei][0]; - stack.dPoreVolume_dPres = m_volume[ei] * m_dPoro_dPres[ei][0]; - - // set row index and degrees of freedom indices for this element - stack.localRow = m_dofNumber[ei] - m_rankOffset; - for( integer idof = 0; idof < numDof; ++idof ) - { - stack.dofIndices[idof] = m_dofNumber[ei] + idof; - } - } - - /** - * @brief Compute the local accumulation contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[inout] stack the stack variables - * @param[in] phaseAmountKernelOp the function used to customize the kernel - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void computeAccumulation( localIndex const ei, - StackVariables & stack, - FUNC && phaseAmountKernelOp = NoOpFunc{} ) const - { - if( m_kernelFlags.isSet( ElementBasedAssemblyKernelFlags::SimpleAccumulation ) ) - { - // ic - index of component whose conservation equation is assembled - // (i.e. row number in local matrix) - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const compAmount = stack.poreVolume * m_compDens[ei][ic]; - real64 const compAmount_n = m_compAmount_n[ei][ic]; - - stack.localResidual[ic] += compAmount - compAmount_n; - - // Pavel: commented below is some experiment, needs to be re-tested - //real64 const compDens = (ic == 0 && m_compDens[ei][ic] < 1e-6) ? 1e-3 : m_compDens[ei][ic]; - real64 const dCompAmount_dP = stack.dPoreVolume_dPres * m_compDens[ei][ic]; - stack.localJacobian[ic][0] += dCompAmount_dP; - - real64 const dCompAmount_dC = stack.poreVolume; - stack.localJacobian[ic][ic + 1] += dCompAmount_dC; - } - } - else - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - // construct the slices for variables accessed multiple times - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; - - arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac = m_phaseVolFrac[ei]; - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; - - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseDens = m_phaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseDens = m_dPhaseDens[ei][0]; - - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 2 > phaseCompFrac = m_phaseCompFrac[ei][0]; - arraySlice3d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac = m_dPhaseCompFrac[ei][0]; - - // temporary work arrays - real64 dPhaseAmount_dC[numComp]{}; - real64 dPhaseCompFrac_dC[numComp]{}; - - // start with old time step values - for( integer ic = 0; ic < numComp; ++ic ) - { - stack.localResidual[ic] = -m_compAmount_n[ei][ic]; - } - - // sum contributions to component accumulation from each phase - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - real64 const phaseAmount = stack.poreVolume * phaseVolFrac[ip] * phaseDens[ip]; - - real64 const dPhaseAmount_dP = stack.dPoreVolume_dPres * phaseVolFrac[ip] * phaseDens[ip] - + stack.poreVolume * ( dPhaseVolFrac[ip][Deriv::dP] * phaseDens[ip] - + phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dP] ); - - // assemble density dependence - applyChainRule( numComp, dCompFrac_dCompDens, dPhaseDens[ip], dPhaseAmount_dC, Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseAmount_dC[jc] = dPhaseAmount_dC[jc] * phaseVolFrac[ip] - + phaseDens[ip] * dPhaseVolFrac[ip][Deriv::dC + jc]; - dPhaseAmount_dC[jc] *= stack.poreVolume; - } - - // ic - index of component whose conservation equation is assembled - // (i.e. row number in local matrix) - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const phaseCompAmount = phaseAmount * phaseCompFrac[ip][ic]; - - real64 const dPhaseCompAmount_dP = dPhaseAmount_dP * phaseCompFrac[ip][ic] - + phaseAmount * dPhaseCompFrac[ip][ic][Deriv::dP]; - - stack.localResidual[ic] += phaseCompAmount; - stack.localJacobian[ic][0] += dPhaseCompAmount_dP; - - // jc - index of component w.r.t. whose compositional var the derivative is being taken - // (i.e. col number in local matrix) - - // assemble phase composition dependence - applyChainRule( numComp, dCompFrac_dCompDens, dPhaseCompFrac[ip][ic], dPhaseCompFrac_dC, Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - real64 const dPhaseCompAmount_dC = dPhaseCompFrac_dC[jc] * phaseAmount - + phaseCompFrac[ip][ic] * dPhaseAmount_dC[jc]; - - stack.localJacobian[ic][jc + 1] += dPhaseCompAmount_dC; - } - } - - // call the lambda in the phase loop to allow the reuse of the phase amounts and their derivatives - // possible use: assemble the derivatives wrt temperature, and the accumulation term of the energy equation for this phase - phaseAmountKernelOp( ip, phaseAmount, dPhaseAmount_dP, dPhaseAmount_dC ); - - } - } - } - - /** - * @brief Compute the local volume balance contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[inout] stack the stack variables - * @param[in] phaseVolFractionSumKernelOp the function used to customize the kernel - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void computeVolumeBalance( localIndex const ei, - StackVariables & stack, - FUNC && phaseVolFractionSumKernelOp = NoOpFunc{} ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac = m_phaseVolFrac[ei]; - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; - - real64 oneMinusPhaseVolFracSum = 1.0; - - // sum contributions to component accumulation from each phase - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - oneMinusPhaseVolFracSum -= phaseVolFrac[ip]; - stack.localJacobian[numComp][0] -= dPhaseVolFrac[ip][Deriv::dP]; - - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.localJacobian[numComp][jc+1] -= dPhaseVolFrac[ip][Deriv::dC+jc]; - } - } - - // call the lambda in the phase loop to allow the reuse of the phase amounts and their derivatives - // possible use: assemble the derivatives wrt temperature, and use oneMinusPhaseVolFracSum if poreVolume depends on temperature - phaseVolFractionSumKernelOp( oneMinusPhaseVolFracSum ); - - // scale saturation-based volume balance by pore volume (for better scaling w.r.t. other equations) - stack.localResidual[numComp] = stack.poreVolume * oneMinusPhaseVolFracSum; - for( integer idof = 0; idof < numDof; ++idof ) - { - stack.localJacobian[numComp][idof] *= stack.poreVolume; - } - stack.localJacobian[numComp][0] += stack.dPoreVolume_dPres * oneMinusPhaseVolFracSum; - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void complete( localIndex const GEOS_UNUSED_PARAM( ei ), - StackVariables & stack ) const - { - using namespace compositionalMultiphaseUtilities; - - if( m_kernelFlags.isSet( ElementBasedAssemblyKernelFlags::TotalMassEquation ) ) - { - // apply equation/variable change transformation to the component mass balance equations - real64 work[numDof]{}; - shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numDof, stack.localJacobian, work ); - shiftElementsAheadByOneAndReplaceFirstElementWithSum( numComp, stack.localResidual ); - } - - // add contribution to residual and jacobian into: - // - the component mass balance equations (i = 0 to i = numComp-1) - // - the volume balance equations (i = numComp) - // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels - integer const numRows = numComp+1; - for( integer i = 0; i < numRows; ++i ) - { - m_localRhs[stack.localRow + i] += stack.localResidual[i]; - m_localMatrix.addToRow< serialAtomic >( stack.localRow + i, - stack.dofIndices, - stack.localJacobian[i], - numDof ); - } - } - - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numElems the number of elements - * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables - */ - template< typename POLICY, typename KERNEL_TYPE > - static void - launch( localIndex const numElems, - KERNEL_TYPE const & kernelComponent ) - { - GEOS_MARK_FUNCTION; - - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( kernelComponent.elemGhostRank( ei ) >= 0 ) - { - return; - } - - typename KERNEL_TYPE::StackVariables stack; - - kernelComponent.setup( ei, stack ); - kernelComponent.computeAccumulation( ei, stack ); - kernelComponent.computeVolumeBalance( ei, stack ); - kernelComponent.complete( ei, stack ); - } ); - } - -protected: - - /// Number of fluid phases - integer const m_numPhases; - - /// Offset for my MPI rank - globalIndex const m_rankOffset; - - /// View on the dof numbers - arrayView1d< globalIndex const > const m_dofNumber; - - /// View on the ghost ranks - arrayView1d< integer const > const m_elemGhostRank; - - /// View on the element volumes - arrayView1d< real64 const > const m_volume; - - /// Views on the porosity - arrayView2d< real64 const > const m_porosity; - arrayView2d< real64 const > const m_dPoro_dPres; - - /// Views on the derivatives of comp fractions wrt component density - arrayView3d< real64 const, compflow::USD_COMP_DC > const m_dCompFrac_dCompDens; - - /// Views on the phase volume fractions - arrayView2d< real64 const, compflow::USD_PHASE > const m_phaseVolFrac; - arrayView3d< real64 const, compflow::USD_PHASE_DC > const m_dPhaseVolFrac; - - /// Views on the phase densities - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseDens; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseDens; - - /// Views on the phase component fraction - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > const m_phaseCompFrac; - arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > const m_dPhaseCompFrac; - - // View on component densities - arrayView2d< real64 const, compflow::USD_COMP > m_compDens; - - // View on component amount (mass/moles) from previous time step - arrayView2d< real64 const, compflow::USD_COMP > m_compAmount_n; - - /// View on the local CRS matrix - CRSMatrixView< real64, globalIndex const > const m_localMatrix; - /// View on the local RHS - arrayView1d< real64 > const m_localRhs; - - BitFlags< ElementBasedAssemblyKernelFlags > const m_kernelFlags; -}; - -/** - * @class ElementBasedAssemblyKernelFactory - */ -class ElementBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - integer const useTotalMassEquation, - integer const useSimpleAccumulation, - string const dofKey, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - internal::kernelLaunchSelectorCompSwitch( numComps, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - integer constexpr NUM_DOF = NC()+1; - - BitFlags< ElementBasedAssemblyKernelFlags > kernelFlags; - if( useTotalMassEquation ) - kernelFlags.set( ElementBasedAssemblyKernelFlags::TotalMassEquation ); - if( useSimpleAccumulation ) - kernelFlags.set( ElementBasedAssemblyKernelFlags::SimpleAccumulation ); - - ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF > - kernel( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ); - ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - -}; - -/******************************** SolutionScalingKernelKernel ********************************/ - -/** - * @class ScalingAndCheckingSystemSolutionKernelBase - * @brief Define the kernel for scaling the solution and check its validity - */ -template< typename TYPE > -class ScalingAndCheckingSystemSolutionKernelBase -{ -public: - - /** - * @brief Create a new kernel instance - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - * @param[in] pressure the pressure vector - * @param[in] compDens the component density vector - * @param[in] pressureScalingFactor the pressure local scaling factor - * @param[in] compDensScalingFactor the component local scaling factor - */ - ScalingAndCheckingSystemSolutionKernelBase( globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor ) - : m_rankOffset( rankOffset ), - m_numComp( numComp ), - m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), - m_ghostRank( subRegion.ghostRank() ), - m_localSolution( localSolution ), - m_pressure( pressure ), // not passed with fields::flow to be able to reuse this for wells - m_compDens( compDens ), // same here - m_pressureScalingFactor( pressureScalingFactor ), - m_compDensScalingFactor( compDensScalingFactor ) - { } - - /** - * @struct StackVariables - * @brief Kernel variables located on the stack - */ - struct StackVariables - { - GEOS_HOST_DEVICE - StackVariables() - { } - - StackVariables( real64 _localMinVal ) - : - localMinVal( _localMinVal ) - { } - - /// Index of the local row corresponding to this element - localIndex localRow; - - /// The local value - TYPE localMinVal; - }; - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] ei the element index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - void setup( localIndex const ei, - StackVariables & stack ) const - { - stack.localMinVal = 1; - - // set row index and degrees of freedom indices for this element - stack.localRow = m_dofNumber[ei] - m_rankOffset; - } - - /** - * @brief Getter for the ghost rank - * @param[in] i the looping index of the element/node/face - * @return the ghost rank of the element/node/face - */ - GEOS_HOST_DEVICE - integer ghostRank( localIndex const i ) const - { return m_ghostRank( i ); } - - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numElems the number of elements - * @param[inout] kernelComponent the kernel component providing access to the compute function - */ - template< typename POLICY, typename KERNEL_TYPE > - static TYPE - launch( localIndex const numElems, - KERNEL_TYPE const & kernelComponent ) - { - RAJA::ReduceMin< ReducePolicy< POLICY >, TYPE > minVal( 1 ); - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( kernelComponent.ghostRank( ei ) >= 0 ) - { - return; - } - - StackVariables stack; - kernelComponent.setup( ei, stack ); - kernelComponent.compute( ei, stack ); - minVal.min( stack.localMinVal ); - } ); - - return minVal.get(); - } - -protected: - - /// Offset for my MPI rank - globalIndex const m_rankOffset; - - /// Number of components - real64 const m_numComp; - - /// View on the dof numbers - arrayView1d< globalIndex const > const m_dofNumber; - - /// View on the ghost ranks - arrayView1d< integer const > const m_ghostRank; - - /// View on the local residual - arrayView1d< real64 const > const m_localSolution; - - /// View on the primary variables - arrayView1d< real64 const > const m_pressure; - arrayView2d< real64 const, compflow::USD_COMP > const m_compDens; - - /// View on the scaling factors - arrayView1d< real64 > const m_pressureScalingFactor; - arrayView1d< real64 > const m_compDensScalingFactor; - -}; - -/** - * @class ScalingForSystemSolutionKernel - * @brief Define the kernel for scaling the Newton update - */ -class ScalingForSystemSolutionKernel : public ScalingAndCheckingSystemSolutionKernelBase< real64 > -{ -public: - - using Base = ScalingAndCheckingSystemSolutionKernelBase< real64 >; - using Base::m_rankOffset; - using Base::m_numComp; - using Base::m_dofNumber; - using Base::m_ghostRank; - using Base::m_localSolution; - using Base::m_pressure; - using Base::m_compDens; - using Base::m_pressureScalingFactor; - using Base::m_compDensScalingFactor; - - /** - * @brief Create a new kernel instance - * @param[in] maxRelativePresChange the max allowed relative pressure change - * @param[in] maxAbsolutePresChange the max allowed absolute pressure change - * @param[in] maxCompFracChange the max allowed comp fraction change - * @param[in] maxRelativeCompDensChange the max allowed comp density change - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - * @param[in] pressure the pressure vector - * @param[in] compDens the component density vector - * @param[in] pressureScalingFactor the pressure local scaling factor - * @param[in] compDensScalingFactor the component density local scaling factor - */ - ScalingForSystemSolutionKernel( real64 const maxRelativePresChange, - real64 const maxAbsolutePresChange, - real64 const maxCompFracChange, - real64 const maxRelativeCompDensChange, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor ) - : Base( rankOffset, - numComp, - dofKey, - subRegion, - localSolution, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor ), - m_maxRelativePresChange( maxRelativePresChange ), - m_maxAbsolutePresChange( maxAbsolutePresChange ), - m_maxCompFracChange( maxCompFracChange ), - m_maxRelativeCompDensChange( maxRelativeCompDensChange ) - {} - - /** - * @struct StackVariables - * @brief Kernel variables located on the stack - */ - struct StackVariables : public Base::StackVariables - { - GEOS_HOST_DEVICE - StackVariables() - { } - - StackVariables( real64 _localMinVal, - real64 _localMaxDeltaPres, - real64 _localMaxDeltaTemp, - real64 _localMaxDeltaCompDens, - real64 _localMinPresScalingFactor, - real64 _localMinTempScalingFactor, - real64 _localMinCompDensScalingFactor ) - : - Base::StackVariables( _localMinVal ), - localMaxDeltaPres( _localMaxDeltaPres ), - localMaxDeltaTemp( _localMaxDeltaTemp ), - localMaxDeltaCompDens( _localMaxDeltaCompDens ), - localMinPresScalingFactor( _localMinPresScalingFactor ), - localMinTempScalingFactor( _localMinTempScalingFactor ), - localMinCompDensScalingFactor( _localMinCompDensScalingFactor ) - { } - - real64 localMaxDeltaPres; - real64 localMaxDeltaTemp; - real64 localMaxDeltaCompDens; - - real64 localMinPresScalingFactor; - real64 localMinTempScalingFactor; - real64 localMinCompDensScalingFactor; + stack.localResidual[ic] += phaseCompAmount; + stack.localJacobian[ic][0] += dPhaseCompAmount_dP; - }; + // jc - index of component w.r.t. whose compositional var the derivative is being taken + // (i.e. col number in local matrix) - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numElems the number of elements - * @param[inout] kernelComponent the kernel component providing access to the compute function - */ - template< typename POLICY, typename KERNEL_TYPE > - static StackVariables - launch( localIndex const numElems, - KERNEL_TYPE const & kernelComponent ) - { - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > globalScalingFactor( 1.0 ); + // assemble phase composition dependence + applyChainRule( numComp, dCompFrac_dCompDens, dPhaseCompFrac[ip][ic], dPhaseCompFrac_dC, Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + real64 const dPhaseCompAmount_dC = dPhaseCompFrac_dC[jc] * phaseAmount + + phaseCompFrac[ip][ic] * dPhaseAmount_dC[jc]; - RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 ); - RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaTemp( 0.0 ); - RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaCompDens( 0.0 ); + stack.localJacobian[ic][jc + 1] += dPhaseCompAmount_dC; + } + } - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPresScalingFactor( 1.0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minTempScalingFactor( 1.0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minCompDensScalingFactor( 1.0 ); + // call the lambda in the phase loop to allow the reuse of the phase amounts and their derivatives + // possible use: assemble the derivatives wrt temperature, and the accumulation term of the energy equation for this phase + phaseAmountKernelOp( ip, phaseAmount, dPhaseAmount_dP, dPhaseAmount_dC ); - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( kernelComponent.ghostRank( ei ) >= 0 ) - { - return; } - - StackVariables stack; - kernelComponent.setup( ei, stack ); - kernelComponent.compute( ei, stack ); - - globalScalingFactor.min( stack.localMinVal ); - - maxDeltaPres.max( stack.localMaxDeltaPres ); - maxDeltaTemp.max( stack.localMaxDeltaTemp ); - maxDeltaCompDens.max( stack.localMaxDeltaCompDens ); - - minPresScalingFactor.min( stack.localMinPresScalingFactor ); - minTempScalingFactor.min( stack.localMinTempScalingFactor ); - minCompDensScalingFactor.min( stack.localMinCompDensScalingFactor ); - } ); - - return StackVariables( globalScalingFactor.get(), - maxDeltaPres.get(), - maxDeltaTemp.get(), - maxDeltaCompDens.get(), - minPresScalingFactor.get(), - minTempScalingFactor.get(), - minCompDensScalingFactor.get() ); - } - - GEOS_HOST_DEVICE - void setup( localIndex const ei, - StackVariables & stack ) const - { - Base::setup( ei, stack ); - - stack.localMaxDeltaPres = 0.0; - stack.localMaxDeltaTemp = 0.0; - stack.localMaxDeltaCompDens = 0.0; - - stack.localMinPresScalingFactor = 1.0; - stack.localMinTempScalingFactor = 1.0; - stack.localMinCompDensScalingFactor = 1.0; - } - - /** - * @brief Compute the local value - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void compute( localIndex const ei, - StackVariables & stack ) const - { - computeScalingFactor( ei, stack ); + } } /** - * @brief Compute the local value of the scaling factor + * @brief Compute the local volume balance contributions to the residual and Jacobian * @tparam FUNC the type of the function that can be used to customize the kernel * @param[in] ei the element index * @param[inout] stack the stack variables - * @param[in] kernelOp the function used to customize the kernel + * @param[in] phaseVolFractionSumKernelOp the function used to customize the kernel */ template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE - void computeScalingFactor( localIndex const ei, + void computeVolumeBalance( localIndex const ei, StackVariables & stack, - FUNC && kernelOp = NoOpFunc{} ) const + FUNC && phaseVolFractionSumKernelOp = NoOpFunc{} ) const { - real64 constexpr eps = minDensForDivision; - - // compute the change in pressure - real64 const pres = m_pressure[ei]; - real64 const absPresChange = LvArray::math::abs( m_localSolution[stack.localRow] ); - if( stack.localMaxDeltaPres < absPresChange ) - { - stack.localMaxDeltaPres = absPresChange; - } - - // compute pressure scaling factor - real64 presScalingFactor = 1.0; - // when enabled, absolute change scaling has a priority over relative change - if( m_maxAbsolutePresChange > 0.0 ) // maxAbsolutePresChange <= 0.0 means that absolute scaling is disabled - { - if( absPresChange > m_maxAbsolutePresChange ) - { - presScalingFactor = m_maxAbsolutePresChange / absPresChange; - } - } - else if( pres > eps ) - { - real64 const relativePresChange = absPresChange / pres; - if( relativePresChange > m_maxRelativePresChange ) - { - presScalingFactor = m_maxRelativePresChange / relativePresChange; - } - } - m_pressureScalingFactor[ei] = presScalingFactor; - if( stack.localMinVal > presScalingFactor ) - { - stack.localMinVal = presScalingFactor; - } - if( stack.localMinPresScalingFactor > presScalingFactor ) - { - stack.localMinPresScalingFactor = presScalingFactor; - } + using Deriv = constitutive::multifluid::DerivativeOffset; - real64 prevTotalDens = 0; - for( integer ic = 0; ic < m_numComp; ++ic ) - { - prevTotalDens += m_compDens[ei][ic]; - } + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac = m_phaseVolFrac[ei]; + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; - m_compDensScalingFactor[ei] = 1.0; + real64 oneMinusPhaseVolFracSum = 1.0; - // compute the change in component densities and component fractions - for( integer ic = 0; ic < m_numComp; ++ic ) + // sum contributions to component accumulation from each phase + for( integer ip = 0; ip < m_numPhases; ++ip ) { - // compute scaling factor based on relative change in component densities - real64 const absCompDensChange = LvArray::math::abs( m_localSolution[stack.localRow + ic + 1] ); - if( stack.localMaxDeltaCompDens < absCompDensChange ) - { - stack.localMaxDeltaCompDens = absCompDensChange; - } - - // This actually checks the change in component fraction, using a lagged total density - // Indeed we can rewrite the following check as: - // | prevCompDens / prevTotalDens - newCompDens / prevTotalDens | > maxCompFracChange - // Note that the total density in the second term is lagged (i.e, we use prevTotalDens) - // because I found it more robust than using directly newTotalDens (which can vary also - // wildly when the compDens change is large) - real64 const maxAbsCompDensChange = m_maxCompFracChange * prevTotalDens; - if( absCompDensChange > maxAbsCompDensChange && absCompDensChange > eps ) - { - real64 const compScalingFactor = maxAbsCompDensChange / absCompDensChange; - m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor ); - if( stack.localMinVal > compScalingFactor ) - { - stack.localMinVal = compScalingFactor; - } - if( stack.localMinCompDensScalingFactor > compScalingFactor ) - { - stack.localMinCompDensScalingFactor = compScalingFactor; - } - } + oneMinusPhaseVolFracSum -= phaseVolFrac[ip]; + stack.localJacobian[numComp][0] -= dPhaseVolFrac[ip][Deriv::dP]; - // switch from relative to absolute when value is < 1.0 - real64 const maxRelCompDensChange = m_maxRelativeCompDensChange * LvArray::math::max( m_compDens[ei][ic], 1.0 ); - if( absCompDensChange > maxRelCompDensChange && absCompDensChange > eps ) + for( integer jc = 0; jc < numComp; ++jc ) { - real64 const compScalingFactor = maxRelCompDensChange / absCompDensChange; - m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor ); - if( stack.localMinVal > compScalingFactor ) - { - stack.localMinVal = compScalingFactor; - } - if( stack.localMinCompDensScalingFactor > compScalingFactor ) - { - stack.localMinCompDensScalingFactor = compScalingFactor; - } + stack.localJacobian[numComp][jc+1] -= dPhaseVolFrac[ip][Deriv::dC+jc]; } } - // compute the scaling factor for other vars, such as temperature - kernelOp(); - } - -protected: - - /// Max allowed changes in primary variables - real64 const m_maxRelativePresChange; - real64 const m_maxAbsolutePresChange; - real64 const m_maxCompFracChange; - real64 const m_maxRelativeCompDensChange; - -}; - -/** - * @class ScalingForSystemSolutionKernelFactory - */ -class ScalingForSystemSolutionKernelFactory -{ -public: - - /* - * @brief Create and launch the kernel computing the scaling factor - * @tparam POLICY the kernel policy - * @param[in] maxRelativePresChange the max allowed relative pressure change - * @param[in] maxAbsolutePresChange the max allowed absolute pressure change - * @param[in] maxCompFracChange the max allowed comp fraction change - * @param[in] maxRelativeCompDensChange the max allowed comp density change - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - * @return the scaling factor - */ - template< typename POLICY > - static ScalingForSystemSolutionKernel::StackVariables - createAndLaunch( real64 const maxRelativePresChange, - real64 const maxAbsolutePresChange, - real64 const maxCompFracChange, - real64 const maxRelativeCompDensChange, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase & subRegion, - arrayView1d< real64 const > const localSolution ) - { - arrayView1d< real64 const > const pressure = - subRegion.getField< fields::flow::pressure >(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = - subRegion.getField< fields::flow::globalCompDensity >(); - arrayView1d< real64 > pressureScalingFactor = - subRegion.getField< fields::flow::pressureScalingFactor >(); - arrayView1d< real64 > compDensScalingFactor = - subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); - ScalingForSystemSolutionKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset, - numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); - return ScalingForSystemSolutionKernel::launch< POLICY >( subRegion.size(), kernel ); - } -}; - -/******************************** SolutionCheckKernel ********************************/ - -/** - * @class SolutionCheckKernel - * @brief Define the kernel for checking the updated solution - */ -class SolutionCheckKernel : public ScalingAndCheckingSystemSolutionKernelBase< integer > -{ -public: - - using Base = ScalingAndCheckingSystemSolutionKernelBase< integer >; - using Base::m_rankOffset; - using Base::m_numComp; - using Base::m_dofNumber; - using Base::m_ghostRank; - using Base::m_localSolution; - using Base::m_pressure; - using Base::m_compDens; - - /** - * @brief Create a new kernel instance - * @param[in] allowCompDensChopping flag to allow the component density chopping - * @param[in] scalingFactor the scaling factor - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - * @param[in] pressure the pressure vector - * @param[in] compDens the component density vector - */ - SolutionCheckKernel( integer const allowCompDensChopping, - integer const allowNegativePressure, - CompositionalMultiphaseFVM::ScalingType const scalingType, - real64 const scalingFactor, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor ) - : Base( rankOffset, - numComp, - dofKey, - subRegion, - localSolution, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor ), - m_allowCompDensChopping( allowCompDensChopping ), - m_allowNegativePressure( allowNegativePressure ), - m_scalingFactor( scalingFactor ), - m_scalingType( scalingType ) - {} - - /** - * @struct StackVariables - * @brief Kernel variables located on the stack - */ - struct StackVariables : public Base::StackVariables - { - GEOS_HOST_DEVICE - StackVariables() - { } - - StackVariables( real64 _localMinVal, - real64 _localMinPres, - real64 _localMinDens, - real64 _localMinTotalDens, - integer _localNumNegPressures, - integer _localNumNegDens, - integer _localNumNegTotalDens ) - : - Base::StackVariables( _localMinVal ), - localMinPres( _localMinPres ), - localMinDens( _localMinDens ), - localMinTotalDens( _localMinTotalDens ), - localNumNegPressures( _localNumNegPressures ), - localNumNegDens( _localNumNegDens ), - localNumNegTotalDens( _localNumNegTotalDens ) - { } - - real64 localMinPres; - real64 localMinDens; - real64 localMinTotalDens; - - integer localNumNegPressures; - integer localNumNegDens; - integer localNumNegTotalDens; - - }; - - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numElems the number of elements - * @param[inout] kernelComponent the kernel component providing access to the compute function - */ - template< typename POLICY, typename KERNEL_TYPE > - static StackVariables - launch( localIndex const numElems, - KERNEL_TYPE const & kernelComponent ) - { - RAJA::ReduceMin< ReducePolicy< POLICY >, integer > globalMinVal( 1 ); - - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPres( 0.0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minDens( 0.0 ); - RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minTotalDens( 0.0 ); - - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegPressures( 0 ); - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegDens( 0 ); - RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegTotalDens( 0 ); + // call the lambda in the phase loop to allow the reuse of the phase amounts and their derivatives + // possible use: assemble the derivatives wrt temperature, and use oneMinusPhaseVolFracSum if poreVolume depends on temperature + phaseVolFractionSumKernelOp( oneMinusPhaseVolFracSum ); - forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + // scale saturation-based volume balance by pore volume (for better scaling w.r.t. other equations) + stack.localResidual[numComp] = stack.poreVolume * oneMinusPhaseVolFracSum; + for( integer idof = 0; idof < numDof; ++idof ) { - if( kernelComponent.ghostRank( ei ) >= 0 ) - { - return; - } - - StackVariables stack; - kernelComponent.setup( ei, stack ); - kernelComponent.compute( ei, stack ); - - globalMinVal.min( stack.localMinVal ); - - minPres.min( stack.localMinPres ); - minDens.min( stack.localMinDens ); - minTotalDens.min( stack.localMinTotalDens ); - - numNegPressures += stack.localNumNegPressures; - numNegDens += stack.localNumNegDens; - numNegTotalDens += stack.localNumNegTotalDens; - } ); - - return StackVariables( globalMinVal.get(), - minPres.get(), - minDens.get(), - minTotalDens.get(), - numNegPressures.get(), - numNegDens.get(), - numNegTotalDens.get() ); - } - - GEOS_HOST_DEVICE - void setup( localIndex const ei, - StackVariables & stack ) const - { - Base::setup( ei, stack ); - - stack.localMinPres = 0.0; - stack.localMinDens = 0.0; - stack.localMinTotalDens = 0.0; - - stack.localNumNegPressures = 0; - stack.localNumNegDens = 0; - stack.localNumNegTotalDens = 0; - } - - /** - * @brief Compute the local value - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void compute( localIndex const ei, - StackVariables & stack ) const - { - computeSolutionCheck( ei, stack ); + stack.localJacobian[numComp][idof] *= stack.poreVolume; + } + stack.localJacobian[numComp][0] += stack.dPoreVolume_dPres * oneMinusPhaseVolFracSum; } /** - * @brief Compute the local value of the check - * @tparam FUNC the type of the function that can be used to customize the kernel + * @brief Performs the complete phase for the kernel. * @param[in] ei the element index * @param[inout] stack the stack variables - * @param[in] kernelOp the function used to customize the kernel */ - template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE - void computeSolutionCheck( localIndex const ei, - StackVariables & stack, - FUNC && kernelOp = NoOpFunc{} ) const + void complete( localIndex const GEOS_UNUSED_PARAM( ei ), + StackVariables & stack ) const { - bool const localScaling = m_scalingType == CompositionalMultiphaseFVM::ScalingType::Local; + using namespace compositionalMultiphaseUtilities; - real64 const newPres = m_pressure[ei] + (localScaling ? m_pressureScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow]; - if( newPres < 0 ) + if( m_kernelFlags.isSet( AccumulationKernelFlags::TotalMassEquation ) ) { - if( !m_allowNegativePressure ) - { - stack.localMinVal = 0; - } - stack.localNumNegPressures += 1; - if( newPres < stack.localMinPres ) - stack.localMinPres = newPres; + // apply equation/variable change transformation to the component mass balance equations + real64 work[numDof]{}; + shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numDof, stack.localJacobian, work ); + shiftElementsAheadByOneAndReplaceFirstElementWithSum( numComp, stack.localResidual ); } - // if component density chopping is not allowed, the time step fails if a component density is negative - // otherwise, we just check that the total density is positive, and negative component densities - // will be chopped (i.e., set to zero) in ApplySystemSolution) - if( !m_allowCompDensChopping ) - { - for( integer ic = 0; ic < m_numComp; ++ic ) - { - real64 const newDens = m_compDens[ei][ic] + (localScaling ? m_compDensScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow + ic + 1]; - if( newDens < 0 ) - { - stack.localMinVal = 0; - stack.localNumNegDens += 1; - if( newDens < stack.localMinDens ) - stack.localMinDens = newDens; - } - } - } - else + // add contribution to residual and jacobian into: + // - the component mass balance equations (i = 0 to i = numComp-1) + // - the volume balance equations (i = numComp) + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + integer const numRows = numComp+1; + for( integer i = 0; i < numRows; ++i ) { - real64 totalDens = 0.0; - for( integer ic = 0; ic < m_numComp; ++ic ) - { - real64 const newDens = m_compDens[ei][ic] + (localScaling ? m_compDensScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow + ic + 1]; - totalDens += ( newDens > 0.0 ) ? newDens : 0.0; - } - if( totalDens < 0 ) - { - stack.localMinVal = 0; - stack.localNumNegTotalDens += 1; - if( totalDens < stack.localMinTotalDens ) - stack.localMinTotalDens = totalDens; - } + m_localRhs[stack.localRow + i] += stack.localResidual[i]; + m_localMatrix.addToRow< serialAtomic >( stack.localRow + i, + stack.dofIndices, + stack.localJacobian[i], + numDof ); } - - kernelOp(); } -protected: - - /// flag to allow the component density chopping - integer const m_allowCompDensChopping; - - /// flag to allow negative pressure values - integer const m_allowNegativePressure; - - /// scaling factor - real64 const m_scalingFactor; - - /// scaling type (global or local) - CompositionalMultiphaseFVM::ScalingType const m_scalingType; - -}; - -/** - * @class SolutionCheckKernelFactory - */ -class SolutionCheckKernelFactory -{ -public: - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] allowCompDensChopping flag to allow the component density chopping - * @param[in] scalingFactor the scaling factor - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables */ - template< typename POLICY > - static SolutionCheckKernel::StackVariables - createAndLaunch( integer const allowCompDensChopping, - integer const allowNegativePressure, - CompositionalMultiphaseFVM::ScalingType const scalingType, - real64 const scalingFactor, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase & subRegion, - arrayView1d< real64 const > const localSolution ) - { - arrayView1d< real64 const > const pressure = - subRegion.getField< fields::flow::pressure >(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = - subRegion.getField< fields::flow::globalCompDensity >(); - arrayView1d< real64 > pressureScalingFactor = - subRegion.getField< fields::flow::pressureScalingFactor >(); - arrayView1d< real64 > compDensScalingFactor = - subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); - SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, rankOffset, - numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); - return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); - } - -}; - -/******************************** ResidualNormKernel ********************************/ - -/** - * @class ResidualNormKernel - */ -class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > -{ -public: - - using Base = solverBaseKernels::ResidualNormKernelBase< 1 >; - using Base::m_minNormalizer; - using Base::m_rankOffset; - using Base::m_localResidual; - using Base::m_dofNumber; - - ResidualNormKernel( globalIndex const rankOffset, - arrayView1d< real64 const > const & localResidual, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< localIndex const > const & ghostRank, - integer const numComponents, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - real64 const minNormalizer ) - : Base( rankOffset, - localResidual, - dofNumber, - ghostRank, - minNormalizer ), - m_numComponents( numComponents ), - m_volume( subRegion.getElementVolume() ), - m_porosity_n( solid.getPorosity_n() ), - m_totalDens_n( fluid.totalDensity_n() ) - {} - - GEOS_HOST_DEVICE - virtual void computeLinf( localIndex const ei, - LinfStackVariables & stack ) const override + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) { - // this should never be zero if the simulation is set up correctly, but we never know - real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_totalDens_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ); - real64 const volumeNormalizer = LvArray::math::max( m_minNormalizer, m_porosity_n[ei][0] * m_volume[ei] ); - - // step 1: mass residuals + GEOS_MARK_FUNCTION; - for( integer idof = 0; idof < m_numComponents; ++idof ) + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) { - real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow + idof] ) / massNormalizer; - if( valMass > stack.localValue[0] ) + if( kernelComponent.elemGhostRank( ei ) >= 0 ) { - stack.localValue[0] = valMass; + return; } - } - // step 2: volume residual + typename KERNEL_TYPE::StackVariables stack; - real64 const valVol = LvArray::math::abs( m_localResidual[stack.localRow + m_numComponents] ) / volumeNormalizer; - if( valVol > stack.localValue[0] ) - { - stack.localValue[0] = valVol; - } + kernelComponent.setup( ei, stack ); + kernelComponent.computeAccumulation( ei, stack ); + kernelComponent.computeVolumeBalance( ei, stack ); + kernelComponent.complete( ei, stack ); + } ); } - GEOS_HOST_DEVICE - virtual void computeL2( localIndex const ei, - L2StackVariables & stack ) const override - { - // note: for the L2 norm, we bundle the volume and mass residuals/normalizers +protected: + + /// Number of fluid phases + integer const m_numPhases; - real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_totalDens_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ); + /// Offset for my MPI rank + globalIndex const m_rankOffset; - // step 1: mass residuals + /// View on the dof numbers + arrayView1d< globalIndex const > const m_dofNumber; - for( integer idof = 0; idof < m_numComponents; ++idof ) - { - stack.localValue[0] += m_localResidual[stack.localRow + idof] * m_localResidual[stack.localRow + idof]; - stack.localNormalizer[0] += massNormalizer; - } + /// View on the ghost ranks + arrayView1d< integer const > const m_elemGhostRank; - // step 2: volume residual + /// View on the element volumes + arrayView1d< real64 const > const m_volume; - real64 const val = m_localResidual[stack.localRow + m_numComponents] * m_totalDens_n[ei][0]; // we need a mass here, hence the - // multiplication - stack.localValue[0] += val * val; - stack.localNormalizer[0] += massNormalizer; - } + /// Views on the porosity + arrayView2d< real64 const > const m_porosity; + arrayView2d< real64 const > const m_dPoro_dPres; + + /// Views on the derivatives of comp fractions wrt component density + arrayView3d< real64 const, compflow::USD_COMP_DC > const m_dCompFrac_dCompDens; + /// Views on the phase volume fractions + arrayView2d< real64 const, compflow::USD_PHASE > const m_phaseVolFrac; + arrayView3d< real64 const, compflow::USD_PHASE_DC > const m_dPhaseVolFrac; -protected: + /// Views on the phase densities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseDens; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseDens; - /// Number of fluid coponents - integer const m_numComponents; + /// Views on the phase component fraction + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > const m_phaseCompFrac; + arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > const m_dPhaseCompFrac; - /// View on the volume - arrayView1d< real64 const > const m_volume; + // View on component densities + arrayView2d< real64 const, compflow::USD_COMP > m_compDens; - /// View on porosity at the previous converged time step - arrayView2d< real64 const > const m_porosity_n; + // View on component amount (mass/moles) from previous time step + arrayView2d< real64 const, compflow::USD_COMP > m_compAmount_n; - /// View on total mass/molar density at the previous converged time step - arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const m_totalDens_n; + /// View on the local CRS matrix + CRSMatrixView< real64, globalIndex const > const m_localMatrix; + /// View on the local RHS + arrayView1d< real64 > const m_localRhs; + BitFlags< AccumulationKernelFlags > const m_kernelFlags; }; /** - * @class ResidualNormKernelFactory + * @class ElementBasedAssemblyKernelFactory */ -class ResidualNormKernelFactory +class ElementBasedAssemblyKernelFactory { public: /** * @brief Create a new kernel and launch * @tparam POLICY the policy used in the RAJA kernel - * @param[in] normType the type of norm used (Linf or L2) * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases * @param[in] rankOffset the offset of my MPI rank * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] localResidual the residual vector on my MPI rank * @param[in] subRegion the element subregion * @param[in] fluid the fluid model * @param[in] solid the solid model - * @param[out] residualNorm the residual norm on the subRegion - * @param[out] residualNormalizer the residual normalizer on the subRegion + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector */ template< typename POLICY > static void - createAndLaunch( solverBaseKernels::NormType const normType, - integer const numComps, + createAndLaunch( integer const numComps, + integer const numPhases, globalIndex const rankOffset, + integer const useTotalMassEquation, + integer const useSimpleAccumulation, string const dofKey, - arrayView1d< real64 const > const & localResidual, ElementSubRegionBase const & subRegion, constitutive::MultiFluidBase const & fluid, constitutive::CoupledSolidBase const & solid, - real64 const minNormalizer, - real64 (& residualNorm)[1], - real64 (& residualNormalizer)[1] ) - { - arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); - arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - - ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, numComps, subRegion, fluid, solid, minNormalizer ); - if( normType == solverBaseKernels::NormType::Linf ) - { - ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); - } - else // L2 norm - { - ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); - } - } - -}; - -/******************************** StatisticsKernel ********************************/ - -struct StatisticsKernel -{ - template< typename POLICY > - static void - saveDeltaPressure( localIndex const size, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & initPres, - arrayView1d< real64 > const & deltaPres ) - { - forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - deltaPres[ei] = pres[ei] - initPres[ei]; - } ); - } - - template< typename POLICY > - static void - launch( localIndex const size, - integer const numComps, - integer const numPhases, - real64 const relpermThreshold, - arrayView1d< integer const > const & elemGhostRank, - arrayView1d< real64 const > const & volume, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & deltaPres, - arrayView1d< real64 const > const & temp, - arrayView1d< real64 const > const & refPorosity, - arrayView2d< real64 const > const & porosity, - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const & phaseDensity, - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > const & phaseCompFraction, - arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac, - arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > const & phaseTrappedVolFrac, - arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > const & phaseRelperm, - real64 & minPres, - real64 & avgPresNumerator, - real64 & maxPres, - real64 & minDeltaPres, - real64 & maxDeltaPres, - real64 & minTemp, - real64 & avgTempNumerator, - real64 & maxTemp, - real64 & totalUncompactedPoreVol, - arrayView1d< real64 > const & phaseDynamicPoreVol, - arrayView1d< real64 > const & phaseMass, - arrayView1d< real64 > const & trappedPhaseMass, - arrayView1d< real64 > const & immobilePhaseMass, - arrayView2d< real64 > const & dissolvedComponentMass ) - { - RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinPres( LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgPresNumerator( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPres( -LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinDeltaPres( LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxDeltaPres( -LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinTemp( LvArray::NumericLimits< real64 >::max ); - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgTempNumerator( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTemp( 0.0 ); - RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalUncompactedPoreVol( 0.0 ); - - // For this arrays phaseDynamicPoreVol, phaseMass, dissolvedComponentMass, - // using an array of ReduceSum leads to a formal parameter overflow in CUDA. - // As a workaround, we use a slice with RAJA::atomicAdd instead - - forAll< parallelDevicePolicy<> >( size, [numComps, - numPhases, - relpermThreshold, - elemGhostRank, - volume, - refPorosity, - porosity, - pres, - deltaPres, - temp, - phaseDensity, - phaseVolFrac, - phaseTrappedVolFrac, - phaseRelperm, - phaseCompFraction, - subRegionMinPres, - subRegionAvgPresNumerator, - subRegionMaxPres, - subRegionMinDeltaPres, - subRegionMaxDeltaPres, - subRegionMinTemp, - subRegionAvgTempNumerator, - subRegionMaxTemp, - subRegionTotalUncompactedPoreVol, - phaseDynamicPoreVol, - phaseMass, - trappedPhaseMass, - immobilePhaseMass, - dissolvedComponentMass] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( elemGhostRank[ei] >= 0 ) - { - return; - } - - // To match our "reference", we have to use reference porosity here, not the actual porosity when we compute averages - real64 const uncompactedPoreVol = volume[ei] * refPorosity[ei]; - real64 const dynamicPoreVol = volume[ei] * porosity[ei][0]; - - subRegionMinPres.min( pres[ei] ); - subRegionAvgPresNumerator += uncompactedPoreVol * pres[ei]; - subRegionMaxPres.max( pres[ei] ); - - subRegionMaxDeltaPres.max( deltaPres[ei] ); - subRegionMinDeltaPres.min( deltaPres[ei] ); - - subRegionMinTemp.min( temp[ei] ); - subRegionAvgTempNumerator += uncompactedPoreVol * temp[ei]; - subRegionMaxTemp.max( temp[ei] ); - subRegionTotalUncompactedPoreVol += uncompactedPoreVol; - for( integer ip = 0; ip < numPhases; ++ip ) - { - real64 const elemPhaseVolume = dynamicPoreVol * phaseVolFrac[ei][ip]; - real64 const elemPhaseMass = phaseDensity[ei][0][ip] * elemPhaseVolume; - real64 const elemTrappedPhaseMass = phaseDensity[ei][0][ip] * dynamicPoreVol * phaseTrappedVolFrac[ei][0][ip]; - // RAJA::atomicAdd used here because we do not use ReduceSum here (for the reason explained above) - RAJA::atomicAdd( parallelDeviceAtomic{}, &phaseDynamicPoreVol[ip], elemPhaseVolume ); - RAJA::atomicAdd( parallelDeviceAtomic{}, &phaseMass[ip], elemPhaseMass ); - RAJA::atomicAdd( parallelDeviceAtomic{}, &trappedPhaseMass[ip], elemTrappedPhaseMass ); - if( phaseRelperm[ei][0][ip] < relpermThreshold ) - { - RAJA::atomicAdd( parallelDeviceAtomic{}, &immobilePhaseMass[ip], elemPhaseMass ); - } - for( integer ic = 0; ic < numComps; ++ic ) - { - // RAJA::atomicAdd used here because we do not use ReduceSum here (for the reason explained above) - RAJA::atomicAdd( parallelDeviceAtomic{}, &dissolvedComponentMass[ip][ic], phaseCompFraction[ei][0][ip][ic] * elemPhaseMass ); - } - } - - } ); - - minPres = subRegionMinPres.get(); - avgPresNumerator = subRegionAvgPresNumerator.get(); - maxPres = subRegionMaxPres.get(); - minDeltaPres = subRegionMinDeltaPres.get(); - maxDeltaPres = subRegionMaxDeltaPres.get(); - minTemp = subRegionMinTemp.get(); - avgTempNumerator = subRegionAvgTempNumerator.get(); - maxTemp = subRegionMaxTemp.get(); - totalUncompactedPoreVol = subRegionTotalUncompactedPoreVol.get(); - - // dummy loop to bring data back to the CPU - forAll< serialPolicy >( 1, [phaseDynamicPoreVol, phaseMass, trappedPhaseMass, immobilePhaseMass, dissolvedComponentMass] ( localIndex const ) - { - GEOS_UNUSED_VAR( phaseDynamicPoreVol, phaseMass, trappedPhaseMass, immobilePhaseMass, dissolvedComponentMass ); - } ); - } -}; - -/******************************** HydrostaticPressureKernel ********************************/ - -struct HydrostaticPressureKernel -{ - - // TODO: this type of constants should be centralized somewhere or provided by fluid model - static real64 constexpr MIN_FOR_PHASE_PRESENCE = 1e-12; - - enum class ReturnType : integer - { - FAILED_TO_CONVERGE = 0, - DETECTED_MULTIPHASE_FLOW = 1, - SUCCESS = 2 - }; - - template< typename FLUID_WRAPPER > - static ReturnType - computeHydrostaticPressure( integer const numComps, - integer const numPhases, - integer const ipInit, - integer const maxNumEquilIterations, - real64 const & equilTolerance, - real64 const (&gravVector)[ 3 ], - FLUID_WRAPPER fluidWrapper, - arrayView1d< TableFunction::KernelWrapper const > compFracTableWrappers, - TableFunction::KernelWrapper tempTableWrapper, - real64 const & refElevation, - real64 const & refPres, - arraySlice1d< real64 const > const & refPhaseMassDens, - real64 const & newElevation, - real64 & newPres, - arraySlice1d< real64 > const & newPhaseMassDens ) - { - // fluid properties at this elevation - StackArray< real64, 2, constitutive::MultiFluidBase::MAX_NUM_COMPONENTS, compflow::LAYOUT_COMP > compFrac( 1, numComps ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseFrac( 1, 1, numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseDens( 1, 1, numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseMassDens( 1, 1, numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseVisc( 1, 1, numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseEnthalpy( 1, 1, numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > phaseInternalEnergy( 1, 1, numPhases ); - StackArray< real64, 4, constitutive::MultiFluidBase::MAX_NUM_PHASES *constitutive::MultiFluidBase::MAX_NUM_COMPONENTS, - constitutive::multifluid::LAYOUT_PHASE_COMP > phaseCompFrac( 1, 1, numPhases, numComps ); - real64 totalDens = 0.0; - - bool isSinglePhaseFlow = true; - - // Step 1: compute the hydrostatic pressure at the current elevation - - real64 const gravCoef = gravVector[2] * ( refElevation - newElevation ); - real64 const temp = tempTableWrapper.compute( &newElevation ); - for( integer ic = 0; ic < numComps; ++ic ) - { - compFrac[0][ic] = compFracTableWrappers[ic].compute( &newElevation ); - } - - // Step 2: guess the pressure with the refPhaseMassDensity - - real64 pres0 = refPres - refPhaseMassDens[ipInit] * gravCoef; - real64 pres1 = 0.0; - - // Step 3: compute the mass density at this elevation using the guess, and update pressure - - constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper, - pres0, - temp, - compFrac[0], - phaseFrac[0][0], - phaseDens[0][0], - phaseMassDens[0][0], - phaseVisc[0][0], - phaseEnthalpy[0][0], - phaseInternalEnergy[0][0], - phaseCompFrac[0][0], - totalDens ); - pres1 = refPres - 0.5 * ( refPhaseMassDens[ipInit] + phaseMassDens[0][0][ipInit] ) * gravCoef; - - // Step 4: fixed-point iteration until convergence - - bool equilHasConverged = false; - for( integer eqIter = 0; eqIter < maxNumEquilIterations; ++eqIter ) - { - - // check convergence - equilHasConverged = ( LvArray::math::abs( pres0 - pres1 ) < equilTolerance ); - pres0 = pres1; - - // if converged, check number of phases and move on - if( equilHasConverged ) - { - // make sure that the fluid is single-phase, other we have to issue a warning (for now) - // if only one phase is mobile, we are in good shape (unfortunately it is hard to access relperm from here) - localIndex numberOfPhases = 0; - for( integer ip = 0; ip < numPhases; ++ip ) - { - if( phaseFrac[0][0][ip] > MIN_FOR_PHASE_PRESENCE ) - { - numberOfPhases++; - } - } - if( numberOfPhases > 1 ) - { - isSinglePhaseFlow = false; - } - - break; - } - - // compute the mass density at this elevation using the previous pressure, and compute the new pressure - constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper, - pres0, - temp, - compFrac[0], - phaseFrac[0][0], - phaseDens[0][0], - phaseMassDens[0][0], - phaseVisc[0][0], - phaseEnthalpy[0][0], - phaseInternalEnergy[0][0], - phaseCompFrac[0][0], - totalDens ); - pres1 = refPres - 0.5 * ( refPhaseMassDens[ipInit] + phaseMassDens[0][0][ipInit] ) * gravCoef; - } - - // Step 5: save the hydrostatic pressure and the corresponding density - - newPres = pres1; - for( integer ip = 0; ip < numPhases; ++ip ) - { - newPhaseMassDens[ip] = phaseMassDens[0][0][ip]; - } - - if( !equilHasConverged ) - { - return ReturnType::FAILED_TO_CONVERGE; - } - else if( !isSinglePhaseFlow ) - { - return ReturnType::DETECTED_MULTIPHASE_FLOW; - } - else - { - return ReturnType::SUCCESS; - } - } - - template< typename FLUID_WRAPPER > - static ReturnType - launch( localIndex const size, - integer const numComps, - integer const numPhases, - integer const ipInit, - integer const maxNumEquilIterations, - real64 const equilTolerance, - real64 const (&gravVector)[ 3 ], - real64 const & minElevation, - real64 const & elevationIncrement, - real64 const & datumElevation, - real64 const & datumPres, - FLUID_WRAPPER fluidWrapper, - arrayView1d< TableFunction::KernelWrapper const > compFracTableWrappers, - TableFunction::KernelWrapper tempTableWrapper, - arrayView1d< arrayView1d< real64 > const > elevationValues, - arrayView1d< real64 > pressureValues ) + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) { - - ReturnType returnVal = ReturnType::SUCCESS; - - // Step 1: compute the phase mass densities at datum - - // datum fluid properties - array2d< real64, compflow::LAYOUT_COMP > datumCompFrac( 1, numComps ); - array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseFrac( 1, 1, numPhases ); - array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseDens( 1, 1, numPhases ); - array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseMassDens( 1, 1, numPhases ); - array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseVisc( 1, 1, numPhases ); - array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseEnthalpy( 1, 1, numPhases ); - array3d< real64, constitutive::multifluid::LAYOUT_PHASE > datumPhaseInternalEnergy( 1, 1, numPhases ); - array4d< real64, constitutive::multifluid::LAYOUT_PHASE_COMP > datumPhaseCompFrac( 1, 1, numPhases, numComps ); - real64 datumTotalDens = 0.0; - - real64 const datumTemp = tempTableWrapper.compute( &datumElevation ); - for( integer ic = 0; ic < numComps; ++ic ) - { - datumCompFrac[0][ic] = compFracTableWrappers[ic].compute( &datumElevation ); - } - constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper, - datumPres, - datumTemp, - datumCompFrac[0], - datumPhaseFrac[0][0], - datumPhaseDens[0][0], - datumPhaseMassDens[0][0], - datumPhaseVisc[0][0], - datumPhaseEnthalpy[0][0], - datumPhaseInternalEnergy[0][0], - datumPhaseCompFrac[0][0], - datumTotalDens ); - - // Step 2: find the closest elevation to datumElevation - - forAll< parallelHostPolicy >( size, [=] ( localIndex const i ) - { - real64 const elevation = minElevation + i * elevationIncrement; - elevationValues[0][i] = elevation; - } ); - integer const iRef = LvArray::sortedArrayManipulation::find( elevationValues[0].begin(), - elevationValues[0].size(), - datumElevation ); - - // Step 3: compute the mass density and pressure at the reference elevation - - array2d< real64 > phaseMassDens( pressureValues.size(), numPhases ); - // temporary array without permutation to compile on Lassen - array1d< real64 > datumPhaseMassDensTmp( numPhases ); - for( integer ip = 0; ip < numPhases; ++ip ) - { - datumPhaseMassDensTmp[ip] = datumPhaseMassDens[0][0][ip]; - } - - ReturnType const refReturnVal = - computeHydrostaticPressure( numComps, - numPhases, - ipInit, - maxNumEquilIterations, - equilTolerance, - gravVector, - fluidWrapper, - compFracTableWrappers, - tempTableWrapper, - datumElevation, - datumPres, - datumPhaseMassDensTmp, - elevationValues[0][iRef], - pressureValues[iRef], - phaseMassDens[iRef] ); - if( refReturnVal == ReturnType::FAILED_TO_CONVERGE ) - { - return ReturnType::FAILED_TO_CONVERGE; - } - else if( refReturnVal == ReturnType::DETECTED_MULTIPHASE_FLOW ) - { - returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW; - } - - // Step 4: for each elevation above the reference elevation, compute the pressure - - localIndex const numEntriesAboveRef = size - iRef - 1; - forAll< serialPolicy >( numEntriesAboveRef, [=, &returnVal] ( localIndex const i ) + internal::kernelLaunchSelectorCompSwitch( numComps, [&] ( auto NC ) { - ReturnType const returnValAboveRef = - computeHydrostaticPressure( numComps, - numPhases, - ipInit, - maxNumEquilIterations, - equilTolerance, - gravVector, - fluidWrapper, - compFracTableWrappers, - tempTableWrapper, - elevationValues[0][iRef+i], - pressureValues[iRef+i], - phaseMassDens[iRef+i], - elevationValues[0][iRef+i+1], - pressureValues[iRef+i+1], - phaseMassDens[iRef+i+1] ); - if( returnValAboveRef == ReturnType::FAILED_TO_CONVERGE ) - { - returnVal = ReturnType::FAILED_TO_CONVERGE; - } - else if( ( returnValAboveRef == ReturnType::DETECTED_MULTIPHASE_FLOW ) && - ( returnVal != ReturnType::FAILED_TO_CONVERGE ) ) - { - returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW; - } - - } ); - - // Step 5: for each elevation below the reference elevation, compute the pressure + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC()+1; - localIndex const numEntriesBelowRef = iRef; - forAll< serialPolicy >( numEntriesBelowRef, [=, &returnVal] ( localIndex const i ) - { - ReturnType const returnValBelowRef = - computeHydrostaticPressure( numComps, - numPhases, - ipInit, - maxNumEquilIterations, - equilTolerance, - gravVector, - fluidWrapper, - compFracTableWrappers, - tempTableWrapper, - elevationValues[0][iRef-i], - pressureValues[iRef-i], - phaseMassDens[iRef-i], - elevationValues[0][iRef-i-1], - pressureValues[iRef-i-1], - phaseMassDens[iRef-i-1] ); - if( returnValBelowRef == ReturnType::FAILED_TO_CONVERGE ) - { - returnVal = ReturnType::FAILED_TO_CONVERGE; - } - else if( ( returnValBelowRef == ReturnType::DETECTED_MULTIPHASE_FLOW ) && - ( returnVal != ReturnType::FAILED_TO_CONVERGE ) ) - { - returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW; - } + BitFlags< AccumulationKernelFlags > kernelFlags; + if( useTotalMassEquation ) + kernelFlags.set( AccumulationKernelFlags::TotalMassEquation ); + if( useSimpleAccumulation ) + kernelFlags.set( AccumulationKernelFlags::SimpleAccumulation ); + ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF > + kernel( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ); + ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); } ); - - return returnVal; } }; - -/******************************** Kernel launch machinery ********************************/ - -template< typename KERNELWRAPPER, typename ... ARGS > -void KernelLaunchSelector1( integer const numComp, ARGS && ... args ) -{ - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - KERNELWRAPPER::template launch< NC() >( std::forward< ARGS >( args )... ); - } ); -} - -template< typename KERNELWRAPPER, typename ... ARGS > -void KernelLaunchSelector2( integer const numComp, integer const numPhase, ARGS && ... args ) -{ - // Ideally this would be inside the dispatch, but it breaks on Summit with GCC 9.1.0 and CUDA 11.0.3. - if( numPhase == 2 ) - { - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - KERNELWRAPPER::template launch< NC(), 2 >( std::forward< ARGS >( args ) ... ); - } ); - } - else if( numPhase == 3 ) - { - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - KERNELWRAPPER::template launch< NC(), 3 >( std::forward< ARGS >( args ) ... ); - } ); - } - else - { - GEOS_ERROR( "Unsupported number of phases: " << numPhase ); - } -} - } // namespace isothermalCompositionalMultiphaseBaseKernels } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp index 16bca0cc8cf..af484124b75 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp @@ -73,212 +73,6 @@ enum class FaceBasedAssemblyKernelFlags // Flag8 = 1 << 7 //128 }; -/******************************** PhaseMobilityKernel ********************************/ - -/** - * @class PhaseMobilityKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_PHASE number of fluid phases - * @brief Define the interface for the property kernel in charge of computing the phase mobilities - */ -template< integer NUM_COMP, integer NUM_PHASE > -class PhaseMobilityKernel : public isothermalCompositionalMultiphaseBaseKernels::PropertyKernelBase< NUM_COMP > -{ -public: - - using Base = isothermalCompositionalMultiphaseBaseKernels::PropertyKernelBase< NUM_COMP >; - using Base::numComp; - - /// Compile time value for the number of phases - static constexpr integer numPhase = NUM_PHASE; - - /** - * @brief Constructor - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] relperm the relperm model - */ - PhaseMobilityKernel( ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::RelativePermeabilityBase const & relperm ) - : Base(), - m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), - m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), - m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), - m_phaseDens( fluid.phaseDensity() ), - m_dPhaseDens( fluid.dPhaseDensity() ), - m_phaseVisc( fluid.phaseViscosity() ), - m_dPhaseVisc( fluid.dPhaseViscosity() ), - m_phaseRelPerm( relperm.phaseRelPerm() ), - m_dPhaseRelPerm_dPhaseVolFrac( relperm.dPhaseRelPerm_dPhaseVolFraction() ), - m_phaseMob( subRegion.getField< fields::flow::phaseMobility >() ), - m_dPhaseMob( subRegion.getField< fields::flow::dPhaseMobility >() ) - {} - - /** - * @brief Compute the phase mobilities in an element - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[in] phaseMobilityKernelOp the function used to customize the kernel - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void compute( localIndex const ei, - FUNC && phaseMobilityKernelOp = NoOpFunc{} ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseVisc = m_phaseVisc[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseVisc = m_dPhaseVisc[ei][0]; - arraySlice1d< real64 const, constitutive::relperm::USD_RELPERM - 2 > const phaseRelPerm = m_phaseRelPerm[ei][0]; - arraySlice2d< real64 const, constitutive::relperm::USD_RELPERM_DS - 2 > const dPhaseRelPerm_dPhaseVolFrac = m_dPhaseRelPerm_dPhaseVolFrac[ei][0]; - arraySlice1d< real64 const, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; - arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseMob = m_phaseMob[ei]; - arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseMob = m_dPhaseMob[ei]; - - real64 dRelPerm_dC[numComp]{}; - real64 dDens_dC[numComp]{}; - real64 dVisc_dC[numComp]{}; - - for( integer ip = 0; ip < numPhase; ++ip ) - { - - // compute the phase mobility only if the phase is present - bool const phaseExists = (phaseVolFrac[ip] > 0); - if( !phaseExists ) - { - phaseMob[ip] = 0.0; - for( integer jc = 0; jc < numComp + 2; ++jc ) - { - dPhaseMob[ip][jc] = 0.0; - } - continue; - } - - real64 const density = phaseDens[ip]; - real64 const dDens_dP = dPhaseDens[ip][Deriv::dP]; - applyChainRule( numComp, dCompFrac_dCompDens, dPhaseDens[ip], dDens_dC, Deriv::dC ); - - real64 const viscosity = phaseVisc[ip]; - real64 const dVisc_dP = dPhaseVisc[ip][Deriv::dP]; - applyChainRule( numComp, dCompFrac_dCompDens, dPhaseVisc[ip], dVisc_dC, Deriv::dC ); - - real64 const relPerm = phaseRelPerm[ip]; - real64 dRelPerm_dP = 0.0; - for( integer ic = 0; ic < numComp; ++ic ) - { - dRelPerm_dC[ic] = 0.0; - } - - for( integer jp = 0; jp < numPhase; ++jp ) - { - real64 const dRelPerm_dS = dPhaseRelPerm_dPhaseVolFrac[ip][jp]; - dRelPerm_dP += dRelPerm_dS * dPhaseVolFrac[jp][Deriv::dP]; - - for( integer jc = 0; jc < numComp; ++jc ) - { - dRelPerm_dC[jc] += dRelPerm_dS * dPhaseVolFrac[jp][Deriv::dC+jc]; - } - } - - real64 const mobility = relPerm * density / viscosity; - - phaseMob[ip] = mobility; - dPhaseMob[ip][Deriv::dP] = dRelPerm_dP * density / viscosity - + mobility * (dDens_dP / density - dVisc_dP / viscosity); - - // compositional derivatives - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseMob[ip][Deriv::dC+jc] = dRelPerm_dC[jc] * density / viscosity - + mobility * (dDens_dC[jc] / density - dVisc_dC[jc] / viscosity); - } - - // call the lambda in the phase loop to allow the reuse of the relperm, density, viscosity, and mobility - // possible use: assemble the derivatives wrt temperature - phaseMobilityKernelOp( ip, phaseMob[ip], dPhaseMob[ip] ); - } - } - -protected: - - // inputs - - /// Views on the phase volume fractions - arrayView2d< real64 const, compflow::USD_PHASE > m_phaseVolFrac; - arrayView3d< real64 const, compflow::USD_PHASE_DC > m_dPhaseVolFrac; - arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; - - /// Views on the phase densities - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseDens; - - /// Views on the phase viscosities - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseVisc; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseVisc; - - /// Views on the phase relative permeabilities - arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > m_phaseRelPerm; - arrayView4d< real64 const, constitutive::relperm::USD_RELPERM_DS > m_dPhaseRelPerm_dPhaseVolFrac; - - // outputs - - /// Views on the phase mobilities - arrayView2d< real64, compflow::USD_PHASE > m_phaseMob; - arrayView3d< real64, compflow::USD_PHASE_DC > m_dPhaseMob; - -}; - -/** - * @class PhaseMobilityKernelFactory - */ -class PhaseMobilityKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComp the number of fluid components - * @param[in] numPhase the number of fluid phases - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] relperm the relperm model - */ - template< typename POLICY > - static void - createAndLaunch( integer const numComp, - integer const numPhase, - ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::RelativePermeabilityBase const & relperm ) - { - if( numPhase == 2 ) - { - isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseMobilityKernel< NUM_COMP, 2 > kernel( subRegion, fluid, relperm ); - PhaseMobilityKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - else if( numPhase == 3 ) - { - isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseMobilityKernel< NUM_COMP, 3 > kernel( subRegion, fluid, relperm ); - PhaseMobilityKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - } -}; - - /******************************** FaceBasedAssemblyKernel ********************************/ /** diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp new file mode 100644 index 00000000000..21982d01284 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp @@ -0,0 +1,111 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 KernelLaunchSelector.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_KERNELLAUNCHSELECTOR_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_KERNELLAUNCHSELECTOR_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "functions/TableFunction.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** Kernel launch machinery ********************************/ + +namespace internal +{ + +template< typename T, typename LAMBDA > +void kernelLaunchSelectorCompSwitch( T value, LAMBDA && lambda ) +{ + static_assert( std::is_integral< T >::value, "kernelLaunchSelectorCompSwitch: type should be integral" ); + + switch( value ) + { + case 1: + { lambda( std::integral_constant< T, 1 >() ); return; } + case 2: + { lambda( std::integral_constant< T, 2 >() ); return; } + case 3: + { lambda( std::integral_constant< T, 3 >() ); return; } + case 4: + { lambda( std::integral_constant< T, 4 >() ); return; } + case 5: + { lambda( std::integral_constant< T, 5 >() ); return; } + default: + { GEOS_ERROR( "Unsupported number of components: " << value ); } + } +} + +} // namespace internal + +template< typename KERNELWRAPPER, typename ... ARGS > +void KernelLaunchSelector1( integer const numComp, ARGS && ... args ) +{ + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + KERNELWRAPPER::template launch< NC() >( std::forward< ARGS >( args )... ); + } ); +} + +template< typename KERNELWRAPPER, typename ... ARGS > +void KernelLaunchSelector2( integer const numComp, integer const numPhase, ARGS && ... args ) +{ + // Ideally this would be inside the dispatch, but it breaks on Summit with GCC 9.1.0 and CUDA 11.0.3. + if( numPhase == 2 ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + KERNELWRAPPER::template launch< NC(), 2 >( std::forward< ARGS >( args ) ... ); + } ); + } + else if( numPhase == 3 ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + KERNELWRAPPER::template launch< NC(), 3 >( std::forward< ARGS >( args ) ... ); + } ); + } + else + { + GEOS_ERROR( "Unsupported number of phases: " << numPhase ); + } +} + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_KERNELLAUNCHSELECTOR_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp new file mode 100644 index 00000000000..450cfff1ba3 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp @@ -0,0 +1,241 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PhaseMobilityKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEMOBILITYKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEMOBILITYKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** PhaseMobilityKernel ********************************/ + +/** + * @class PhaseMobilityKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_PHASE number of fluid phases + * @brief Define the interface for the property kernel in charge of computing the phase mobilities + */ +template< integer NUM_COMP, integer NUM_PHASE > +class PhaseMobilityKernel : public isothermalCompositionalMultiphaseBaseKernels::PropertyKernelBase< NUM_COMP > +{ +public: + + using Base = isothermalCompositionalMultiphaseBaseKernels::PropertyKernelBase< NUM_COMP >; + using Base::numComp; + + /// Compile time value for the number of phases + static constexpr integer numPhase = NUM_PHASE; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] relperm the relperm model + */ + PhaseMobilityKernel( ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::RelativePermeabilityBase const & relperm ) + : Base(), + m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), + m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), + m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), + m_phaseDens( fluid.phaseDensity() ), + m_dPhaseDens( fluid.dPhaseDensity() ), + m_phaseVisc( fluid.phaseViscosity() ), + m_dPhaseVisc( fluid.dPhaseViscosity() ), + m_phaseRelPerm( relperm.phaseRelPerm() ), + m_dPhaseRelPerm_dPhaseVolFrac( relperm.dPhaseRelPerm_dPhaseVolFraction() ), + m_phaseMob( subRegion.getField< fields::flow::phaseMobility >() ), + m_dPhaseMob( subRegion.getField< fields::flow::dPhaseMobility >() ) + {} + + /** + * @brief Compute the phase mobilities in an element + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[in] phaseMobilityKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void compute( localIndex const ei, + FUNC && phaseMobilityKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseVisc = m_phaseVisc[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseVisc = m_dPhaseVisc[ei][0]; + arraySlice1d< real64 const, constitutive::relperm::USD_RELPERM - 2 > const phaseRelPerm = m_phaseRelPerm[ei][0]; + arraySlice2d< real64 const, constitutive::relperm::USD_RELPERM_DS - 2 > const dPhaseRelPerm_dPhaseVolFrac = m_dPhaseRelPerm_dPhaseVolFrac[ei][0]; + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; + arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseMob = m_phaseMob[ei]; + arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseMob = m_dPhaseMob[ei]; + + real64 dRelPerm_dC[numComp]{}; + real64 dDens_dC[numComp]{}; + real64 dVisc_dC[numComp]{}; + + for( integer ip = 0; ip < numPhase; ++ip ) + { + + // compute the phase mobility only if the phase is present + bool const phaseExists = (phaseVolFrac[ip] > 0); + if( !phaseExists ) + { + phaseMob[ip] = 0.0; + for( integer jc = 0; jc < numComp + 2; ++jc ) + { + dPhaseMob[ip][jc] = 0.0; + } + continue; + } + + real64 const density = phaseDens[ip]; + real64 const dDens_dP = dPhaseDens[ip][Deriv::dP]; + applyChainRule( numComp, dCompFrac_dCompDens, dPhaseDens[ip], dDens_dC, Deriv::dC ); + + real64 const viscosity = phaseVisc[ip]; + real64 const dVisc_dP = dPhaseVisc[ip][Deriv::dP]; + applyChainRule( numComp, dCompFrac_dCompDens, dPhaseVisc[ip], dVisc_dC, Deriv::dC ); + + real64 const relPerm = phaseRelPerm[ip]; + real64 dRelPerm_dP = 0.0; + for( integer ic = 0; ic < numComp; ++ic ) + { + dRelPerm_dC[ic] = 0.0; + } + + for( integer jp = 0; jp < numPhase; ++jp ) + { + real64 const dRelPerm_dS = dPhaseRelPerm_dPhaseVolFrac[ip][jp]; + dRelPerm_dP += dRelPerm_dS * dPhaseVolFrac[jp][Deriv::dP]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + dRelPerm_dC[jc] += dRelPerm_dS * dPhaseVolFrac[jp][Deriv::dC+jc]; + } + } + + real64 const mobility = relPerm * density / viscosity; + + phaseMob[ip] = mobility; + dPhaseMob[ip][Deriv::dP] = dRelPerm_dP * density / viscosity + + mobility * (dDens_dP / density - dVisc_dP / viscosity); + + // compositional derivatives + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseMob[ip][Deriv::dC+jc] = dRelPerm_dC[jc] * density / viscosity + + mobility * (dDens_dC[jc] / density - dVisc_dC[jc] / viscosity); + } + + // call the lambda in the phase loop to allow the reuse of the relperm, density, viscosity, and mobility + // possible use: assemble the derivatives wrt temperature + phaseMobilityKernelOp( ip, phaseMob[ip], dPhaseMob[ip] ); + } + } + +protected: + + // inputs + + /// Views on the phase volume fractions + arrayView2d< real64 const, compflow::USD_PHASE > m_phaseVolFrac; + arrayView3d< real64 const, compflow::USD_PHASE_DC > m_dPhaseVolFrac; + arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; + + /// Views on the phase densities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseDens; + + /// Views on the phase viscosities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseVisc; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseVisc; + + /// Views on the phase relative permeabilities + arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > m_phaseRelPerm; + arrayView4d< real64 const, constitutive::relperm::USD_RELPERM_DS > m_dPhaseRelPerm_dPhaseVolFrac; + + // outputs + + /// Views on the phase mobilities + arrayView2d< real64, compflow::USD_PHASE > m_phaseMob; + arrayView3d< real64, compflow::USD_PHASE_DC > m_dPhaseMob; + +}; + +/** + * @class PhaseMobilityKernelFactory + */ +class PhaseMobilityKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] numPhase the number of fluid phases + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] relperm the relperm model + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComp, + integer const numPhase, + ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::RelativePermeabilityBase const & relperm ) + { + if( numPhase == 2 ) + { + isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseMobilityKernel< NUM_COMP, 2 > kernel( subRegion, fluid, relperm ); + PhaseMobilityKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + else if( numPhase == 3 ) + { + isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseMobilityKernel< NUM_COMP, 3 > kernel( subRegion, fluid, relperm ); + PhaseMobilityKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + } +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEMOBILITYKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp new file mode 100644 index 00000000000..875bfe07c8e --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp @@ -0,0 +1,256 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PhaseVolumeFractionKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEVOLUMEFRACTIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEVOLUMEFRACTIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** PhaseVolumeFractionKernel ********************************/ + +/** + * @class PhaseVolumeFractionKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_PHASE number of fluid phases + * @brief Define the interface for the property kernel in charge of computing the phase volume fractions + */ +template< integer NUM_COMP, integer NUM_PHASE > +class PhaseVolumeFractionKernel : public PropertyKernelBase< NUM_COMP > +{ +public: + + using Base = PropertyKernelBase< NUM_COMP >; + using Base::numComp; + + /// Compile time value for the number of phases + static constexpr integer numPhase = NUM_PHASE; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + PhaseVolumeFractionKernel( ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid ) + : Base(), + m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), + m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), + m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), + m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), + m_phaseFrac( fluid.phaseFraction() ), + m_dPhaseFrac( fluid.dPhaseFraction() ), + m_phaseDens( fluid.phaseDensity() ), + m_dPhaseDens( fluid.dPhaseDensity() ) + {} + + /** + * @brief Compute the phase volume fractions in an element + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[in] phaseVolFractionKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + real64 compute( localIndex const ei, + FUNC && phaseVolFractionKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; + arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; + arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; + + real64 work[numComp]{}; + + // compute total density from component partial densities + real64 totalDensity = 0.0; + real64 const dTotalDens_dCompDens = 1.0; + for( integer ic = 0; ic < numComp; ++ic ) + { + totalDensity += compDens[ic]; + } + + real64 maxDeltaPhaseVolFrac = 0.0; + + for( integer ip = 0; ip < numPhase; ++ip ) + { + + // set the saturation to zero if the phase is absent + bool const phaseExists = (phaseFrac[ip] > 0); + if( !phaseExists ) + { + phaseVolFrac[ip] = 0.; + for( integer jc = 0; jc < numComp+2; ++jc ) + { + dPhaseVolFrac[ip][jc] = 0.; + } + continue; + } + + // Expression for volume fractions: S_p = (nu_p / rho_p) * rho_t + real64 const phaseDensInv = 1.0 / phaseDens[ip]; + + // store old saturation to compute change later + real64 const satOld = phaseVolFrac[ip]; + + // compute saturation and derivatives except multiplying by the total density + phaseVolFrac[ip] = phaseFrac[ip] * phaseDensInv; + + dPhaseVolFrac[ip][Deriv::dP] = + (dPhaseFrac[ip][Deriv::dP] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dP]) * phaseDensInv; + + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseVolFrac[ip][Deriv::dC+jc] = + (dPhaseFrac[ip][Deriv::dC+jc] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dC+jc]) * phaseDensInv; + } + + // apply chain rule to convert derivatives from global component fractions to densities + applyChainRuleInPlace( numComp, dCompFrac_dCompDens, dPhaseVolFrac[ip], work, Deriv::dC ); + + // call the lambda in the phase loop to allow the reuse of the phaseVolFrac and totalDensity + // possible use: assemble the derivatives wrt temperature + phaseVolFractionKernelOp( ip, phaseVolFrac[ip], phaseDensInv, totalDensity ); + + // now finalize the computation by multiplying by total density + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseVolFrac[ip][Deriv::dC+jc] *= totalDensity; + dPhaseVolFrac[ip][Deriv::dC+jc] += phaseVolFrac[ip] * dTotalDens_dCompDens; + } + + phaseVolFrac[ip] *= totalDensity; + dPhaseVolFrac[ip][Deriv::dP] *= totalDensity; + + real64 const deltaPhaseVolFrac = LvArray::math::abs( phaseVolFrac[ip] - satOld ); + if( maxDeltaPhaseVolFrac < deltaPhaseVolFrac ) + { + maxDeltaPhaseVolFrac = deltaPhaseVolFrac; + } + } + return maxDeltaPhaseVolFrac; + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static real64 + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPhaseVolFrac( 0.0 ); + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + real64 const deltaPhaseVolFrac = kernelComponent.compute( ei ); + maxDeltaPhaseVolFrac.max( deltaPhaseVolFrac ); + } ); + return maxDeltaPhaseVolFrac.get(); + } + +protected: + + // outputs + + /// Views on phase volume fractions + arrayView2d< real64, compflow::USD_PHASE > m_phaseVolFrac; + arrayView3d< real64, compflow::USD_PHASE_DC > m_dPhaseVolFrac; + + // inputs + + /// Views on component densities + arrayView2d< real64 const, compflow::USD_COMP > m_compDens; + arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; + + /// Views on phase fractions + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseFrac; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseFrac; + + /// Views on phase densities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseDens; + +}; + +/** + * @class PhaseVolumeFractionKernelFactory + */ +class PhaseVolumeFractionKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] numPhase the number of fluid phases + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + template< typename POLICY > + static real64 + createAndLaunch( integer const numComp, + integer const numPhase, + ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid ) + { + real64 maxDeltaPhaseVolFrac = 0.0; + if( numPhase == 2 ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseVolumeFractionKernel< NUM_COMP, 2 > kernel( subRegion, fluid ); + maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + else if( numPhase == 3 ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseVolumeFractionKernel< NUM_COMP, 3 > kernel( subRegion, fluid ); + maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + return maxDeltaPhaseVolFrac; + } +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEVOLUMEFRACTIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp new file mode 100644 index 00000000000..6d1532031a1 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp @@ -0,0 +1,103 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PropertyKernelBase.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PROPERTYKERNELBASE_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PROPERTYKERNELBASE_HPP + +//#include "codingUtilities/Utilities.hpp" +//#include "common/DataLayouts.hpp" +//#include "common/DataTypes.hpp" +//#include "common/GEOS_RAJA_Interface.hpp" +//#include "constitutive/solid/CoupledSolidBase.hpp" +//#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +//#include "functions/TableFunction.hpp" +//#include "mesh/ElementSubRegionBase.hpp" +//#include "mesh/ObjectManagerBase.hpp" +//#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +//#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +//#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +//#include "physicsSolvers/SolverBaseKernels.hpp" +//#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** PropertyKernelBase ********************************/ + +/** + * @class PropertyKernelBase + * @tparam NUM_COMP number of fluid components + * @brief Define the base interface for the property update kernels + */ +template< integer NUM_COMP > +class PropertyKernelBase +{ +public: + + /// Compile time value for the number of components + static constexpr integer numComp = NUM_COMP; + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + kernelComponent.compute( ei ); + } ); + } + + /** + * @brief Performs the kernel launch on a sorted array + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] targetSet the indices of the elements in which we compute the property + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( SortedArrayView< localIndex const > const & targetSet, + KERNEL_TYPE const & kernelComponent ) + { + forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const i ) + { + localIndex const ei = targetSet[ i ]; + kernelComponent.compute( ei ); + } ); + } + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PROPERTYKERNELBASE_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp new file mode 100644 index 00000000000..b964ff56a2e --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp @@ -0,0 +1,85 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 RelativePermeabilityUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RELATIVEPERMEABILITYUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RELATIVEPERMEABILITYUPDATEKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "functions/TableFunction.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** RelativePermeabilityUpdateKernel ********************************/ + +struct RelativePermeabilityUpdateKernel +{ + template< typename POLICY, typename RELPERM_WRAPPER > + static void + launch( localIndex const size, + RELPERM_WRAPPER const & relPermWrapper, + arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < relPermWrapper.numGauss(); ++q ) + { + relPermWrapper.update( k, q, phaseVolFrac[k] ); + } + } ); + } + + template< typename POLICY, typename RELPERM_WRAPPER > + static void + launch( SortedArrayView< localIndex const > const & targetSet, + RELPERM_WRAPPER const & relPermWrapper, + arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac ) + { + forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) + { + localIndex const k = targetSet[a]; + for( localIndex q = 0; q < relPermWrapper.numGauss(); ++q ) + { + relPermWrapper.update( k, q, phaseVolFrac[k] ); + } + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RELATIVEPERMEABILITYUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp new file mode 100644 index 00000000000..134460ca4cf --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp @@ -0,0 +1,204 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ResidualNormKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RESIDUALNORMKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RESIDUALNORMKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "functions/TableFunction.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** ResidualNormKernel ********************************/ + +/** + * @class ResidualNormKernel + */ +class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 1 > +{ +public: + + using Base = solverBaseKernels::ResidualNormKernelBase< 1 >; + using Base::m_minNormalizer; + using Base::m_rankOffset; + using Base::m_localResidual; + using Base::m_dofNumber; + + ResidualNormKernel( globalIndex const rankOffset, + arrayView1d< real64 const > const & localResidual, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< localIndex const > const & ghostRank, + integer const numComponents, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + real64 const minNormalizer ) + : Base( rankOffset, + localResidual, + dofNumber, + ghostRank, + minNormalizer ), + m_numComponents( numComponents ), + m_volume( subRegion.getElementVolume() ), + m_porosity_n( solid.getPorosity_n() ), + m_totalDens_n( fluid.totalDensity_n() ) + {} + + GEOS_HOST_DEVICE + virtual void computeLinf( localIndex const ei, + LinfStackVariables & stack ) const override + { + // this should never be zero if the simulation is set up correctly, but we never know + real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_totalDens_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ); + real64 const volumeNormalizer = LvArray::math::max( m_minNormalizer, m_porosity_n[ei][0] * m_volume[ei] ); + + // step 1: mass residuals + + for( integer idof = 0; idof < m_numComponents; ++idof ) + { + real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow + idof] ) / massNormalizer; + if( valMass > stack.localValue[0] ) + { + stack.localValue[0] = valMass; + } + } + + // step 2: volume residual + + real64 const valVol = LvArray::math::abs( m_localResidual[stack.localRow + m_numComponents] ) / volumeNormalizer; + if( valVol > stack.localValue[0] ) + { + stack.localValue[0] = valVol; + } + } + + GEOS_HOST_DEVICE + virtual void computeL2( localIndex const ei, + L2StackVariables & stack ) const override + { + // note: for the L2 norm, we bundle the volume and mass residuals/normalizers + + real64 const massNormalizer = LvArray::math::max( m_minNormalizer, m_totalDens_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ); + + // step 1: mass residuals + + for( integer idof = 0; idof < m_numComponents; ++idof ) + { + stack.localValue[0] += m_localResidual[stack.localRow + idof] * m_localResidual[stack.localRow + idof]; + stack.localNormalizer[0] += massNormalizer; + } + + // step 2: volume residual + + real64 const val = m_localResidual[stack.localRow + m_numComponents] * m_totalDens_n[ei][0]; // we need a mass here, hence the + // multiplication + stack.localValue[0] += val * val; + stack.localNormalizer[0] += massNormalizer; + } + + +protected: + + /// Number of fluid coponents + integer const m_numComponents; + + /// View on the volume + arrayView1d< real64 const > const m_volume; + + /// View on porosity at the previous converged time step + arrayView2d< real64 const > const m_porosity_n; + + /// View on total mass/molar density at the previous converged time step + arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const m_totalDens_n; + +}; + +/** + * @class ResidualNormKernelFactory + */ +class ResidualNormKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] normType the type of norm used (Linf or L2) + * @param[in] numComps the number of fluid components + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] localResidual the residual vector on my MPI rank + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[out] residualNorm the residual norm on the subRegion + * @param[out] residualNormalizer the residual normalizer on the subRegion + */ + template< typename POLICY > + static void + createAndLaunch( solverBaseKernels::NormType const normType, + integer const numComps, + globalIndex const rankOffset, + string const dofKey, + arrayView1d< real64 const > const & localResidual, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + real64 const minNormalizer, + real64 (& residualNorm)[1], + real64 (& residualNormalizer)[1] ) + { + arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, numComps, subRegion, fluid, solid, minNormalizer ); + if( normType == solverBaseKernels::NormType::Linf ) + { + ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); + } + else // L2 norm + { + ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); + } + } + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RESIDUALNORMKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp new file mode 100644 index 00000000000..e24c36797c3 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp @@ -0,0 +1,192 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ScalingAndCheckingSystemSolutionKernelBase.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SCALINGANDCHECKINGSYSTEMSOLUTIONKERNELBASE_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SCALINGANDCHECKINGSYSTEMSOLUTIONKERNELBASE_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "functions/TableFunction.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/** + * @class ScalingAndCheckingSystemSolutionKernelBase + * @brief Define the kernel for scaling the solution and check its validity + */ +template< typename TYPE > +class ScalingAndCheckingSystemSolutionKernelBase +{ +public: + + /** + * @brief Create a new kernel instance + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @param[in] pressure the pressure vector + * @param[in] compDens the component density vector + * @param[in] pressureScalingFactor the pressure local scaling factor + * @param[in] compDensScalingFactor the component local scaling factor + */ + ScalingAndCheckingSystemSolutionKernelBase( globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor ) + : m_rankOffset( rankOffset ), + m_numComp( numComp ), + m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), + m_ghostRank( subRegion.ghostRank() ), + m_localSolution( localSolution ), + m_pressure( pressure ), // not passed with fields::flow to be able to reuse this for wells + m_compDens( compDens ), // same here + m_pressureScalingFactor( pressureScalingFactor ), + m_compDensScalingFactor( compDensScalingFactor ) + { } + + /** + * @struct StackVariables + * @brief Kernel variables located on the stack + */ + struct StackVariables + { + GEOS_HOST_DEVICE + StackVariables() + { } + + StackVariables( real64 _localMinVal ) + : + localMinVal( _localMinVal ) + { } + + /// Index of the local row corresponding to this element + localIndex localRow; + + /// The local value + TYPE localMinVal; + }; + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] ei the element index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + stack.localMinVal = 1; + + // set row index and degrees of freedom indices for this element + stack.localRow = m_dofNumber[ei] - m_rankOffset; + } + + /** + * @brief Getter for the ghost rank + * @param[in] i the looping index of the element/node/face + * @return the ghost rank of the element/node/face + */ + GEOS_HOST_DEVICE + integer ghostRank( localIndex const i ) const + { return m_ghostRank( i ); } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static TYPE + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + RAJA::ReduceMin< ReducePolicy< POLICY >, TYPE > minVal( 1 ); + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( kernelComponent.ghostRank( ei ) >= 0 ) + { + return; + } + + StackVariables stack; + kernelComponent.setup( ei, stack ); + kernelComponent.compute( ei, stack ); + minVal.min( stack.localMinVal ); + } ); + + return minVal.get(); + } + +protected: + + /// Offset for my MPI rank + globalIndex const m_rankOffset; + + /// Number of components + real64 const m_numComp; + + /// View on the dof numbers + arrayView1d< globalIndex const > const m_dofNumber; + + /// View on the ghost ranks + arrayView1d< integer const > const m_ghostRank; + + /// View on the local residual + arrayView1d< real64 const > const m_localSolution; + + /// View on the primary variables + arrayView1d< real64 const > const m_pressure; + arrayView2d< real64 const, compflow::USD_COMP > const m_compDens; + + /// View on the scaling factors + arrayView1d< real64 > const m_pressureScalingFactor; + arrayView1d< real64 > const m_compDensScalingFactor; + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SCALINGANDCHECKINGSYSTEMSOLUTIONKERNELBASE_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp new file mode 100644 index 00000000000..ddef53d3bf9 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -0,0 +1,350 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2023-2024 Chevron + * Copyright (c) 2019- GEOS/GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file SolutionCheckKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "functions/TableFunction.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** SolutionCheckKernel ********************************/ + +/** + * @class SolutionCheckKernel + * @brief Define the kernel for checking the updated solution + */ +class SolutionCheckKernel : public ScalingAndCheckingSystemSolutionKernelBase< integer > +{ +public: + + using Base = ScalingAndCheckingSystemSolutionKernelBase< integer >; + using Base::m_rankOffset; + using Base::m_numComp; + using Base::m_dofNumber; + using Base::m_ghostRank; + using Base::m_localSolution; + using Base::m_pressure; + using Base::m_compDens; + + /** + * @brief Create a new kernel instance + * @param[in] allowCompDensChopping flag to allow the component density chopping + * @param[in] scalingFactor the scaling factor + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @param[in] pressure the pressure vector + * @param[in] compDens the component density vector + */ + SolutionCheckKernel( integer const allowCompDensChopping, + integer const allowNegativePressure, + CompositionalMultiphaseFVM::ScalingType const scalingType, + real64 const scalingFactor, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor ) + : Base( rankOffset, + numComp, + dofKey, + subRegion, + localSolution, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor ), + m_allowCompDensChopping( allowCompDensChopping ), + m_allowNegativePressure( allowNegativePressure ), + m_scalingFactor( scalingFactor ), + m_scalingType( scalingType ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables located on the stack + */ + struct StackVariables : public Base::StackVariables + { + GEOS_HOST_DEVICE + StackVariables() + { } + + StackVariables( real64 _localMinVal, + real64 _localMinPres, + real64 _localMinDens, + real64 _localMinTotalDens, + integer _localNumNegPressures, + integer _localNumNegDens, + integer _localNumNegTotalDens ) + : + Base::StackVariables( _localMinVal ), + localMinPres( _localMinPres ), + localMinDens( _localMinDens ), + localMinTotalDens( _localMinTotalDens ), + localNumNegPressures( _localNumNegPressures ), + localNumNegDens( _localNumNegDens ), + localNumNegTotalDens( _localNumNegTotalDens ) + { } + + real64 localMinPres; + real64 localMinDens; + real64 localMinTotalDens; + + integer localNumNegPressures; + integer localNumNegDens; + integer localNumNegTotalDens; + + }; + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static StackVariables + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + RAJA::ReduceMin< ReducePolicy< POLICY >, integer > globalMinVal( 1 ); + + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPres( 0.0 ); + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minDens( 0.0 ); + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minTotalDens( 0.0 ); + + RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegPressures( 0 ); + RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegDens( 0 ); + RAJA::ReduceSum< ReducePolicy< POLICY >, integer > numNegTotalDens( 0 ); + + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( kernelComponent.ghostRank( ei ) >= 0 ) + { + return; + } + + StackVariables stack; + kernelComponent.setup( ei, stack ); + kernelComponent.compute( ei, stack ); + + globalMinVal.min( stack.localMinVal ); + + minPres.min( stack.localMinPres ); + minDens.min( stack.localMinDens ); + minTotalDens.min( stack.localMinTotalDens ); + + numNegPressures += stack.localNumNegPressures; + numNegDens += stack.localNumNegDens; + numNegTotalDens += stack.localNumNegTotalDens; + } ); + + return StackVariables( globalMinVal.get(), + minPres.get(), + minDens.get(), + minTotalDens.get(), + numNegPressures.get(), + numNegDens.get(), + numNegTotalDens.get() ); + } + + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + Base::setup( ei, stack ); + + stack.localMinPres = 0.0; + stack.localMinDens = 0.0; + stack.localMinTotalDens = 0.0; + + stack.localNumNegPressures = 0; + stack.localNumNegDens = 0; + stack.localNumNegTotalDens = 0; + } + + /** + * @brief Compute the local value + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void compute( localIndex const ei, + StackVariables & stack ) const + { + computeSolutionCheck( ei, stack ); + } + + /** + * @brief Compute the local value of the check + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + * @param[in] kernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeSolutionCheck( localIndex const ei, + StackVariables & stack, + FUNC && kernelOp = NoOpFunc{} ) const + { + bool const localScaling = m_scalingType == CompositionalMultiphaseFVM::ScalingType::Local; + + real64 const newPres = m_pressure[ei] + (localScaling ? m_pressureScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow]; + if( newPres < 0 ) + { + if( !m_allowNegativePressure ) + { + stack.localMinVal = 0; + } + stack.localNumNegPressures += 1; + if( newPres < stack.localMinPres ) + stack.localMinPres = newPres; + } + + // if component density chopping is not allowed, the time step fails if a component density is negative + // otherwise, we just check that the total density is positive, and negative component densities + // will be chopped (i.e., set to zero) in ApplySystemSolution) + if( !m_allowCompDensChopping ) + { + for( integer ic = 0; ic < m_numComp; ++ic ) + { + real64 const newDens = m_compDens[ei][ic] + (localScaling ? m_compDensScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow + ic + 1]; + if( newDens < 0 ) + { + stack.localMinVal = 0; + stack.localNumNegDens += 1; + if( newDens < stack.localMinDens ) + stack.localMinDens = newDens; + } + } + } + else + { + real64 totalDens = 0.0; + for( integer ic = 0; ic < m_numComp; ++ic ) + { + real64 const newDens = m_compDens[ei][ic] + (localScaling ? m_compDensScalingFactor[ei] : m_scalingFactor) * m_localSolution[stack.localRow + ic + 1]; + totalDens += ( newDens > 0.0 ) ? newDens : 0.0; + } + if( totalDens < 0 ) + { + stack.localMinVal = 0; + stack.localNumNegTotalDens += 1; + if( totalDens < stack.localMinTotalDens ) + stack.localMinTotalDens = totalDens; + } + } + + kernelOp(); + } + +protected: + + /// flag to allow the component density chopping + integer const m_allowCompDensChopping; + + /// flag to allow negative pressure values + integer const m_allowNegativePressure; + + /// scaling factor + real64 const m_scalingFactor; + + /// scaling type (global or local) + CompositionalMultiphaseFVM::ScalingType const m_scalingType; + +}; + +/** + * @class SolutionCheckKernelFactory + */ +class SolutionCheckKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] allowCompDensChopping flag to allow the component density chopping + * @param[in] scalingFactor the scaling factor + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + */ + template< typename POLICY > + static SolutionCheckKernel::StackVariables + createAndLaunch( integer const allowCompDensChopping, + integer const allowNegativePressure, + CompositionalMultiphaseFVM::ScalingType const scalingType, + real64 const scalingFactor, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase & subRegion, + arrayView1d< real64 const > const localSolution ) + { + arrayView1d< real64 const > const pressure = + subRegion.getField< fields::flow::pressure >(); + arrayView2d< real64 const, compflow::USD_COMP > const compDens = + subRegion.getField< fields::flow::globalCompDensity >(); + arrayView1d< real64 > pressureScalingFactor = + subRegion.getField< fields::flow::pressureScalingFactor >(); + arrayView1d< real64 > compDensScalingFactor = + subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); + SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, rankOffset, + numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); + return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); + } + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp new file mode 100644 index 00000000000..53634692622 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp @@ -0,0 +1,386 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SolutionScalingKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** SolutionScalingKernel ********************************/ + +/** + * @class SolutionScalingKernel + * @brief Define the kernel for scaling the Newton update + */ +class SolutionScalingKernel : public ScalingAndCheckingSystemSolutionKernelBase< real64 > +{ +public: + + using Base = ScalingAndCheckingSystemSolutionKernelBase< real64 >; + using Base::m_rankOffset; + using Base::m_numComp; + using Base::m_dofNumber; + using Base::m_ghostRank; + using Base::m_localSolution; + using Base::m_pressure; + using Base::m_compDens; + using Base::m_pressureScalingFactor; + using Base::m_compDensScalingFactor; + + /** + * @brief Create a new kernel instance + * @param[in] maxRelativePresChange the max allowed relative pressure change + * @param[in] maxAbsolutePresChange the max allowed absolute pressure change + * @param[in] maxCompFracChange the max allowed comp fraction change + * @param[in] maxRelativeCompDensChange the max allowed comp density change + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @param[in] pressure the pressure vector + * @param[in] compDens the component density vector + * @param[in] pressureScalingFactor the pressure local scaling factor + * @param[in] compDensScalingFactor the component density local scaling factor + */ + SolutionScalingKernel( real64 const maxRelativePresChange, + real64 const maxAbsolutePresChange, + real64 const maxCompFracChange, + real64 const maxRelativeCompDensChange, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor ) + : Base( rankOffset, + numComp, + dofKey, + subRegion, + localSolution, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor ), + m_maxRelativePresChange( maxRelativePresChange ), + m_maxAbsolutePresChange( maxAbsolutePresChange ), + m_maxCompFracChange( maxCompFracChange ), + m_maxRelativeCompDensChange( maxRelativeCompDensChange ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables located on the stack + */ + struct StackVariables : public Base::StackVariables + { + GEOS_HOST_DEVICE + StackVariables() + { } + + StackVariables( real64 _localMinVal, + real64 _localMaxDeltaPres, + real64 _localMaxDeltaTemp, + real64 _localMaxDeltaCompDens, + real64 _localMinPresScalingFactor, + real64 _localMinTempScalingFactor, + real64 _localMinCompDensScalingFactor ) + : + Base::StackVariables( _localMinVal ), + localMaxDeltaPres( _localMaxDeltaPres ), + localMaxDeltaTemp( _localMaxDeltaTemp ), + localMaxDeltaCompDens( _localMaxDeltaCompDens ), + localMinPresScalingFactor( _localMinPresScalingFactor ), + localMinTempScalingFactor( _localMinTempScalingFactor ), + localMinCompDensScalingFactor( _localMinCompDensScalingFactor ) + { } + + real64 localMaxDeltaPres; + real64 localMaxDeltaTemp; + real64 localMaxDeltaCompDens; + + real64 localMinPresScalingFactor; + real64 localMinTempScalingFactor; + real64 localMinCompDensScalingFactor; + + }; + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static StackVariables + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > globalScalingFactor( 1.0 ); + + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 ); + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaTemp( 0.0 ); + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaCompDens( 0.0 ); + + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPresScalingFactor( 1.0 ); + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minTempScalingFactor( 1.0 ); + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minCompDensScalingFactor( 1.0 ); + + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( kernelComponent.ghostRank( ei ) >= 0 ) + { + return; + } + + StackVariables stack; + kernelComponent.setup( ei, stack ); + kernelComponent.compute( ei, stack ); + + globalScalingFactor.min( stack.localMinVal ); + + maxDeltaPres.max( stack.localMaxDeltaPres ); + maxDeltaTemp.max( stack.localMaxDeltaTemp ); + maxDeltaCompDens.max( stack.localMaxDeltaCompDens ); + + minPresScalingFactor.min( stack.localMinPresScalingFactor ); + minTempScalingFactor.min( stack.localMinTempScalingFactor ); + minCompDensScalingFactor.min( stack.localMinCompDensScalingFactor ); + } ); + + return StackVariables( globalScalingFactor.get(), + maxDeltaPres.get(), + maxDeltaTemp.get(), + maxDeltaCompDens.get(), + minPresScalingFactor.get(), + minTempScalingFactor.get(), + minCompDensScalingFactor.get() ); + } + + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + Base::setup( ei, stack ); + + stack.localMaxDeltaPres = 0.0; + stack.localMaxDeltaTemp = 0.0; + stack.localMaxDeltaCompDens = 0.0; + + stack.localMinPresScalingFactor = 1.0; + stack.localMinTempScalingFactor = 1.0; + stack.localMinCompDensScalingFactor = 1.0; + } + + /** + * @brief Compute the local value + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void compute( localIndex const ei, + StackVariables & stack ) const + { + computeScalingFactor( ei, stack ); + } + + /** + * @brief Compute the local value of the scaling factor + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + * @param[in] kernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeScalingFactor( localIndex const ei, + StackVariables & stack, + FUNC && kernelOp = NoOpFunc{} ) const + { + real64 constexpr eps = minDensForDivision; + + // compute the change in pressure + real64 const pres = m_pressure[ei]; + real64 const absPresChange = LvArray::math::abs( m_localSolution[stack.localRow] ); + if( stack.localMaxDeltaPres < absPresChange ) + { + stack.localMaxDeltaPres = absPresChange; + } + + // compute pressure scaling factor + real64 presScalingFactor = 1.0; + // when enabled, absolute change scaling has a priority over relative change + if( m_maxAbsolutePresChange > 0.0 ) // maxAbsolutePresChange <= 0.0 means that absolute scaling is disabled + { + if( absPresChange > m_maxAbsolutePresChange ) + { + presScalingFactor = m_maxAbsolutePresChange / absPresChange; + } + } + else if( pres > eps ) + { + real64 const relativePresChange = absPresChange / pres; + if( relativePresChange > m_maxRelativePresChange ) + { + presScalingFactor = m_maxRelativePresChange / relativePresChange; + } + } + m_pressureScalingFactor[ei] = presScalingFactor; + if( stack.localMinVal > presScalingFactor ) + { + stack.localMinVal = presScalingFactor; + } + if( stack.localMinPresScalingFactor > presScalingFactor ) + { + stack.localMinPresScalingFactor = presScalingFactor; + } + + real64 prevTotalDens = 0; + for( integer ic = 0; ic < m_numComp; ++ic ) + { + prevTotalDens += m_compDens[ei][ic]; + } + + m_compDensScalingFactor[ei] = 1.0; + + // compute the change in component densities and component fractions + for( integer ic = 0; ic < m_numComp; ++ic ) + { + // compute scaling factor based on relative change in component densities + real64 const absCompDensChange = LvArray::math::abs( m_localSolution[stack.localRow + ic + 1] ); + if( stack.localMaxDeltaCompDens < absCompDensChange ) + { + stack.localMaxDeltaCompDens = absCompDensChange; + } + + // This actually checks the change in component fraction, using a lagged total density + // Indeed we can rewrite the following check as: + // | prevCompDens / prevTotalDens - newCompDens / prevTotalDens | > maxCompFracChange + // Note that the total density in the second term is lagged (i.e, we use prevTotalDens) + // because I found it more robust than using directly newTotalDens (which can vary also + // wildly when the compDens change is large) + real64 const maxAbsCompDensChange = m_maxCompFracChange * prevTotalDens; + if( absCompDensChange > maxAbsCompDensChange && absCompDensChange > eps ) + { + real64 const compScalingFactor = maxAbsCompDensChange / absCompDensChange; + m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor ); + if( stack.localMinVal > compScalingFactor ) + { + stack.localMinVal = compScalingFactor; + } + if( stack.localMinCompDensScalingFactor > compScalingFactor ) + { + stack.localMinCompDensScalingFactor = compScalingFactor; + } + } + + // switch from relative to absolute when value is < 1.0 + real64 const maxRelCompDensChange = m_maxRelativeCompDensChange * LvArray::math::max( m_compDens[ei][ic], 1.0 ); + if( absCompDensChange > maxRelCompDensChange && absCompDensChange > eps ) + { + real64 const compScalingFactor = maxRelCompDensChange / absCompDensChange; + m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor ); + if( stack.localMinVal > compScalingFactor ) + { + stack.localMinVal = compScalingFactor; + } + if( stack.localMinCompDensScalingFactor > compScalingFactor ) + { + stack.localMinCompDensScalingFactor = compScalingFactor; + } + } + } + + // compute the scaling factor for other vars, such as temperature + kernelOp(); + } + +protected: + + /// Max allowed changes in primary variables + real64 const m_maxRelativePresChange; + real64 const m_maxAbsolutePresChange; + real64 const m_maxCompFracChange; + real64 const m_maxRelativeCompDensChange; + +}; + +/** + * @class SolutionScalingKernelFactory + */ +class SolutionScalingKernelFactory +{ +public: + + /* + * @brief Create and launch the kernel computing the scaling factor + * @tparam POLICY the kernel policy + * @param[in] maxRelativePresChange the max allowed relative pressure change + * @param[in] maxAbsolutePresChange the max allowed absolute pressure change + * @param[in] maxCompFracChange the max allowed comp fraction change + * @param[in] maxRelativeCompDensChange the max allowed comp density change + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @return the scaling factor + */ + template< typename POLICY > + static SolutionScalingKernel::StackVariables + createAndLaunch( real64 const maxRelativePresChange, + real64 const maxAbsolutePresChange, + real64 const maxCompFracChange, + real64 const maxRelativeCompDensChange, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase & subRegion, + arrayView1d< real64 const > const localSolution ) + { + arrayView1d< real64 const > const pressure = + subRegion.getField< fields::flow::pressure >(); + arrayView2d< real64 const, compflow::USD_COMP > const compDens = + subRegion.getField< fields::flow::globalCompDensity >(); + arrayView1d< real64 > pressureScalingFactor = + subRegion.getField< fields::flow::pressureScalingFactor >(); + arrayView1d< real64 > compDensScalingFactor = + subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); + SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset, + numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); + return SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel ); + } +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp new file mode 100644 index 00000000000..41caa82c81c --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp @@ -0,0 +1,203 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 StatisticsKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STATISTICSKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STATISTICSKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "functions/TableFunction.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** StatisticsKernel ********************************/ + +struct StatisticsKernel +{ + template< typename POLICY > + static void + saveDeltaPressure( localIndex const size, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & initPres, + arrayView1d< real64 > const & deltaPres ) + { + forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + deltaPres[ei] = pres[ei] - initPres[ei]; + } ); + } + + template< typename POLICY > + static void + launch( localIndex const size, + integer const numComps, + integer const numPhases, + real64 const relpermThreshold, + arrayView1d< integer const > const & elemGhostRank, + arrayView1d< real64 const > const & volume, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & deltaPres, + arrayView1d< real64 const > const & temp, + arrayView1d< real64 const > const & refPorosity, + arrayView2d< real64 const > const & porosity, + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const & phaseDensity, + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > const & phaseCompFraction, + arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac, + arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > const & phaseTrappedVolFrac, + arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > const & phaseRelperm, + real64 & minPres, + real64 & avgPresNumerator, + real64 & maxPres, + real64 & minDeltaPres, + real64 & maxDeltaPres, + real64 & minTemp, + real64 & avgTempNumerator, + real64 & maxTemp, + real64 & totalUncompactedPoreVol, + arrayView1d< real64 > const & phaseDynamicPoreVol, + arrayView1d< real64 > const & phaseMass, + arrayView1d< real64 > const & trappedPhaseMass, + arrayView1d< real64 > const & immobilePhaseMass, + arrayView2d< real64 > const & dissolvedComponentMass ) + { + RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinPres( LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgPresNumerator( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPres( -LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinDeltaPres( LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxDeltaPres( -LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinTemp( LvArray::NumericLimits< real64 >::max ); + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgTempNumerator( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTemp( 0.0 ); + RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalUncompactedPoreVol( 0.0 ); + + // For this arrays phaseDynamicPoreVol, phaseMass, dissolvedComponentMass, + // using an array of ReduceSum leads to a formal parameter overflow in CUDA. + // As a workaround, we use a slice with RAJA::atomicAdd instead + + forAll< parallelDevicePolicy<> >( size, [numComps, + numPhases, + relpermThreshold, + elemGhostRank, + volume, + refPorosity, + porosity, + pres, + deltaPres, + temp, + phaseDensity, + phaseVolFrac, + phaseTrappedVolFrac, + phaseRelperm, + phaseCompFraction, + subRegionMinPres, + subRegionAvgPresNumerator, + subRegionMaxPres, + subRegionMinDeltaPres, + subRegionMaxDeltaPres, + subRegionMinTemp, + subRegionAvgTempNumerator, + subRegionMaxTemp, + subRegionTotalUncompactedPoreVol, + phaseDynamicPoreVol, + phaseMass, + trappedPhaseMass, + immobilePhaseMass, + dissolvedComponentMass] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( elemGhostRank[ei] >= 0 ) + { + return; + } + + // To match our "reference", we have to use reference porosity here, not the actual porosity when we compute averages + real64 const uncompactedPoreVol = volume[ei] * refPorosity[ei]; + real64 const dynamicPoreVol = volume[ei] * porosity[ei][0]; + + subRegionMinPres.min( pres[ei] ); + subRegionAvgPresNumerator += uncompactedPoreVol * pres[ei]; + subRegionMaxPres.max( pres[ei] ); + + subRegionMaxDeltaPres.max( deltaPres[ei] ); + subRegionMinDeltaPres.min( deltaPres[ei] ); + + subRegionMinTemp.min( temp[ei] ); + subRegionAvgTempNumerator += uncompactedPoreVol * temp[ei]; + subRegionMaxTemp.max( temp[ei] ); + subRegionTotalUncompactedPoreVol += uncompactedPoreVol; + for( integer ip = 0; ip < numPhases; ++ip ) + { + real64 const elemPhaseVolume = dynamicPoreVol * phaseVolFrac[ei][ip]; + real64 const elemPhaseMass = phaseDensity[ei][0][ip] * elemPhaseVolume; + real64 const elemTrappedPhaseMass = phaseDensity[ei][0][ip] * dynamicPoreVol * phaseTrappedVolFrac[ei][0][ip]; + // RAJA::atomicAdd used here because we do not use ReduceSum here (for the reason explained above) + RAJA::atomicAdd( parallelDeviceAtomic{}, &phaseDynamicPoreVol[ip], elemPhaseVolume ); + RAJA::atomicAdd( parallelDeviceAtomic{}, &phaseMass[ip], elemPhaseMass ); + RAJA::atomicAdd( parallelDeviceAtomic{}, &trappedPhaseMass[ip], elemTrappedPhaseMass ); + if( phaseRelperm[ei][0][ip] < relpermThreshold ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &immobilePhaseMass[ip], elemPhaseMass ); + } + for( integer ic = 0; ic < numComps; ++ic ) + { + // RAJA::atomicAdd used here because we do not use ReduceSum here (for the reason explained above) + RAJA::atomicAdd( parallelDeviceAtomic{}, &dissolvedComponentMass[ip][ic], phaseCompFraction[ei][0][ip][ic] * elemPhaseMass ); + } + } + + } ); + + minPres = subRegionMinPres.get(); + avgPresNumerator = subRegionAvgPresNumerator.get(); + maxPres = subRegionMaxPres.get(); + minDeltaPres = subRegionMinDeltaPres.get(); + maxDeltaPres = subRegionMaxDeltaPres.get(); + minTemp = subRegionMinTemp.get(); + avgTempNumerator = subRegionAvgTempNumerator.get(); + maxTemp = subRegionMaxTemp.get(); + totalUncompactedPoreVol = subRegionTotalUncompactedPoreVol.get(); + + // dummy loop to bring data back to the CPU + forAll< serialPolicy >( 1, [phaseDynamicPoreVol, phaseMass, trappedPhaseMass, immobilePhaseMass, dissolvedComponentMass] ( localIndex const ) + { + GEOS_UNUSED_VAR( phaseDynamicPoreVol, phaseMass, trappedPhaseMass, immobilePhaseMass, dissolvedComponentMass ); + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STATISTICSKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp index 7eb095cc2b6..5e99ab07feb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp @@ -21,6 +21,10 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" namespace geos { @@ -187,7 +191,7 @@ class ElementBasedAssemblyKernel : public isothermalCompositionalMultiphaseBaseK constitutive::CoupledSolidBase const & solid, CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseBaseKernels::ElementBasedAssemblyKernelFlags > const kernelFlags ) + BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > const kernelFlags ) : Base( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ), m_dPoro_dTemp( solid.getDporosity_dTemperature() ), m_phaseInternalEnergy( fluid.phaseInternalEnergy() ), @@ -431,9 +435,9 @@ class ElementBasedAssemblyKernelFactory localIndex constexpr NUM_COMP = NC(); localIndex constexpr NUM_DOF = NC()+2; - BitFlags< isothermalCompositionalMultiphaseBaseKernels::ElementBasedAssemblyKernelFlags > kernelFlags; + BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > kernelFlags; if( useTotalMassEquation ) - kernelFlags.set( isothermalCompositionalMultiphaseBaseKernels::ElementBasedAssemblyKernelFlags::TotalMassEquation ); + kernelFlags.set( isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags::TotalMassEquation ); ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF > kernel( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ); @@ -502,17 +506,17 @@ struct SolidInternalEnergyUpdateKernel } }; -/******************************** ScalingForSystemSolutionKernel ********************************/ +/******************************** SolutionScalingKernel ********************************/ /** - * @class ScalingForSystemSolutionKernel + * @class SolutionScalingKernel * @brief Define the kernel for scaling the Newton update */ -class ScalingForSystemSolutionKernel : public isothermalCompositionalMultiphaseBaseKernels::ScalingForSystemSolutionKernel +class SolutionScalingKernel : public isothermalCompositionalMultiphaseBaseKernels::SolutionScalingKernel { public: - using Base = isothermalCompositionalMultiphaseBaseKernels::ScalingForSystemSolutionKernel; + using Base = isothermalCompositionalMultiphaseBaseKernels::SolutionScalingKernel; using Base::m_numComp; using Base::m_localSolution; @@ -535,7 +539,7 @@ class ScalingForSystemSolutionKernel : public isothermalCompositionalMultiphaseB * @param[in] compDensScalingFactor the component density local scaling factor * @param[in] temperatureFactor the temperature local scaling factor */ - ScalingForSystemSolutionKernel( real64 const maxRelativePresChange, + SolutionScalingKernel( real64 const maxRelativePresChange, real64 const maxAbsolutePresChange, real64 const maxRelativeTempChange, real64 const maxCompFracChange, @@ -637,9 +641,9 @@ class ScalingForSystemSolutionKernel : public isothermalCompositionalMultiphaseB }; /** - * @class ScalingForSystemSolutionKernelFactory + * @class SolutionScalingKernelFactory */ -class ScalingForSystemSolutionKernelFactory +class SolutionScalingKernelFactory { public: @@ -658,7 +662,7 @@ class ScalingForSystemSolutionKernelFactory * @param[in] localSolution the Newton update */ template< typename POLICY > - static ScalingForSystemSolutionKernel::StackVariables + static SolutionScalingKernel::StackVariables createAndLaunch( real64 const maxRelativePresChange, real64 const maxAbsolutePresChange, real64 const maxRelativeTempChange, @@ -676,13 +680,13 @@ class ScalingForSystemSolutionKernelFactory arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); - ScalingForSystemSolutionKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxRelativeTempChange, + SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxRelativeTempChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset, numComp, dofKey, subRegion, localSolution, pressure, temperature, compDens, pressureScalingFactor, temperatureScalingFactor, compDensScalingFactor ); return thermalCompositionalMultiphaseBaseKernels:: - ScalingForSystemSolutionKernel::launch< POLICY >( subRegion.size(), kernel ); + SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel ); } }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 990b328a422..6cd3ba1ca1c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -40,6 +40,7 @@ #include "physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" @@ -1283,7 +1284,7 @@ CompositionalMultiphaseWell::scalingForSystemSolution( DomainPartition & domain, // check that pressure and component densities are non-negative auto const subRegionData = compositionalMultiphaseWellKernels:: - ScalingForSystemSolutionKernelFactory:: + SolutionScalingKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, m_maxAbsolutePresChange, m_maxCompFracChange, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index ca5c95ab26b..9d1d8f7676f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -33,6 +33,9 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/WellSolverBaseFields.hpp" @@ -903,12 +906,12 @@ class ResidualNormKernelFactory }; -/******************************** ScalingForSystemSolutionKernel ********************************/ +/******************************** SolutionScalingKernel ********************************/ /** - * @class ScalingForSystemSolutionKernelFactory + * @class SolutionScalingKernelFactory */ -class ScalingForSystemSolutionKernelFactory +class SolutionScalingKernelFactory { public: @@ -926,7 +929,7 @@ class ScalingForSystemSolutionKernelFactory * @param[in] localSolution the Newton update */ template< typename POLICY > - static isothermalCompositionalMultiphaseBaseKernels::ScalingForSystemSolutionKernel::StackVariables + static isothermalCompositionalMultiphaseBaseKernels::SolutionScalingKernel::StackVariables createAndLaunch( real64 const maxRelativePresChange, real64 const maxAbsolutePresChange, real64 const maxCompFracChange, @@ -946,10 +949,10 @@ class ScalingForSystemSolutionKernelFactory arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::well::globalCompDensityScalingFactor >(); isothermalCompositionalMultiphaseBaseKernels:: - ScalingForSystemSolutionKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset, + SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset, numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); return isothermalCompositionalMultiphaseBaseKernels:: - ScalingForSystemSolutionKernel:: + SolutionScalingKernel:: launch< POLICY >( subRegion.size(), kernel ); } From da6ed323ffbaf964ddb902fee4a250b60408d9bd Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Sat, 28 Sep 2024 13:37:50 -0500 Subject: [PATCH 21/47] isothermal accum kernel --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 2 +- .../fluidFlow/CompositionalMultiphaseBase.cpp | 6 ++--- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 2 +- .../CompositionalMultiphaseHybridFVM.cpp | 2 +- .../CompositionalMultiphaseStatistics.cpp | 4 +-- ...BaseKernels.hpp => AccumulationKernel.hpp} | 26 +++++++++---------- ...ompositionalMultiphaseHybridFVMKernels.hpp | 3 ++- ...ermalCompositionalMultiphaseFVMKernels.hpp | 4 ++- .../compositional/KernelLaunchSelector.hpp | 10 ------- ...rmalCompositionalMultiphaseBaseKernels.hpp | 23 ++++++++-------- .../wells/CompositionalMultiphaseWell.cpp | 2 +- .../CompositionalMultiphaseWellKernels.hpp | 2 +- 12 files changed, 39 insertions(+), 47 deletions(-) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/{IsothermalCompositionalMultiphaseBaseKernels.hpp => AccumulationKernel.hpp} (95%) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index e808dbd9fdb..39fe55ba857 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -44,7 +44,7 @@ set( physicsSolvers_headers fluidFlow/kernels/singlePhase/ThermalFluxComputeKernel.hpp fluidFlow/kernels/singlePhase/proppant/ProppantBaseKernels.hpp fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.hpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/compositional/AccumulationKernel.hpp fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 2fa3871cb21..d0cda04269d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -41,7 +41,7 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" // TODO this should not be here #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" @@ -1414,7 +1414,7 @@ void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( Dom if( m_isThermal ) { thermalCompositionalMultiphaseBaseKernels:: - ElementBasedAssemblyKernelFactory:: + AccumulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -1429,7 +1429,7 @@ void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( Dom else { isothermalCompositionalMultiphaseBaseKernels:: - ElementBasedAssemblyKernelFactory:: + AccumulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 1afb7d70e19..374d776db5d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -34,7 +34,7 @@ #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index b8b1c8090ca..ab10c46da43 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -31,7 +31,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp index 0aaea3ab9fb..80f34fdd364 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp @@ -30,8 +30,8 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" // check if needed +#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" // check if needed #include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp similarity index 95% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp index 783aae6f0c5..333ae5dded2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file IsothermalCompositionalMultiphaseBaseKernels.hpp + * @file AccumulationKernels.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_ACCUMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_ACCUMULATIONKERNEL_HPP #include "codingUtilities/Utilities.hpp" #include "common/DataLayouts.hpp" @@ -57,16 +57,16 @@ enum class AccumulationKernelFlags // Flag8 = 1 << 7 //128 }; -/******************************** ElementBasedAssemblyKernel ********************************/ +/******************************** AccumulationKernel ********************************/ /** - * @class ElementBasedAssemblyKernel + * @class AccumulationKernel * @tparam NUM_COMP number of fluid components * @tparam NUM_DOF number of degrees of freedom * @brief Define the interface for the assembly kernel in charge of accumulation and volume balance */ template< integer NUM_COMP, integer NUM_DOF > -class ElementBasedAssemblyKernel +class AccumulationKernel { public: @@ -90,7 +90,7 @@ class ElementBasedAssemblyKernel * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - ElementBasedAssemblyKernel( localIndex const numPhases, + AccumulationKernel( localIndex const numPhases, globalIndex const rankOffset, string const dofKey, ElementSubRegionBase const & subRegion, @@ -454,9 +454,9 @@ class ElementBasedAssemblyKernel }; /** - * @class ElementBasedAssemblyKernelFactory + * @class AccumulationKernelFactory */ -class ElementBasedAssemblyKernelFactory +class AccumulationKernelFactory { public: @@ -498,9 +498,9 @@ class ElementBasedAssemblyKernelFactory if( useSimpleAccumulation ) kernelFlags.set( AccumulationKernelFlags::SimpleAccumulation ); - ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF > - kernel( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ); - ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); + AccumulationKernel< NUM_COMP, NUM_DOF > kernel( numPhases, rankOffset, dofKey, subRegion, + fluid, solid, localMatrix, localRhs, kernelFlags ); + AccumulationKernel< NUM_COMP, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); } ); } @@ -511,4 +511,4 @@ class ElementBasedAssemblyKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_ACCUMULATIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp index fb236b0fa4f..ac6fee0e23c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp @@ -32,8 +32,9 @@ #include "mesh/ObjectManagerBase.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp index af484124b75..31f39d1e7fb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp @@ -33,6 +33,7 @@ #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" #include "constitutive/permeability/PermeabilityFields.hpp" #include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" #include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" @@ -47,7 +48,8 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +//#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp index 21982d01284..d69767bd128 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp @@ -24,16 +24,6 @@ #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "functions/TableFunction.hpp" -#include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp index 5e99ab07feb..d27dc8d0fdb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" @@ -138,20 +138,20 @@ class PhaseVolumeFractionKernelFactory }; -/******************************** ElementBasedAssemblyKernel ********************************/ +/******************************** AccumulationKernel ********************************/ /** - * @class ElementBasedAssemblyKernel + * @class AccumulationKernel * @tparam NUM_COMP number of fluid components * @tparam NUM_DOF number of degrees of freedom * @brief Define the interface for the assembly kernel in charge of thermal accumulation and volume balance */ template< localIndex NUM_COMP, localIndex NUM_DOF > -class ElementBasedAssemblyKernel : public isothermalCompositionalMultiphaseBaseKernels::ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF > +class AccumulationKernel : public isothermalCompositionalMultiphaseBaseKernels::AccumulationKernel< NUM_COMP, NUM_DOF > { public: - using Base = isothermalCompositionalMultiphaseBaseKernels::ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF >; + using Base = isothermalCompositionalMultiphaseBaseKernels::AccumulationKernel< NUM_COMP, NUM_DOF >; using Base::numComp; using Base::numDof; using Base::numEqn; @@ -183,7 +183,7 @@ class ElementBasedAssemblyKernel : public isothermalCompositionalMultiphaseBaseK * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - ElementBasedAssemblyKernel( localIndex const numPhases, + AccumulationKernel( localIndex const numPhases, globalIndex const rankOffset, string const dofKey, ElementSubRegionBase const & subRegion, @@ -397,9 +397,9 @@ class ElementBasedAssemblyKernel : public isothermalCompositionalMultiphaseBaseK }; /** - * @class ElementBasedAssemblyKernelFactory + * @class AccumulationKernelFactory */ -class ElementBasedAssemblyKernelFactory +class AccumulationKernelFactory { public: @@ -439,10 +439,9 @@ class ElementBasedAssemblyKernelFactory if( useTotalMassEquation ) kernelFlags.set( isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags::TotalMassEquation ); - ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF > - kernel( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ); - ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF >::template - launch< POLICY, ElementBasedAssemblyKernel< NUM_COMP, NUM_DOF > >( subRegion.size(), kernel ); + AccumulationKernel< NUM_COMP, NUM_DOF > kernel( numPhases, rankOffset, dofKey, subRegion, + fluid, solid, localMatrix, localRhs, kernelFlags ); + AccumulationKernel< NUM_COMP, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); } ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 6cd3ba1ca1c..0bb47d1b154 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -38,7 +38,7 @@ #include "physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWellFields.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index 9d1d8f7676f..280cdf8dcf1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -32,7 +32,7 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" From 1ebcd9af98fc6f2387e733f58a88861fd1813849 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Sat, 28 Sep 2024 15:09:55 -0500 Subject: [PATCH 22/47] thermal accum --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 6 +- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 6 +- .../compositional/FluidUpdateKernel.hpp | 77 ++ .../compositional/PhaseMobilityKernel.hpp | 2 +- .../compositional/PropertyKernelBase.hpp | 4 +- .../compositional/ResidualNormKernel.hpp | 13 - .../SolidInternalEnergyUpdateKernel.hpp | 55 + .../ThermalAccumulationKernel.hpp | 345 ++++++ ...rmalCompositionalMultiphaseBaseKernels.hpp | 1045 ----------------- ...ermalCompositionalMultiphaseFVMKernels.hpp | 1 + .../ThermalPhaseVolumeFractionKernel.hpp | 140 +++ .../ThermalResidualNormKernel.hpp | 241 ++++ .../ThermalSolutionCheckKernel.hpp | 177 +++ .../ThermalSolutionScalingKernel.hpp | 221 ++++ .../wells/CompositionalMultiphaseWell.cpp | 5 +- 15 files changed, 1274 insertions(+), 1064 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index d0cda04269d..13d65723666 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -43,10 +43,14 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" // TODO this should not be here -#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 374d776db5d..a48926fd0bd 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -35,13 +35,17 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp new file mode 100644 index 00000000000..9389da529de --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp @@ -0,0 +1,77 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluidUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUIDUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUIDUPDATEKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseBaseKernels +{ + +/******************************** FluidUpdateKernel ********************************/ + +struct FluidUpdateKernel +{ + template< typename POLICY, typename FLUID_WRAPPER > + static void + launch( localIndex const size, + FLUID_WRAPPER const & fluidWrapper, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & temp, + arrayView2d< real64 const, compflow::USD_COMP > const & compFrac ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) + { + fluidWrapper.update( k, q, pres[k], temp[k], compFrac[k] ); + } + } ); + } + + template< typename POLICY, typename FLUID_WRAPPER > + static void + launch( SortedArrayView< localIndex const > const & targetSet, + FLUID_WRAPPER const & fluidWrapper, + arrayView1d< real64 const > const & pres, + arrayView1d< real64 const > const & temp, + arrayView2d< real64 const, compflow::USD_COMP > const & compFrac ) + { + forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) + { + localIndex const k = targetSet[a]; + for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) + { + fluidWrapper.update( k, q, pres[k], temp[k], compFrac[k] ); + } + } ); + } +}; + +} // namespace thermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp index 450cfff1ba3..1886cdbe4f5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp @@ -34,7 +34,7 @@ namespace isothermalCompositionalMultiphaseFVMKernels * @class PhaseMobilityKernel * @tparam NUM_COMP number of fluid components * @tparam NUM_PHASE number of fluid phases - * @brief Define the interface for the property kernel in charge of computing the phase mobilities + * @brief Defines the interface for the property kernel in charge of computing the phase mobilities */ template< integer NUM_COMP, integer NUM_PHASE > class PhaseMobilityKernel : public isothermalCompositionalMultiphaseBaseKernels::PropertyKernelBase< NUM_COMP > diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp index 6d1532031a1..a7e693f2e81 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp @@ -22,8 +22,8 @@ //#include "codingUtilities/Utilities.hpp" //#include "common/DataLayouts.hpp" -//#include "common/DataTypes.hpp" -//#include "common/GEOS_RAJA_Interface.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" //#include "constitutive/solid/CoupledSolidBase.hpp" //#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" //#include "functions/TableFunction.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp index 134460ca4cf..b1a9603fa59 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp @@ -20,20 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RESIDUALNORMKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RESIDUALNORMKERNEL_HPP -#include "codingUtilities/Utilities.hpp" -#include "common/DataLayouts.hpp" -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "functions/TableFunction.hpp" -#include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp new file mode 100644 index 00000000000..059be14db29 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp @@ -0,0 +1,55 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SolidInternalEnergyUpdateKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLIDINTERNALENERGYUPDATEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLIDINTERNALENERGYUPDATEKERNEL_HPP + +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseBaseKernels +{ + +/******************************** SolidInternalEnergyUpdateKernel ********************************/ + +struct SolidInternalEnergyUpdateKernel +{ + + template< typename POLICY, typename SOLID_INTERNAL_ENERGY_WRAPPER > + static void + launch( localIndex const size, + SOLID_INTERNAL_ENERGY_WRAPPER const & solidInternalEnergyWrapper, + arrayView1d< real64 const > const & temp ) + { + forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) + { + solidInternalEnergyWrapper.update( k, temp[k] ); + } ); + } +}; + +} // namespace thermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALACCUMULATIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp new file mode 100644 index 00000000000..fd5b059f6ea --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp @@ -0,0 +1,345 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalAccumulationKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALACCUMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALACCUMULATIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseBaseKernels +{ + +/******************************** AccumulationKernel ********************************/ + +/** + * @class AccumulationKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @brief Define the interface for the assembly kernel in charge of thermal accumulation and volume balance + */ +template< localIndex NUM_COMP, localIndex NUM_DOF > +class AccumulationKernel : public isothermalCompositionalMultiphaseBaseKernels::AccumulationKernel< NUM_COMP, NUM_DOF > +{ +public: + + using Base = isothermalCompositionalMultiphaseBaseKernels::AccumulationKernel< NUM_COMP, NUM_DOF >; + using Base::numComp; + using Base::numDof; + using Base::numEqn; + using Base::m_numPhases; + using Base::m_rankOffset; + using Base::m_dofNumber; + using Base::m_elemGhostRank; + using Base::m_volume; + using Base::m_porosity; + using Base::m_dPoro_dPres; + using Base::m_dCompFrac_dCompDens; + using Base::m_phaseVolFrac; + using Base::m_dPhaseVolFrac; + using Base::m_phaseDens; + using Base::m_dPhaseDens; + using Base::m_phaseCompFrac; + using Base::m_dPhaseCompFrac; + using Base::m_localMatrix; + using Base::m_localRhs; + + /** + * @brief Constructor + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + AccumulationKernel( localIndex const numPhases, + globalIndex const rankOffset, + string const dofKey, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > const kernelFlags ) + : Base( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ), + m_dPoro_dTemp( solid.getDporosity_dTemperature() ), + m_phaseInternalEnergy( fluid.phaseInternalEnergy() ), + m_dPhaseInternalEnergy( fluid.dPhaseInternalEnergy() ), + m_rockInternalEnergy( solid.getInternalEnergy() ), + m_dRockInternalEnergy_dTemp( solid.getDinternalEnergy_dTemperature() ), + m_energy_n( subRegion.getField< fields::flow::energy_n >() ) + {} + + struct StackVariables : public Base::StackVariables + { +public: + + GEOS_HOST_DEVICE + StackVariables() + : Base::StackVariables() + {} + + using Base::StackVariables::localRow; + using Base::StackVariables::dofIndices; + using Base::StackVariables::localResidual; + using Base::StackVariables::localJacobian; + + // derivative of pore volume wrt temperature + real64 dPoreVolume_dTemp = 0.0; + + // Solid energy + + /// Solid energy at time n+1 + real64 solidEnergy = 0.0; + + /// Derivative of solid internal energy with respect to pressure + real64 dSolidEnergy_dPres = 0.0; + + /// Derivative of solid internal energy with respect to temperature + real64 dSolidEnergy_dTemp = 0.0; + + }; + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] ei the element index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + Base::setup( ei, stack ); + + // derivative of pore volume wrt temperature + stack.dPoreVolume_dTemp = m_volume[ei] * m_dPoro_dTemp[ei][0]; + + // initialize the solid volume + real64 const solidVolume = m_volume[ei] * ( 1.0 - m_porosity[ei][0] ); + real64 const dSolidVolume_dPres = -m_volume[ei] * m_dPoro_dPres[ei][0]; + real64 const dSolidVolume_dTemp = -stack.dPoreVolume_dTemp; + + // initialize the solid internal energy + stack.solidEnergy = solidVolume * m_rockInternalEnergy[ei][0]; + stack.dSolidEnergy_dPres = dSolidVolume_dPres * m_rockInternalEnergy[ei][0]; + stack.dSolidEnergy_dTemp = solidVolume * m_dRockInternalEnergy_dTemp[ei][0] + + dSolidVolume_dTemp * m_rockInternalEnergy[ei][0]; + } + + /** + * @brief Compute the local accumulation contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void computeAccumulation( localIndex const ei, + StackVariables & stack ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + // start with old time step value + stack.localResidual[numEqn-1] = -m_energy_n[ei]; + + Base::computeAccumulation( ei, stack, [&] ( integer const ip, + real64 const & phaseAmount, + real64 const & dPhaseAmount_dP, + real64 const (&dPhaseAmount_dC)[numComp] ) + { + // We are in the loop over phases, ip provides the current phase index. + // We have to do two things: + // 1- Assemble the derivatives of the component mass balance equations with respect to temperature + // 2- Assemble the phase-dependent part of the accumulation term of the energy equation + + real64 dPhaseInternalEnergy_dC[numComp]{}; + + // construct the slices + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac = m_phaseVolFrac[ei]; + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 2 > phaseCompFrac = m_phaseCompFrac[ei][0]; + arraySlice3d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac = m_dPhaseCompFrac[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseInternalEnergy = m_phaseInternalEnergy[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseInternalEnergy = m_dPhaseInternalEnergy[ei][0]; + + // Step 1: assemble the derivatives of the component mass balance equations with respect to temperature + + real64 const dPhaseAmount_dT = stack.dPoreVolume_dTemp * phaseVolFrac[ip] * phaseDens[ip] + + stack.poreVolume * (dPhaseVolFrac[ip][Deriv::dT] * phaseDens[ip] + phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dT] ); + for( integer ic = 0; ic < numComp; ++ic ) + { + stack.localJacobian[ic][numDof-1] += dPhaseAmount_dT * phaseCompFrac[ip][ic] + + phaseAmount * dPhaseCompFrac[ip][ic][Deriv::dT]; + } + + // Step 2: assemble the phase-dependent part of the accumulation term of the energy equation + + real64 const phaseEnergy = phaseAmount * phaseInternalEnergy[ip]; + real64 const dPhaseEnergy_dP = dPhaseAmount_dP * phaseInternalEnergy[ip] + + phaseAmount * dPhaseInternalEnergy[ip][Deriv::dP]; + real64 const dPhaseEnergy_dT = dPhaseAmount_dT * phaseInternalEnergy[ip] + + phaseAmount * dPhaseInternalEnergy[ip][Deriv::dT]; + + // local accumulation + stack.localResidual[numEqn-1] += phaseEnergy; + + // derivatives w.r.t. pressure and temperature + stack.localJacobian[numEqn-1][0] += dPhaseEnergy_dP; + stack.localJacobian[numEqn-1][numDof-1] += dPhaseEnergy_dT; + + // derivatives w.r.t. component densities + applyChainRule( numComp, dCompFrac_dCompDens, dPhaseInternalEnergy[ip], dPhaseInternalEnergy_dC, Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.localJacobian[numEqn-1][jc + 1] += phaseInternalEnergy[ip] * dPhaseAmount_dC[jc] + + dPhaseInternalEnergy_dC[jc] * phaseAmount; + } + } ); + + // Step 3: assemble the solid part of the accumulation term + + // local accumulation and derivatives w.r.t. pressure and temperature + stack.localResidual[numEqn-1] += stack.solidEnergy; + stack.localJacobian[numEqn-1][0] += stack.dSolidEnergy_dPres; + stack.localJacobian[numEqn-1][numDof-1] += stack.dSolidEnergy_dTemp; + + } + + /** + * @brief Compute the local volume balance contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void computeVolumeBalance( localIndex const ei, + StackVariables & stack ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + Base::computeVolumeBalance( ei, stack, [&] ( real64 const & oneMinusPhaseVolFraction ) + { + GEOS_UNUSED_VAR( oneMinusPhaseVolFraction ); + + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; + + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + stack.localJacobian[numEqn-2][numDof-1] -= dPhaseVolFrac[ip][Deriv::dT]; + } + } ); + } + + GEOS_HOST_DEVICE + void complete( localIndex const ei, + StackVariables & stack ) const + { + // Step 1: assemble the component mass balance equations and volume balance equations + Base::complete( ei, stack ); + + // Step 2: assemble the energy equation + m_localRhs[stack.localRow + numEqn-1] += stack.localResidual[numEqn-1]; + m_localMatrix.template addToRow< serialAtomic >( stack.localRow + numEqn-1, + stack.dofIndices, + stack.localJacobian[numEqn-1], + numDof ); + } + +protected: + + /// View on derivative of porosity w.r.t temperature + arrayView2d< real64 const > const m_dPoro_dTemp; + + /// Views on phase internal energy + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseInternalEnergy; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseInternalEnergy; + + /// Views on rock internal energy + arrayView2d< real64 const > m_rockInternalEnergy; + arrayView2d< real64 const > m_dRockInternalEnergy_dTemp; + + /// Views on energy + arrayView1d< real64 const > m_energy_n; + +}; + +/** + * @class AccumulationKernelFactory + */ +class AccumulationKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY > + static void + createAndLaunch( localIndex const numComps, + localIndex const numPhases, + globalIndex const rankOffset, + integer const useTotalMassEquation, + string const dofKey, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + isothermalCompositionalMultiphaseBaseKernels:: + internal::kernelLaunchSelectorCompSwitch( numComps, [&] ( auto NC ) + { + localIndex constexpr NUM_COMP = NC(); + localIndex constexpr NUM_DOF = NC()+2; + + BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > kernelFlags; + if( useTotalMassEquation ) + kernelFlags.set( isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags::TotalMassEquation ); + + AccumulationKernel< NUM_COMP, NUM_DOF > kernel( numPhases, rankOffset, dofKey, subRegion, + fluid, solid, localMatrix, localRhs, kernelFlags ); + AccumulationKernel< NUM_COMP, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + +}; + +} // namespace thermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALACCUMULATIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp deleted file mode 100644 index d27dc8d0fdb..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp +++ /dev/null @@ -1,1045 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 ThermalCompositionalMultiphaseBaseKernels.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP - -#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" - -namespace geos -{ - -namespace thermalCompositionalMultiphaseBaseKernels -{ - - -/******************************** PhaseVolumeFractionKernel ********************************/ - -/** - * @class PhaseVolumeFractionKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_PHASE number of fluid phases - * @brief Define the interface for the property kernel in charge of computing the phase volume fractions - */ -template< integer NUM_COMP, integer NUM_PHASE > -class PhaseVolumeFractionKernel : public isothermalCompositionalMultiphaseBaseKernels::PhaseVolumeFractionKernel< NUM_COMP, NUM_PHASE > -{ -public: - - using Base = isothermalCompositionalMultiphaseBaseKernels::PhaseVolumeFractionKernel< NUM_COMP, NUM_PHASE >; - using Base::m_dPhaseDens; - using Base::m_dPhaseFrac; - using Base::m_dPhaseVolFrac; - - /** - * @brief Constructor - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - */ - PhaseVolumeFractionKernel( ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid ) - : Base( subRegion, fluid ) - {} - - /** - * @brief Compute the phase volume fractions in an element - * @param[in] ei the element index - */ - GEOS_HOST_DEVICE - real64 compute( localIndex const ei ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; - - arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; - - // Call the base compute the compute the phase volume fraction - return Base::compute( ei, [&] ( localIndex const ip, - real64 const & phaseVolFrac, - real64 const & phaseDensInv, - real64 const & totalDensity ) - { - // when this lambda is called, we are in the phase loop - // for each phase ip, compute the derivative of phase volume fraction wrt temperature - dPhaseVolFrac[ip][Deriv::dT] = (dPhaseFrac[ip][Deriv::dT] - phaseVolFrac * dPhaseDens[ip][Deriv::dT]) * phaseDensInv; - dPhaseVolFrac[ip][Deriv::dT] *= totalDensity; - } ); - } - -}; - -/** - * @class PhaseVolumeFractionKernelFactory - */ -class PhaseVolumeFractionKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComp the number of fluid components - * @param[in] numPhase the number of fluid phases - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - */ - template< typename POLICY > - static real64 - createAndLaunch( integer const numComp, - integer const numPhase, - ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid ) - { - real64 maxDeltaPhaseVolFrac = 0.0; - if( numPhase == 2 ) - { - isothermalCompositionalMultiphaseBaseKernels:: - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseVolumeFractionKernel< NUM_COMP, 2 > kernel( subRegion, fluid ); - maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - else if( numPhase == 3 ) - { - isothermalCompositionalMultiphaseBaseKernels:: - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseVolumeFractionKernel< NUM_COMP, 3 > kernel( subRegion, fluid ); - maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - return maxDeltaPhaseVolFrac; - } -}; - - -/******************************** AccumulationKernel ********************************/ - -/** - * @class AccumulationKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @brief Define the interface for the assembly kernel in charge of thermal accumulation and volume balance - */ -template< localIndex NUM_COMP, localIndex NUM_DOF > -class AccumulationKernel : public isothermalCompositionalMultiphaseBaseKernels::AccumulationKernel< NUM_COMP, NUM_DOF > -{ -public: - - using Base = isothermalCompositionalMultiphaseBaseKernels::AccumulationKernel< NUM_COMP, NUM_DOF >; - using Base::numComp; - using Base::numDof; - using Base::numEqn; - using Base::m_numPhases; - using Base::m_rankOffset; - using Base::m_dofNumber; - using Base::m_elemGhostRank; - using Base::m_volume; - using Base::m_porosity; - using Base::m_dPoro_dPres; - using Base::m_dCompFrac_dCompDens; - using Base::m_phaseVolFrac; - using Base::m_dPhaseVolFrac; - using Base::m_phaseDens; - using Base::m_dPhaseDens; - using Base::m_phaseCompFrac; - using Base::m_dPhaseCompFrac; - using Base::m_localMatrix; - using Base::m_localRhs; - - /** - * @brief Constructor - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - AccumulationKernel( localIndex const numPhases, - globalIndex const rankOffset, - string const dofKey, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > const kernelFlags ) - : Base( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ), - m_dPoro_dTemp( solid.getDporosity_dTemperature() ), - m_phaseInternalEnergy( fluid.phaseInternalEnergy() ), - m_dPhaseInternalEnergy( fluid.dPhaseInternalEnergy() ), - m_rockInternalEnergy( solid.getInternalEnergy() ), - m_dRockInternalEnergy_dTemp( solid.getDinternalEnergy_dTemperature() ), - m_energy_n( subRegion.getField< fields::flow::energy_n >() ) - {} - - struct StackVariables : public Base::StackVariables - { -public: - - GEOS_HOST_DEVICE - StackVariables() - : Base::StackVariables() - {} - - using Base::StackVariables::localRow; - using Base::StackVariables::dofIndices; - using Base::StackVariables::localResidual; - using Base::StackVariables::localJacobian; - - // derivative of pore volume wrt temperature - real64 dPoreVolume_dTemp = 0.0; - - // Solid energy - - /// Solid energy at time n+1 - real64 solidEnergy = 0.0; - - /// Derivative of solid internal energy with respect to pressure - real64 dSolidEnergy_dPres = 0.0; - - /// Derivative of solid internal energy with respect to temperature - real64 dSolidEnergy_dTemp = 0.0; - - }; - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] ei the element index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - void setup( localIndex const ei, - StackVariables & stack ) const - { - Base::setup( ei, stack ); - - // derivative of pore volume wrt temperature - stack.dPoreVolume_dTemp = m_volume[ei] * m_dPoro_dTemp[ei][0]; - - // initialize the solid volume - real64 const solidVolume = m_volume[ei] * ( 1.0 - m_porosity[ei][0] ); - real64 const dSolidVolume_dPres = -m_volume[ei] * m_dPoro_dPres[ei][0]; - real64 const dSolidVolume_dTemp = -stack.dPoreVolume_dTemp; - - // initialize the solid internal energy - stack.solidEnergy = solidVolume * m_rockInternalEnergy[ei][0]; - stack.dSolidEnergy_dPres = dSolidVolume_dPres * m_rockInternalEnergy[ei][0]; - stack.dSolidEnergy_dTemp = solidVolume * m_dRockInternalEnergy_dTemp[ei][0] - + dSolidVolume_dTemp * m_rockInternalEnergy[ei][0]; - } - - /** - * @brief Compute the local accumulation contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void computeAccumulation( localIndex const ei, - StackVariables & stack ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - // start with old time step value - stack.localResidual[numEqn-1] = -m_energy_n[ei]; - - Base::computeAccumulation( ei, stack, [&] ( integer const ip, - real64 const & phaseAmount, - real64 const & dPhaseAmount_dP, - real64 const (&dPhaseAmount_dC)[numComp] ) - { - // We are in the loop over phases, ip provides the current phase index. - // We have to do two things: - // 1- Assemble the derivatives of the component mass balance equations with respect to temperature - // 2- Assemble the phase-dependent part of the accumulation term of the energy equation - - real64 dPhaseInternalEnergy_dC[numComp]{}; - - // construct the slices - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; - arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac = m_phaseVolFrac[ei]; - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseDens = m_phaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseDens = m_dPhaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 2 > phaseCompFrac = m_phaseCompFrac[ei][0]; - arraySlice3d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac = m_dPhaseCompFrac[ei][0]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseInternalEnergy = m_phaseInternalEnergy[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseInternalEnergy = m_dPhaseInternalEnergy[ei][0]; - - // Step 1: assemble the derivatives of the component mass balance equations with respect to temperature - - real64 const dPhaseAmount_dT = stack.dPoreVolume_dTemp * phaseVolFrac[ip] * phaseDens[ip] - + stack.poreVolume * (dPhaseVolFrac[ip][Deriv::dT] * phaseDens[ip] + phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dT] ); - for( integer ic = 0; ic < numComp; ++ic ) - { - stack.localJacobian[ic][numDof-1] += dPhaseAmount_dT * phaseCompFrac[ip][ic] - + phaseAmount * dPhaseCompFrac[ip][ic][Deriv::dT]; - } - - // Step 2: assemble the phase-dependent part of the accumulation term of the energy equation - - real64 const phaseEnergy = phaseAmount * phaseInternalEnergy[ip]; - real64 const dPhaseEnergy_dP = dPhaseAmount_dP * phaseInternalEnergy[ip] - + phaseAmount * dPhaseInternalEnergy[ip][Deriv::dP]; - real64 const dPhaseEnergy_dT = dPhaseAmount_dT * phaseInternalEnergy[ip] - + phaseAmount * dPhaseInternalEnergy[ip][Deriv::dT]; - - // local accumulation - stack.localResidual[numEqn-1] += phaseEnergy; - - // derivatives w.r.t. pressure and temperature - stack.localJacobian[numEqn-1][0] += dPhaseEnergy_dP; - stack.localJacobian[numEqn-1][numDof-1] += dPhaseEnergy_dT; - - // derivatives w.r.t. component densities - applyChainRule( numComp, dCompFrac_dCompDens, dPhaseInternalEnergy[ip], dPhaseInternalEnergy_dC, Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.localJacobian[numEqn-1][jc + 1] += phaseInternalEnergy[ip] * dPhaseAmount_dC[jc] - + dPhaseInternalEnergy_dC[jc] * phaseAmount; - } - } ); - - // Step 3: assemble the solid part of the accumulation term - - // local accumulation and derivatives w.r.t. pressure and temperature - stack.localResidual[numEqn-1] += stack.solidEnergy; - stack.localJacobian[numEqn-1][0] += stack.dSolidEnergy_dPres; - stack.localJacobian[numEqn-1][numDof-1] += stack.dSolidEnergy_dTemp; - - } - - /** - * @brief Compute the local volume balance contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void computeVolumeBalance( localIndex const ei, - StackVariables & stack ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - Base::computeVolumeBalance( ei, stack, [&] ( real64 const & oneMinusPhaseVolFraction ) - { - GEOS_UNUSED_VAR( oneMinusPhaseVolFraction ); - - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac = m_dPhaseVolFrac[ei]; - - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - stack.localJacobian[numEqn-2][numDof-1] -= dPhaseVolFrac[ip][Deriv::dT]; - } - } ); - } - - GEOS_HOST_DEVICE - void complete( localIndex const ei, - StackVariables & stack ) const - { - // Step 1: assemble the component mass balance equations and volume balance equations - Base::complete( ei, stack ); - - // Step 2: assemble the energy equation - m_localRhs[stack.localRow + numEqn-1] += stack.localResidual[numEqn-1]; - m_localMatrix.template addToRow< serialAtomic >( stack.localRow + numEqn-1, - stack.dofIndices, - stack.localJacobian[numEqn-1], - numDof ); - } - -protected: - - /// View on derivative of porosity w.r.t temperature - arrayView2d< real64 const > const m_dPoro_dTemp; - - /// Views on phase internal energy - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseInternalEnergy; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseInternalEnergy; - - /// Views on rock internal energy - arrayView2d< real64 const > m_rockInternalEnergy; - arrayView2d< real64 const > m_dRockInternalEnergy_dTemp; - - /// Views on energy - arrayView1d< real64 const > m_energy_n; - -}; - -/** - * @class AccumulationKernelFactory - */ -class AccumulationKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( localIndex const numComps, - localIndex const numPhases, - globalIndex const rankOffset, - integer const useTotalMassEquation, - string const dofKey, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - isothermalCompositionalMultiphaseBaseKernels:: - internal::kernelLaunchSelectorCompSwitch( numComps, [&] ( auto NC ) - { - localIndex constexpr NUM_COMP = NC(); - localIndex constexpr NUM_DOF = NC()+2; - - BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > kernelFlags; - if( useTotalMassEquation ) - kernelFlags.set( isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags::TotalMassEquation ); - - AccumulationKernel< NUM_COMP, NUM_DOF > kernel( numPhases, rankOffset, dofKey, subRegion, - fluid, solid, localMatrix, localRhs, kernelFlags ); - AccumulationKernel< NUM_COMP, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - -}; - -/******************************** FluidUpdateKernel ********************************/ - -struct FluidUpdateKernel -{ - template< typename POLICY, typename FLUID_WRAPPER > - static void - launch( localIndex const size, - FLUID_WRAPPER const & fluidWrapper, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & temp, - arrayView2d< real64 const, compflow::USD_COMP > const & compFrac ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) - { - fluidWrapper.update( k, q, pres[k], temp[k], compFrac[k] ); - } - } ); - } - - template< typename POLICY, typename FLUID_WRAPPER > - static void - launch( SortedArrayView< localIndex const > const & targetSet, - FLUID_WRAPPER const & fluidWrapper, - arrayView1d< real64 const > const & pres, - arrayView1d< real64 const > const & temp, - arrayView2d< real64 const, compflow::USD_COMP > const & compFrac ) - { - forAll< POLICY >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) - { - localIndex const k = targetSet[a]; - for( localIndex q = 0; q < fluidWrapper.numGauss(); ++q ) - { - fluidWrapper.update( k, q, pres[k], temp[k], compFrac[k] ); - } - } ); - } -}; - -/******************************** SolidInternalEnergyUpdateKernel ********************************/ - -struct SolidInternalEnergyUpdateKernel -{ - - template< typename POLICY, typename SOLID_INTERNAL_ENERGY_WRAPPER > - static void - launch( localIndex const size, - SOLID_INTERNAL_ENERGY_WRAPPER const & solidInternalEnergyWrapper, - arrayView1d< real64 const > const & temp ) - { - forAll< POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const k ) - { - solidInternalEnergyWrapper.update( k, temp[k] ); - } ); - } -}; - -/******************************** SolutionScalingKernel ********************************/ - -/** - * @class SolutionScalingKernel - * @brief Define the kernel for scaling the Newton update - */ -class SolutionScalingKernel : public isothermalCompositionalMultiphaseBaseKernels::SolutionScalingKernel -{ -public: - - using Base = isothermalCompositionalMultiphaseBaseKernels::SolutionScalingKernel; - using Base::m_numComp; - using Base::m_localSolution; - - /** - * @brief Create a new kernel instance - * @param[in] maxRelativePresChange the max allowed relative pressure change - * @param[in] maxAbsolutePresChange the max allowed absolute pressure change - * @param[in] maxRelativeTempChange the max allowed relative temperature change - * @param[in] maxCompFracChange the max allowed comp fraction change - * @param[in] maxRelativeCompDensChange the max allowed comp density change - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - * @param[in] pressure the pressure vector - * @param[in] temperature the temperature vector - * @param[in] compDens the component density vector - * @param[in] pressureScalingFactor the pressure local scaling factor - * @param[in] compDensScalingFactor the component density local scaling factor - * @param[in] temperatureFactor the temperature local scaling factor - */ - SolutionScalingKernel( real64 const maxRelativePresChange, - real64 const maxAbsolutePresChange, - real64 const maxRelativeTempChange, - real64 const maxCompFracChange, - real64 const maxRelativeCompDensChange, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView1d< real64 const > const temperature, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor, - arrayView1d< real64 > temperatureScalingFactor ) - : Base( maxRelativePresChange, - maxAbsolutePresChange, - maxCompFracChange, - maxRelativeCompDensChange, - rankOffset, - numComp, - dofKey, - subRegion, - localSolution, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor ), - m_maxRelativeTempChange( maxRelativeTempChange ), - m_temperature( temperature ), - m_temperatureScalingFactor( temperatureScalingFactor ) - {} - - /** - * @brief Compute the local value - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void compute( localIndex const ei, - StackVariables & stack ) const - { - computeScalingFactor( ei, stack ); - } - - /** - * @brief Compute the local value of the scaling factor - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void computeScalingFactor( localIndex const ei, - StackVariables & stack ) const - { - real64 constexpr eps = isothermalCompositionalMultiphaseBaseKernels::minDensForDivision; - Base::computeScalingFactor( ei, stack, [&] () - { - // compute the change in temperature - real64 const temp = m_temperature[ei]; - real64 const absTempChange = LvArray::math::abs( m_localSolution[stack.localRow + m_numComp + 1] ); - if( stack.localMaxDeltaTemp < absTempChange ) - { - stack.localMaxDeltaTemp = absTempChange; - } - - m_temperatureScalingFactor[ei] = 1.0; - - if( temp > eps ) - { - real64 const relativeTempChange = absTempChange / temp; - if( relativeTempChange > m_maxRelativeTempChange ) - { - real64 const tempScalingFactor = m_maxRelativeTempChange / relativeTempChange; - m_temperatureScalingFactor[ei] = tempScalingFactor; - if( stack.localMinVal > tempScalingFactor ) - { - stack.localMinVal = tempScalingFactor; - } - if( stack.localMinTempScalingFactor > tempScalingFactor ) - { - stack.localMinTempScalingFactor = tempScalingFactor; - } - } - } - } ); - } - -protected: - - /// Max allowed changes in primary variables - real64 const m_maxRelativeTempChange; - - /// View on the primary variables - arrayView1d< real64 const > const m_temperature; - - /// View on the scaling factor - arrayView1d< real64 > const m_temperatureScalingFactor; - -}; - -/** - * @class SolutionScalingKernelFactory - */ -class SolutionScalingKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] maxRelativePresChange the max allowed relative pressure change - * @param[in] maxAbsolutePresChange the max allowed absolute pressure change - * @param[in] maxRelativeTempChange the max allowed relative temperature change - * @param[in] maxCompFracChange the max allowed comp fraction change - * @param[in] maxRelativeCompdensChange the max allowed relative component density change - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - */ - template< typename POLICY > - static SolutionScalingKernel::StackVariables - createAndLaunch( real64 const maxRelativePresChange, - real64 const maxAbsolutePresChange, - real64 const maxRelativeTempChange, - real64 const maxCompFracChange, - real64 const maxRelativeCompDensChange, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase & subRegion, - arrayView1d< real64 const > const localSolution ) - { - arrayView1d< real64 const > const pressure = subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const temperature = subRegion.getField< fields::flow::temperature >(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getField< fields::flow::globalCompDensity >(); - arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); - arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); - arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); - SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxRelativeTempChange, - maxCompFracChange, maxRelativeCompDensChange, - rankOffset, numComp, dofKey, subRegion, localSolution, - pressure, temperature, compDens, pressureScalingFactor, - temperatureScalingFactor, compDensScalingFactor ); - return thermalCompositionalMultiphaseBaseKernels:: - SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel ); - } - -}; - -/******************************** SolutionCheckKernel ********************************/ - -/** - * @class SolutionCheckKernel - * @brief Define the kernel for checking the updated solution - */ -class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels::SolutionCheckKernel -{ -public: - - using Base = isothermalCompositionalMultiphaseBaseKernels::SolutionCheckKernel; - using Base::m_numComp; - using Base::m_localSolution; - using Base::m_scalingFactor; - - static real64 constexpr minTemperature = constants::zeroDegreesCelsiusInKelvin; - - /** - * @brief Create a new kernel instance - * @param[in] allowCompDensChopping flag to allow the component density chopping - * @param[in] scalingFactor the scaling factor - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - * @param[in] pressure the pressure vector - * @param[in] temperature the temperature vector - * @param[in] compDens the component density vector - */ - SolutionCheckKernel( integer const allowCompDensChopping, - integer const allowNegativePressure, - CompositionalMultiphaseFVM::ScalingType const scalingType, - real64 const scalingFactor, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView1d< real64 const > const temperature, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor, - arrayView1d< real64 > temperatureScalingFactor ) - : Base( allowCompDensChopping, - allowNegativePressure, - scalingType, - scalingFactor, - rankOffset, - numComp, - dofKey, - subRegion, - localSolution, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor ), - m_temperature( temperature ), - m_temperatureScalingFactor( temperatureScalingFactor ) - {} - - /** - * @brief Compute the local value of the solution check - * @param[in] ei the element index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void computeSolutionCheck( localIndex const ei, - StackVariables & stack ) const - { - Base::computeSolutionCheck( ei, stack, [&] () - { - bool const localScaling = m_scalingType == CompositionalMultiphaseFVM::ScalingType::Local; - // compute the change in temperature - real64 const newTemp = m_temperature[ei] + (localScaling ? m_temperatureScalingFactor[ei] : m_scalingFactor * m_localSolution[stack.localRow + m_numComp + 1]); - if( newTemp < minTemperature ) - { - stack.localMinVal = 0; - } - } ); - } - -protected: - - /// View on the primary variables - arrayView1d< real64 const > const m_temperature; - - /// View on the scaling factor - arrayView1d< real64 const > const m_temperatureScalingFactor; - -}; - -/** - * @class SolutionCheckKernelFactory - */ -class SolutionCheckKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] maxRelativePresChange the max allowed relative pressure change - * @param[in] maxRelativeTempChange the max allowed relative temperature change - * @param[in] maxCompFracChange the max allowed comp fraction change - * @param[in] rankOffset the rank offset - * @param[in] numComp the number of components - * @param[in] dofKey the dof key to get dof numbers - * @param[in] subRegion the subRegion - * @param[in] localSolution the Newton update - */ - template< typename POLICY > - static SolutionCheckKernel::StackVariables - createAndLaunch( integer const allowCompDensChopping, - integer const allowNegativePressure, - CompositionalMultiphaseFVM::ScalingType const scalingType, - real64 const scalingFactor, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase & subRegion, - arrayView1d< real64 const > const localSolution ) - { - arrayView1d< real64 const > const pressure = - subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const temperature = - subRegion.getField< fields::flow::temperature >(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = - subRegion.getField< fields::flow::globalCompDensity >(); - arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); - arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); - arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); - SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, - rankOffset, numComp, dofKey, subRegion, localSolution, - pressure, temperature, compDens, pressureScalingFactor, temperatureScalingFactor, compDensScalingFactor ); - return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); - } - -}; - - -/******************************** ResidualNormKernel ********************************/ - -/** - * @class ResidualNormKernel - */ -class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 2 > -{ -public: - - using Base = ResidualNormKernelBase< 2 >; - using Base::m_minNormalizer; - using Base::m_rankOffset; - using Base::m_localResidual; - using Base::m_dofNumber; - - ResidualNormKernel( globalIndex const rankOffset, - arrayView1d< real64 const > const & localResidual, - arrayView1d< globalIndex const > const & dofNumber, - arrayView1d< localIndex const > const & ghostRank, - integer const numComponents, - integer const numPhases, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - constitutive::SolidInternalEnergy const & solidInternalEnergy, - real64 const minNormalizer ) - : Base( rankOffset, - localResidual, - dofNumber, - ghostRank, - minNormalizer ), - m_numComponents( numComponents ), - m_numPhases( numPhases ), - m_volume( subRegion.getElementVolume() ), - m_porosity_n( solid.getPorosity_n() ), - m_phaseVolFrac_n( subRegion.getField< fields::flow::phaseVolumeFraction_n >() ), - m_totalDens_n( fluid.totalDensity_n() ), - m_phaseDens_n( fluid.phaseDensity_n() ), - m_phaseInternalEnergy_n( fluid.phaseInternalEnergy_n() ), - m_solidInternalEnergy_n( solidInternalEnergy.getInternalEnergy_n() ) - {} - - GEOS_HOST_DEVICE - void computeMassEnergyNormalizers( localIndex const ei, - real64 & massNormalizer, - real64 & energyNormalizer ) const - { - massNormalizer = LvArray::math::max( m_minNormalizer, m_totalDens_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ); - real64 const poreVolume = m_porosity_n[ei][0] * m_volume[ei]; - energyNormalizer = m_solidInternalEnergy_n[ei][0] * ( 1.0 - m_porosity_n[ei][0] ) * m_volume[ei]; - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - energyNormalizer += m_phaseInternalEnergy_n[ei][0][ip] * m_phaseDens_n[ei][0][ip] * m_phaseVolFrac_n[ei][ip] * poreVolume; - } - // warning: internal energy can be negative - energyNormalizer = LvArray::math::max( m_minNormalizer, LvArray::math::abs( energyNormalizer ) ); - } - - GEOS_HOST_DEVICE - virtual void computeLinf( localIndex const ei, - LinfStackVariables & stack ) const override - { - real64 massNormalizer = 0.0, energyNormalizer = 0.0; - computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); - real64 const volumeNormalizer = LvArray::math::max( m_minNormalizer, m_porosity_n[ei][0] * m_volume[ei] ); - - // step 1: mass residual - - for( integer idof = 0; idof < m_numComponents; ++idof ) - { - real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow + idof] ) / massNormalizer; - if( valMass > stack.localValue[0] ) - { - stack.localValue[0] = valMass; - } - } - - // step 2: volume residual - - real64 const valVol = LvArray::math::abs( m_localResidual[stack.localRow + m_numComponents] ) / volumeNormalizer; - if( valVol > stack.localValue[0] ) - { - stack.localValue[0] = valVol; - } - - // step 3: energy residual - - real64 const valEnergy = LvArray::math::abs( m_localResidual[stack.localRow + m_numComponents + 1] ) / energyNormalizer; - if( valEnergy > stack.localValue[1] ) - { - stack.localValue[1] = valEnergy; - } - } - - GEOS_HOST_DEVICE - virtual void computeL2( localIndex const ei, - L2StackVariables & stack ) const override - { - // note: for the L2 norm, we bundle the volume and mass residuals/normalizers - real64 massNormalizer = 0.0, energyNormalizer = 0.0; - computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); - - // step 1: mass residual - - for( integer idof = 0; idof < m_numComponents; ++idof ) - { - stack.localValue[0] += m_localResidual[stack.localRow + idof] * m_localResidual[stack.localRow + idof]; - stack.localNormalizer[0] += massNormalizer; - } - - // step 2: volume residual - - real64 const valVol = m_localResidual[stack.localRow + m_numComponents] * m_totalDens_n[ei][0]; // we need a mass here, hence the - // multiplication - stack.localValue[0] += valVol * valVol; - stack.localNormalizer[0] += massNormalizer; - - // step 3: energy residual - - stack.localValue[1] += m_localResidual[stack.localRow + m_numComponents + 1] * m_localResidual[stack.localRow + m_numComponents + 1]; - stack.localNormalizer[1] += energyNormalizer; - } - -protected: - - /// Number of fluid components - integer const m_numComponents; - - /// Number of fluid phases - integer const m_numPhases; - - /// View on the volume - arrayView1d< real64 const > const m_volume; - - /// View on porosity at the previous converged time step - arrayView2d< real64 const > const m_porosity_n; - - /// View on phase properties at the previous converged time step - arrayView2d< real64 const, compflow::USD_PHASE > const m_phaseVolFrac_n; - arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const m_totalDens_n; - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseDens_n; - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseInternalEnergy_n; - - /// View on solid properties at the previous converged time step - arrayView2d< real64 const > const m_solidInternalEnergy_n; - -}; - -/** - * @class ResidualNormKernelFactory - */ -class ResidualNormKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] normType the type of norm used (Linf or L2) - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey the string key to retrieve the degress of freedom numbers - * @param[in] localResidual the residual vector on my MPI rank - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] solid the solid model - * @param[in] solidInternalEnergy the solid internal energy model - * @param[out] residualNorm the residual norm on the subRegion - * @param[out] residualNormalizer the residual normalizer on the subRegion - */ - template< typename POLICY > - static void - createAndLaunch( solverBaseKernels::NormType const normType, - integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - string const & dofKey, - arrayView1d< real64 const > const & localResidual, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - constitutive::SolidInternalEnergy const & solidInternalEnergy, - real64 const minNormalizer, - real64 (& residualNorm)[2], - real64 (& residualNormalizer)[2] ) - { - arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); - arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - - ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, - numComps, numPhases, subRegion, fluid, solid, solidInternalEnergy, minNormalizer ); - if( normType == solverBaseKernels::NormType::Linf ) - { - ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); - } - else // L2 norm - { - ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); - } - - } -}; - - -} // namespace thermalCompositionalMultiphaseBaseKernels - -} // namespace geos - - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEBASEKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp index e7d049e43a9..efe3acdc89a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp @@ -21,6 +21,7 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" #include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp new file mode 100644 index 00000000000..375fecd1cea --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp @@ -0,0 +1,140 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalPhaseVolumeFractionKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALPHASEVOLUMEFRACTIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALPHASEVOLUMEFRACTIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseBaseKernels +{ + +/******************************** PhaseVolumeFractionKernel ********************************/ + +/** + * @class PhaseVolumeFractionKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_PHASE number of fluid phases + * @brief Define the interface for the property kernel in charge of computing the phase volume fractions + */ +template< integer NUM_COMP, integer NUM_PHASE > +class PhaseVolumeFractionKernel : public isothermalCompositionalMultiphaseBaseKernels::PhaseVolumeFractionKernel< NUM_COMP, NUM_PHASE > +{ +public: + + using Base = isothermalCompositionalMultiphaseBaseKernels::PhaseVolumeFractionKernel< NUM_COMP, NUM_PHASE >; + using Base::m_dPhaseDens; + using Base::m_dPhaseFrac; + using Base::m_dPhaseVolFrac; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + PhaseVolumeFractionKernel( ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid ) + : Base( subRegion, fluid ) + {} + + /** + * @brief Compute the phase volume fractions in an element + * @param[in] ei the element index + */ + GEOS_HOST_DEVICE + real64 compute( localIndex const ei ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; + + arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; + + // Call the base compute the compute the phase volume fraction + return Base::compute( ei, [&] ( localIndex const ip, + real64 const & phaseVolFrac, + real64 const & phaseDensInv, + real64 const & totalDensity ) + { + // when this lambda is called, we are in the phase loop + // for each phase ip, compute the derivative of phase volume fraction wrt temperature + dPhaseVolFrac[ip][Deriv::dT] = (dPhaseFrac[ip][Deriv::dT] - phaseVolFrac * dPhaseDens[ip][Deriv::dT]) * phaseDensInv; + dPhaseVolFrac[ip][Deriv::dT] *= totalDensity; + } ); + } + +}; + +/** + * @class PhaseVolumeFractionKernelFactory + */ +class PhaseVolumeFractionKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] numPhase the number of fluid phases + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + template< typename POLICY > + static real64 + createAndLaunch( integer const numComp, + integer const numPhase, + ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid ) + { + real64 maxDeltaPhaseVolFrac = 0.0; + if( numPhase == 2 ) + { + isothermalCompositionalMultiphaseBaseKernels:: + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseVolumeFractionKernel< NUM_COMP, 2 > kernel( subRegion, fluid ); + maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + else if( numPhase == 3 ) + { + isothermalCompositionalMultiphaseBaseKernels:: + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseVolumeFractionKernel< NUM_COMP, 3 > kernel( subRegion, fluid ); + maxDeltaPhaseVolFrac = PhaseVolumeFractionKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + return maxDeltaPhaseVolFrac; + } +}; + +} // namespace thermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALPHASEVOLUMEFRACTIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp new file mode 100644 index 00000000000..f0880d3acdd --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp @@ -0,0 +1,241 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalResidualNormKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALRESIDUALNORMKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALRESIDUALNORMKERNEL_HPP + +#include "physicsSolvers/SolverBaseKernels.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseBaseKernels +{ + +/******************************** ResidualNormKernel ********************************/ + +/** + * @class ResidualNormKernel + */ +class ResidualNormKernel : public solverBaseKernels::ResidualNormKernelBase< 2 > +{ +public: + + using Base = ResidualNormKernelBase< 2 >; + using Base::m_minNormalizer; + using Base::m_rankOffset; + using Base::m_localResidual; + using Base::m_dofNumber; + + ResidualNormKernel( globalIndex const rankOffset, + arrayView1d< real64 const > const & localResidual, + arrayView1d< globalIndex const > const & dofNumber, + arrayView1d< localIndex const > const & ghostRank, + integer const numComponents, + integer const numPhases, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + constitutive::SolidInternalEnergy const & solidInternalEnergy, + real64 const minNormalizer ) + : Base( rankOffset, + localResidual, + dofNumber, + ghostRank, + minNormalizer ), + m_numComponents( numComponents ), + m_numPhases( numPhases ), + m_volume( subRegion.getElementVolume() ), + m_porosity_n( solid.getPorosity_n() ), + m_phaseVolFrac_n( subRegion.getField< fields::flow::phaseVolumeFraction_n >() ), + m_totalDens_n( fluid.totalDensity_n() ), + m_phaseDens_n( fluid.phaseDensity_n() ), + m_phaseInternalEnergy_n( fluid.phaseInternalEnergy_n() ), + m_solidInternalEnergy_n( solidInternalEnergy.getInternalEnergy_n() ) + {} + + GEOS_HOST_DEVICE + void computeMassEnergyNormalizers( localIndex const ei, + real64 & massNormalizer, + real64 & energyNormalizer ) const + { + massNormalizer = LvArray::math::max( m_minNormalizer, m_totalDens_n[ei][0] * m_porosity_n[ei][0] * m_volume[ei] ); + real64 const poreVolume = m_porosity_n[ei][0] * m_volume[ei]; + energyNormalizer = m_solidInternalEnergy_n[ei][0] * ( 1.0 - m_porosity_n[ei][0] ) * m_volume[ei]; + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + energyNormalizer += m_phaseInternalEnergy_n[ei][0][ip] * m_phaseDens_n[ei][0][ip] * m_phaseVolFrac_n[ei][ip] * poreVolume; + } + // warning: internal energy can be negative + energyNormalizer = LvArray::math::max( m_minNormalizer, LvArray::math::abs( energyNormalizer ) ); + } + + GEOS_HOST_DEVICE + virtual void computeLinf( localIndex const ei, + LinfStackVariables & stack ) const override + { + real64 massNormalizer = 0.0, energyNormalizer = 0.0; + computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); + real64 const volumeNormalizer = LvArray::math::max( m_minNormalizer, m_porosity_n[ei][0] * m_volume[ei] ); + + // step 1: mass residual + + for( integer idof = 0; idof < m_numComponents; ++idof ) + { + real64 const valMass = LvArray::math::abs( m_localResidual[stack.localRow + idof] ) / massNormalizer; + if( valMass > stack.localValue[0] ) + { + stack.localValue[0] = valMass; + } + } + + // step 2: volume residual + + real64 const valVol = LvArray::math::abs( m_localResidual[stack.localRow + m_numComponents] ) / volumeNormalizer; + if( valVol > stack.localValue[0] ) + { + stack.localValue[0] = valVol; + } + + // step 3: energy residual + + real64 const valEnergy = LvArray::math::abs( m_localResidual[stack.localRow + m_numComponents + 1] ) / energyNormalizer; + if( valEnergy > stack.localValue[1] ) + { + stack.localValue[1] = valEnergy; + } + } + + GEOS_HOST_DEVICE + virtual void computeL2( localIndex const ei, + L2StackVariables & stack ) const override + { + // note: for the L2 norm, we bundle the volume and mass residuals/normalizers + real64 massNormalizer = 0.0, energyNormalizer = 0.0; + computeMassEnergyNormalizers( ei, massNormalizer, energyNormalizer ); + + // step 1: mass residual + + for( integer idof = 0; idof < m_numComponents; ++idof ) + { + stack.localValue[0] += m_localResidual[stack.localRow + idof] * m_localResidual[stack.localRow + idof]; + stack.localNormalizer[0] += massNormalizer; + } + + // step 2: volume residual + + real64 const valVol = m_localResidual[stack.localRow + m_numComponents] * m_totalDens_n[ei][0]; // we need a mass here, hence the + // multiplication + stack.localValue[0] += valVol * valVol; + stack.localNormalizer[0] += massNormalizer; + + // step 3: energy residual + + stack.localValue[1] += m_localResidual[stack.localRow + m_numComponents + 1] * m_localResidual[stack.localRow + m_numComponents + 1]; + stack.localNormalizer[1] += energyNormalizer; + } + +protected: + + /// Number of fluid components + integer const m_numComponents; + + /// Number of fluid phases + integer const m_numPhases; + + /// View on the volume + arrayView1d< real64 const > const m_volume; + + /// View on porosity at the previous converged time step + arrayView2d< real64 const > const m_porosity_n; + + /// View on phase properties at the previous converged time step + arrayView2d< real64 const, compflow::USD_PHASE > const m_phaseVolFrac_n; + arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const m_totalDens_n; + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseDens_n; + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseInternalEnergy_n; + + /// View on solid properties at the previous converged time step + arrayView2d< real64 const > const m_solidInternalEnergy_n; + +}; + +/** + * @class ResidualNormKernelFactory + */ +class ResidualNormKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] normType the type of norm used (Linf or L2) + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] localResidual the residual vector on my MPI rank + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[in] solidInternalEnergy the solid internal energy model + * @param[out] residualNorm the residual norm on the subRegion + * @param[out] residualNormalizer the residual normalizer on the subRegion + */ + template< typename POLICY > + static void + createAndLaunch( solverBaseKernels::NormType const normType, + integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + string const & dofKey, + arrayView1d< real64 const > const & localResidual, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + constitutive::SolidInternalEnergy const & solidInternalEnergy, + real64 const minNormalizer, + real64 (& residualNorm)[2], + real64 (& residualNormalizer)[2] ) + { + arrayView1d< globalIndex const > const dofNumber = subRegion.getReference< array1d< globalIndex > >( dofKey ); + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + ResidualNormKernel kernel( rankOffset, localResidual, dofNumber, ghostRank, + numComps, numPhases, subRegion, fluid, solid, solidInternalEnergy, minNormalizer ); + if( normType == solverBaseKernels::NormType::Linf ) + { + ResidualNormKernel::launchLinf< POLICY >( subRegion.size(), kernel, residualNorm ); + } + else // L2 norm + { + ResidualNormKernel::launchL2< POLICY >( subRegion.size(), kernel, residualNorm, residualNormalizer ); + } + + } +}; + + +} // namespace thermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALRESIDUALNORMKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp new file mode 100644 index 00000000000..6a15d3bbc19 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp @@ -0,0 +1,177 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalSolutionCheckKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONCHECKKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONCHECKKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseBaseKernels +{ + +/******************************** SolutionCheckKernel ********************************/ + +/** + * @class SolutionCheckKernel + * @brief Define the kernel for checking the updated solution + */ +class SolutionCheckKernel : public isothermalCompositionalMultiphaseBaseKernels::SolutionCheckKernel +{ +public: + + using Base = isothermalCompositionalMultiphaseBaseKernels::SolutionCheckKernel; + using Base::m_numComp; + using Base::m_localSolution; + using Base::m_scalingFactor; + + static real64 constexpr minTemperature = constants::zeroDegreesCelsiusInKelvin; + + /** + * @brief Create a new kernel instance + * @param[in] allowCompDensChopping flag to allow the component density chopping + * @param[in] scalingFactor the scaling factor + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @param[in] pressure the pressure vector + * @param[in] temperature the temperature vector + * @param[in] compDens the component density vector + */ + SolutionCheckKernel( integer const allowCompDensChopping, + integer const allowNegativePressure, + CompositionalMultiphaseFVM::ScalingType const scalingType, + real64 const scalingFactor, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView1d< real64 const > const temperature, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor, + arrayView1d< real64 > temperatureScalingFactor ) + : Base( allowCompDensChopping, + allowNegativePressure, + scalingType, + scalingFactor, + rankOffset, + numComp, + dofKey, + subRegion, + localSolution, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor ), + m_temperature( temperature ), + m_temperatureScalingFactor( temperatureScalingFactor ) + {} + + /** + * @brief Compute the local value of the solution check + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void computeSolutionCheck( localIndex const ei, + StackVariables & stack ) const + { + Base::computeSolutionCheck( ei, stack, [&] () + { + bool const localScaling = m_scalingType == CompositionalMultiphaseFVM::ScalingType::Local; + // compute the change in temperature + real64 const newTemp = m_temperature[ei] + (localScaling ? m_temperatureScalingFactor[ei] : m_scalingFactor * m_localSolution[stack.localRow + m_numComp + 1]); + if( newTemp < minTemperature ) + { + stack.localMinVal = 0; + } + } ); + } + +protected: + + /// View on the primary variables + arrayView1d< real64 const > const m_temperature; + + /// View on the scaling factor + arrayView1d< real64 const > const m_temperatureScalingFactor; + +}; + +/** + * @class SolutionCheckKernelFactory + */ +class SolutionCheckKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] maxRelativePresChange the max allowed relative pressure change + * @param[in] maxRelativeTempChange the max allowed relative temperature change + * @param[in] maxCompFracChange the max allowed comp fraction change + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + */ + template< typename POLICY > + static SolutionCheckKernel::StackVariables + createAndLaunch( integer const allowCompDensChopping, + integer const allowNegativePressure, + CompositionalMultiphaseFVM::ScalingType const scalingType, + real64 const scalingFactor, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase & subRegion, + arrayView1d< real64 const > const localSolution ) + { + arrayView1d< real64 const > const pressure = + subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const temperature = + subRegion.getField< fields::flow::temperature >(); + arrayView2d< real64 const, compflow::USD_COMP > const compDens = + subRegion.getField< fields::flow::globalCompDensity >(); + arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); + arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); + arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); + SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor, + rankOffset, numComp, dofKey, subRegion, localSolution, + pressure, temperature, compDens, pressureScalingFactor, temperatureScalingFactor, compDensScalingFactor ); + return SolutionCheckKernel::launch< POLICY >( subRegion.size(), kernel ); + } + +}; + +} // namespace thermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONCHECKKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp new file mode 100644 index 00000000000..67e45cfc792 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp @@ -0,0 +1,221 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalSolutionScalingKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONSCALINGKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONSCALINGKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseBaseKernels +{ + +/******************************** SolutionScalingKernel ********************************/ + +/** + * @class SolutionScalingKernel + * @brief Define the kernel for scaling the Newton update + */ +class SolutionScalingKernel : public isothermalCompositionalMultiphaseBaseKernels::SolutionScalingKernel +{ +public: + + using Base = isothermalCompositionalMultiphaseBaseKernels::SolutionScalingKernel; + using Base::m_numComp; + using Base::m_localSolution; + + /** + * @brief Create a new kernel instance + * @param[in] maxRelativePresChange the max allowed relative pressure change + * @param[in] maxAbsolutePresChange the max allowed absolute pressure change + * @param[in] maxRelativeTempChange the max allowed relative temperature change + * @param[in] maxCompFracChange the max allowed comp fraction change + * @param[in] maxRelativeCompDensChange the max allowed comp density change + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @param[in] pressure the pressure vector + * @param[in] temperature the temperature vector + * @param[in] compDens the component density vector + * @param[in] pressureScalingFactor the pressure local scaling factor + * @param[in] compDensScalingFactor the component density local scaling factor + * @param[in] temperatureFactor the temperature local scaling factor + */ + SolutionScalingKernel( real64 const maxRelativePresChange, + real64 const maxAbsolutePresChange, + real64 const maxRelativeTempChange, + real64 const maxCompFracChange, + real64 const maxRelativeCompDensChange, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView1d< real64 const > const temperature, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor, + arrayView1d< real64 > temperatureScalingFactor ) + : Base( maxRelativePresChange, + maxAbsolutePresChange, + maxCompFracChange, + maxRelativeCompDensChange, + rankOffset, + numComp, + dofKey, + subRegion, + localSolution, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor ), + m_maxRelativeTempChange( maxRelativeTempChange ), + m_temperature( temperature ), + m_temperatureScalingFactor( temperatureScalingFactor ) + {} + + /** + * @brief Compute the local value + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void compute( localIndex const ei, + StackVariables & stack ) const + { + computeScalingFactor( ei, stack ); + } + + /** + * @brief Compute the local value of the scaling factor + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void computeScalingFactor( localIndex const ei, + StackVariables & stack ) const + { + real64 constexpr eps = isothermalCompositionalMultiphaseBaseKernels::minDensForDivision; + Base::computeScalingFactor( ei, stack, [&] () + { + // compute the change in temperature + real64 const temp = m_temperature[ei]; + real64 const absTempChange = LvArray::math::abs( m_localSolution[stack.localRow + m_numComp + 1] ); + if( stack.localMaxDeltaTemp < absTempChange ) + { + stack.localMaxDeltaTemp = absTempChange; + } + + m_temperatureScalingFactor[ei] = 1.0; + + if( temp > eps ) + { + real64 const relativeTempChange = absTempChange / temp; + if( relativeTempChange > m_maxRelativeTempChange ) + { + real64 const tempScalingFactor = m_maxRelativeTempChange / relativeTempChange; + m_temperatureScalingFactor[ei] = tempScalingFactor; + if( stack.localMinVal > tempScalingFactor ) + { + stack.localMinVal = tempScalingFactor; + } + if( stack.localMinTempScalingFactor > tempScalingFactor ) + { + stack.localMinTempScalingFactor = tempScalingFactor; + } + } + } + } ); + } + +protected: + + /// Max allowed changes in primary variables + real64 const m_maxRelativeTempChange; + + /// View on the primary variables + arrayView1d< real64 const > const m_temperature; + + /// View on the scaling factor + arrayView1d< real64 > const m_temperatureScalingFactor; + +}; + +/** + * @class SolutionScalingKernelFactory + */ +class SolutionScalingKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] maxRelativePresChange the max allowed relative pressure change + * @param[in] maxAbsolutePresChange the max allowed absolute pressure change + * @param[in] maxRelativeTempChange the max allowed relative temperature change + * @param[in] maxCompFracChange the max allowed comp fraction change + * @param[in] maxRelativeCompdensChange the max allowed relative component density change + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + */ + template< typename POLICY > + static SolutionScalingKernel::StackVariables + createAndLaunch( real64 const maxRelativePresChange, + real64 const maxAbsolutePresChange, + real64 const maxRelativeTempChange, + real64 const maxCompFracChange, + real64 const maxRelativeCompDensChange, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase & subRegion, + arrayView1d< real64 const > const localSolution ) + { + arrayView1d< real64 const > const pressure = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const temperature = subRegion.getField< fields::flow::temperature >(); + arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getField< fields::flow::globalCompDensity >(); + arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); + arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); + arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); + SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxRelativeTempChange, + maxCompFracChange, maxRelativeCompDensChange, + rankOffset, numComp, dofKey, subRegion, localSolution, + pressure, temperature, compDens, pressureScalingFactor, + temperatureScalingFactor, compDensScalingFactor ); + return thermalCompositionalMultiphaseBaseKernels:: + SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel ); + } + +}; + +} // namespace thermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONSCALINGKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp index 0bb47d1b154..51d2db744a4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/CompositionalMultiphaseWell.cpp @@ -39,8 +39,11 @@ #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" From ee4403318d4d5c4d8c1aa52a6966f06e38a65353 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Sat, 28 Sep 2024 15:54:02 -0500 Subject: [PATCH 23/47] flux helpers --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 6 +- .../kernels/compositional/C1PPUPhaseFlux.hpp | 225 ++++++++ ...VMKernelUtilities.hpp => IHUPhaseFlux.hpp} | 546 +----------------- ...ermalCompositionalMultiphaseFVMKernels.hpp | 5 +- .../kernels/compositional/PPUPhaseFlux.hpp | 161 ++++++ .../compositional/PhaseComponentFlux.hpp | 128 ++++ .../kernels/compositional/PotGrad.hpp | 187 ++++++ 7 files changed, 712 insertions(+), 546 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/{IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp => IHUPhaseFlux.hpp} (82%) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseComponentFlux.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 39fe55ba857..98cf023f51d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -45,9 +45,11 @@ set( physicsSolvers_headers fluidFlow/kernels/singlePhase/proppant/ProppantBaseKernels.hpp fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.hpp fluidFlow/kernels/compositional/AccumulationKernel.hpp - fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseBaseKernels.hpp + fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp + fluidFlow/kernels/compositional/PPUPhaseFlux.hpp + fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp + fluidFlow/kernels/compositional/IHUPhaseFlux.hpp fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp new file mode 100644 index 00000000000..2ff1a7b6a37 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp @@ -0,0 +1,225 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 C1PPUPhaseFlux.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_C1PPUPHASEFLUX_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_C1PPUPHASEFLUX_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "constitutive/fluid/multifluid/Layouts.hpp" +#include "constitutive/capillaryPressure/layouts.hpp" +#include "mesh/ElementRegionManager.hpp" + + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernelUtilities +{ + +// TODO make input parameter +static constexpr real64 epsC1PPU = 5000; + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +using Deriv = constitutive::multifluid::DerivativeOffset; + +struct C1PPUPhaseFlux +{ + /** + * @brief Form the PhasePotentialUpwind from pressure gradient and gravitational head + * @tparam numComp number of components + * @tparam numFluxSupportPoints number of flux support points + * @param numPhase number of phases + * @param ip phase index + * @param hasCapPressure flag indicating if there is capillary pressure + * @param seri arraySlice of the stencil-implied element region index + * @param sesri arraySlice of the stencil-implied element subregion index + * @param sei arraySlice of the stencil-implied element index + * @param trans transmissibility at the connection + * @param dTrans_dPres derivative of transmissibility wrt pressure + * @param pres pressure + * @param gravCoef gravitational coefficient + * @param phaseMob phase mobility + * @param dPhaseMob derivative of phase mobility wrt pressure, temperature, comp density + * @param dPhaseVolFrac derivative of phase volume fraction wrt pressure, temperature, comp density + * @param dCompFrac_dCompDens derivative of component fraction wrt component density + * @param phaseMassDens phase mass density + * @param dPhaseMassDens derivative of phase mass density wrt pressure, temperature, comp fraction + * @param phaseCapPressure phase capillary pressure + * @param dPhaseCapPressure_dPhaseVolFrac derivative of phase capillary pressure wrt phase volume fraction + * @param k_up uptream index for this phase + * @param potGrad potential gradient for this phase + * @param phaseFlux phase flux + * @param dPhaseFlux_dP derivative of phase flux wrt pressure + * @param dPhaseFlux_dC derivative of phase flux wrt comp density + */ + template< integer numComp, integer numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + compute( integer const numPhase, + integer const ip, + integer const hasCapPressure, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + real64 const ( &trans )[2], + real64 const ( &dTrans_dPres )[2], + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseMob, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseMob, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, + ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, + ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, + localIndex & k_up, + real64 & potGrad, + real64 ( &phaseFlux ), + real64 ( & dPhaseFlux_dP )[numFluxSupportPoints], + real64 ( & dPhaseFlux_dC )[numFluxSupportPoints][numComp], + real64 ( & compFlux )[numComp], + real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], + real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) + { + real64 dPresGrad_dP[numFluxSupportPoints]{}; + real64 dPresGrad_dC[numFluxSupportPoints][numComp]{}; + real64 dGravHead_dP[numFluxSupportPoints]{}; + real64 dGravHead_dC[numFluxSupportPoints][numComp]{}; + PotGrad::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, seri, sesri, sei, trans, dTrans_dPres, pres, + gravCoef, dPhaseVolFrac, dCompFrac_dCompDens, phaseMassDens, dPhaseMassDens, + phaseCapPressure, dPhaseCapPressure_dPhaseVolFrac, potGrad, dPresGrad_dP, + dPresGrad_dC, dGravHead_dP, dGravHead_dC ); + + // gravity head + real64 gravHead = 0.0; + for( integer i = 0; i < numFluxSupportPoints; i++ ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + real64 const gravD = trans[i] * gravCoef[er][esr][ei]; + + gravHead += gravD; + } + + // *** upwinding *** + + // phase flux and derivatives + + // assuming TPFA in the code below + + real64 Ttrans = fabs( trans[0] ); + potGrad = potGrad / Ttrans; + + real64 const mobility_i = phaseMob[seri[0]][sesri[0]][sei[0]][ip]; + real64 const mobility_j = phaseMob[seri[1]][sesri[1]][sei[1]][ip]; + + // compute phase flux, see Eqs. (66) and (69) from the reference above + real64 smoEps = epsC1PPU; + if( fabs( gravHead ) <= 1e-20 ) + smoEps = 1000; + real64 const tmpSqrt = sqrt( potGrad * potGrad + smoEps * smoEps ); + real64 const smoMax = 0.5 * (-potGrad + tmpSqrt); + + phaseFlux = Ttrans * ( potGrad * mobility_i - smoMax * (mobility_j - mobility_i) ); + + // derivativess + + // first part, mobility derivative + + // dP + { + real64 const dMob_dP = dPhaseMob[seri[0]][sesri[0]][sei[0]][ip][Deriv::dP]; + dPhaseFlux_dP[0] += Ttrans * potGrad * dMob_dP; + } + + // dC + { + arraySlice1d< real64 const, compflow::USD_PHASE_DC - 2 > + dPhaseMobSub = dPhaseMob[seri[0]][sesri[0]][sei[0]][ip]; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[0][jc] += Ttrans * potGrad * dPhaseMobSub[Deriv::dC + jc]; + } + } + + real64 const tmpInv = 1.0 / tmpSqrt; + real64 const dSmoMax_x = 0.5 * (1.0 - potGrad * tmpInv); + + // pressure gradient and mobility difference depend on all points in the stencil + real64 const dMobDiff_sign[numFluxSupportPoints] = {-1.0, 1.0}; + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + // dP + + real64 const dPotGrad_dP = dPresGrad_dP[ke] - dGravHead_dP[ke]; + + // first part + dPhaseFlux_dP[ke] += dPotGrad_dP * mobility_i; + + // second part + real64 const dSmoMax_dP = -dPotGrad_dP * dSmoMax_x; + dPhaseFlux_dP[ke] += -dSmoMax_dP * (mobility_j - mobility_i); + + real64 const dMob_dP = dPhaseMob[seri[ke]][sesri[ke]][sei[ke]][ip][Deriv::dP]; + dPhaseFlux_dP[ke] += -Ttrans * smoMax * dMobDiff_sign[ke] * dMob_dP; + + // dC + + arraySlice1d< real64 const, compflow::USD_PHASE_DC - 2 > + dPhaseMobSub = dPhaseMob[seri[ke]][sesri[ke]][sei[ke]][ip]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + real64 const dPotGrad_dC = dPresGrad_dC[ke][jc] - dGravHead_dC[ke][jc]; + + // first part + dPhaseFlux_dC[ke][jc] += dPotGrad_dC * mobility_i; + + // second part + real64 const dSmoMax_dC = -dPotGrad_dC * dSmoMax_x; + dPhaseFlux_dC[ke][jc] += -dSmoMax_dC * (mobility_j - mobility_i); + dPhaseFlux_dC[ke][jc] += -Ttrans * smoMax * dMobDiff_sign[ke] * dPhaseMobSub[Deriv::dC + jc]; + } + } + + potGrad = potGrad * Ttrans; + + // choose upstream cell for composition upwinding + k_up = (phaseFlux >= 0) ? 0 : 1; + + //distribute on phaseComponentFlux here + PhaseComponentFlux::compute( ip, k_up, seri, sesri, sei, phaseCompFrac, dPhaseCompFrac, dCompFrac_dCompDens, phaseFlux + , dPhaseFlux_dP, dPhaseFlux_dC, compFlux, dCompFlux_dP, dCompFlux_dC ); + } +}; + +} // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities + +} // namespace geos + + +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_C1PPUPHASEFLUX_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp similarity index 82% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp index 7284f48d985..954b6b2e1f8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp @@ -14,11 +14,11 @@ */ /** - * @file IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp + * @file IHUPhaseFlux.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELUTILITIES_HPP_ -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELUTILITIES_HPP_ +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_IHUPHASEFLUX_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_IHUPHASEFLUX_HPP #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" @@ -33,536 +33,11 @@ namespace geos namespace isothermalCompositionalMultiphaseFVMKernelUtilities { -// TODO make input parameter -static constexpr real64 epsC1PPU = 5000; - template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; using Deriv = constitutive::multifluid::DerivativeOffset; -struct PotGrad -{ - template< integer numComp, integer numFluxSupportPoints > - GEOS_HOST_DEVICE - static void - compute ( integer const numPhase, - integer const ip, - integer const hasCapPressure, - localIndex const ( &seri )[numFluxSupportPoints], - localIndex const ( &sesri )[numFluxSupportPoints], - localIndex const ( &sei )[numFluxSupportPoints], - real64 const ( &trans )[numFluxSupportPoints], - real64 const ( &dTrans_dPres )[numFluxSupportPoints], - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, - ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, - ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, - real64 & potGrad, - real64 ( & dPresGrad_dP )[numFluxSupportPoints], - real64 ( & dPresGrad_dC )[numFluxSupportPoints][numComp], - real64 ( & dGravHead_dP )[numFluxSupportPoints], - real64 ( & dGravHead_dC )[numFluxSupportPoints][numComp] ) - { - // assign derivatives arrays to zero - for( integer i = 0; i < numFluxSupportPoints; ++i ) - { - dPresGrad_dP[i] = 0.0; - dGravHead_dP[i] = 0.0; - for( integer jc = 0; jc < numComp; ++jc ) - { - dPresGrad_dC[i][jc] = 0.0; - dGravHead_dC[i][jc] = 0.0; - } - } - - // create local work arrays - real64 densMean = 0.0; - real64 dDensMean_dP[numFluxSupportPoints]{}; - real64 dDensMean_dC[numFluxSupportPoints][numComp]{}; - - real64 presGrad = 0.0; - real64 gravHead = 0.0; - real64 dCapPressure_dC[numComp]{}; - - real64 dProp_dC[numComp]{}; - - // calculate quantities on primary connected cells - for( integer i = 0; i < numFluxSupportPoints; ++i ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - // density - real64 const density = phaseMassDens[er][esr][ei][0][ip]; - real64 const dDens_dP = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; - - applyChainRule( numComp, - dCompFrac_dCompDens[er][esr][ei], - dPhaseMassDens[er][esr][ei][0][ip], - dProp_dC, - Deriv::dC ); - - // average density and derivatives - densMean += 0.5 * density; - dDensMean_dP[i] = 0.5 * dDens_dP; - for( integer jc = 0; jc < numComp; ++jc ) - { - dDensMean_dC[i][jc] = 0.5 * dProp_dC[jc]; - } - } - - /// compute the TPFA potential difference - for( integer i = 0; i < numFluxSupportPoints; i++ ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - // capillary pressure - real64 capPressure = 0.0; - real64 dCapPressure_dP = 0.0; - - for( integer ic = 0; ic < numComp; ++ic ) - { - dCapPressure_dC[ic] = 0.0; - } - - if( hasCapPressure ) - { - capPressure = phaseCapPressure[er][esr][ei][0][ip]; - - for( integer jp = 0; jp < numPhase; ++jp ) - { - real64 const dCapPressure_dS = dPhaseCapPressure_dPhaseVolFrac[er][esr][ei][0][ip][jp]; - dCapPressure_dP += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dP]; - - for( integer jc = 0; jc < numComp; ++jc ) - { - dCapPressure_dC[jc] += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dC+jc]; - } - } - } - - presGrad += trans[i] * (pres[er][esr][ei] - capPressure); - dPresGrad_dP[i] += trans[i] * (1 - dCapPressure_dP) - + dTrans_dPres[i] * (pres[er][esr][ei] - capPressure); - for( integer jc = 0; jc < numComp; ++jc ) - { - dPresGrad_dC[i][jc] += -trans[i] * dCapPressure_dC[jc]; - } - - real64 const gravD = trans[i] * gravCoef[er][esr][ei]; - real64 const dGravD_dP = dTrans_dPres[i] * gravCoef[er][esr][ei]; - - // the density used in the potential difference is always a mass density - // unlike the density used in the phase mobility, which is a mass density - // if useMass == 1 and a molar density otherwise - gravHead += densMean * gravD; - - // need to add contributions from both cells the mean density depends on - for( integer j = 0; j < numFluxSupportPoints; ++j ) - { - dGravHead_dP[j] += dDensMean_dP[j] * gravD + dGravD_dP * densMean; - for( integer jc = 0; jc < numComp; ++jc ) - { - dGravHead_dC[j][jc] += dDensMean_dC[j][jc] * gravD; - } - } - } - - // compute phase potential gradient - potGrad = presGrad - gravHead; - - } - -}; - -struct PhaseComponentFlux -{ - /** - * @brief Compute the component flux for a given phase - * @tparam numComp number of components - * @tparam numFluxSupportPoints number of flux support points - * @param ip phase index - * @param k_up uptream index for this phase - * @param seri arraySlice of the stencil-implied element region index - * @param sesri arraySlice of the stencil-implied element subregion index - * @param sei arraySlice of the stencil-implied element index - * @param phaseCompFrac phase component fraction - * @param dPhaseCompFrac derivative of phase component fraction wrt pressure, temperature, component fraction - * @param dCompFrac_dCompDens derivative of component fraction wrt component density - * @param phaseFlux phase flux - * @param dPhaseFlux_dP derivative of phase flux wrt pressure - * @param dPhaseFlux_dC derivative of phase flux wrt comp density - * @param compFlux component flux - * @param dCompFlux_dP derivative of phase flux wrt pressure - * @param dCompFlux_dC derivative of phase flux wrt comp density - */ - template< localIndex numComp, localIndex numFluxSupportPoints > - GEOS_HOST_DEVICE - static void - compute( localIndex const ip, - localIndex const k_up, - localIndex const ( &seri )[numFluxSupportPoints], - localIndex const ( &sesri )[numFluxSupportPoints], - localIndex const ( &sei )[numFluxSupportPoints], - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, - ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, - real64 const & phaseFlux, - real64 const ( &dPhaseFlux_dP )[numFluxSupportPoints], - real64 const ( &dPhaseFlux_dC )[numFluxSupportPoints][numComp], - real64 ( & compFlux )[numComp], - real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], - real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) - { - localIndex const er_up = seri[k_up]; - localIndex const esr_up = sesri[k_up]; - localIndex const ei_up = sei[k_up]; - - real64 dProp_dC[numComp]{}; - - // slice some constitutive arrays to avoid too much indexing in component loop - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub = - phaseCompFrac[er_up][esr_up][ei_up][0][ip]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub = - dPhaseCompFrac[er_up][esr_up][ei_up][0][ip]; - - // compute component fluxes and derivatives using upstream cell composition - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const ycp = phaseCompFracSub[ic]; - compFlux[ic] += phaseFlux * ycp; - - // derivatives stemming from phase flux - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dCompFlux_dP[ke][ic] += dPhaseFlux_dP[ke] * ycp; - for( integer jc = 0; jc < numComp; ++jc ) - { - dCompFlux_dC[ke][ic][jc] += dPhaseFlux_dC[ke][jc] * ycp; - } - } - - // additional derivatives stemming from upstream cell phase composition - dCompFlux_dP[k_up][ic] += phaseFlux * dPhaseCompFracSub[ic][Deriv::dP]; - - // convert derivatives of comp fraction w.r.t. comp fractions to derivatives w.r.t. comp densities - applyChainRule( numComp, - dCompFrac_dCompDens[er_up][esr_up][ei_up], - dPhaseCompFracSub[ic], - dProp_dC, - Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - dCompFlux_dC[k_up][ic][jc] += phaseFlux * dProp_dC[jc]; - } - } - - - - } - -}; - -struct PPUPhaseFlux -{ - /** - * @brief Form the PhasePotentialUpwind from pressure gradient and gravitational head - * @tparam numComp number of components - * @tparam numFluxSupportPoints number of flux support points - * @param numPhase number of phases - * @param ip phase index - * @param hasCapPressure flag indicating if there is capillary pressure - * @param seri arraySlice of the stencil-implied element region index - * @param sesri arraySlice of the stencil-implied element subregion index - * @param sei arraySlice of the stencil-implied element index - * @param trans transmissibility at the connection - * @param dTrans_dPres derivative of transmissibility wrt pressure - * @param pres pressure - * @param gravCoef gravitational coefficient - * @param phaseMob phase mobility - * @param dPhaseMob derivative of phase mobility wrt pressure, temperature, comp density - * @param dPhaseVolFrac derivative of phase volume fraction wrt pressure, temperature, comp density - * @param dCompFrac_dCompDens derivative of component fraction wrt component density - * @param phaseMassDens phase mass density - * @param dPhaseMassDens derivative of phase mass density wrt pressure, temperature, comp fraction - * @param phaseCapPressure phase capillary pressure - * @param dPhaseCapPressure_dPhaseVolFrac derivative of phase capillary pressure wrt phase volume fraction - * @param k_up uptream index for this phase - * @param potGrad potential gradient for this phase - * @param phaseFlux phase flux - * @param dPhaseFlux_dP derivative of phase flux wrt pressure - * @param dPhaseFlux_dC derivative of phase flux wrt comp density - */ - template< integer numComp, integer numFluxSupportPoints > - GEOS_HOST_DEVICE - static void - compute( integer const numPhase, - integer const ip, - integer const hasCapPressure, - localIndex const ( &seri )[numFluxSupportPoints], - localIndex const ( &sesri )[numFluxSupportPoints], - localIndex const ( &sei )[numFluxSupportPoints], - real64 const ( &trans )[2], - real64 const ( &dTrans_dPres )[2], - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseMob, - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseMob, - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, - ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, - ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, - ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, - localIndex & k_up, - real64 & potGrad, - real64 ( &phaseFlux ), - real64 ( & dPhaseFlux_dP )[numFluxSupportPoints], - real64 ( & dPhaseFlux_dC )[numFluxSupportPoints][numComp], - real64 ( & compFlux )[numComp], - real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], - real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) - { - real64 dPresGrad_dP[numFluxSupportPoints]{}; - real64 dPresGrad_dC[numFluxSupportPoints][numComp]{}; - real64 dGravHead_dP[numFluxSupportPoints]{}; - real64 dGravHead_dC[numFluxSupportPoints][numComp]{}; - PotGrad::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, seri, sesri, sei, trans, dTrans_dPres, pres, - gravCoef, dPhaseVolFrac, dCompFrac_dCompDens, phaseMassDens, dPhaseMassDens, - phaseCapPressure, dPhaseCapPressure_dPhaseVolFrac, potGrad, dPresGrad_dP, - dPresGrad_dC, dGravHead_dP, dGravHead_dC ); - - // *** upwinding *** - - // choose upstream cell - k_up = (potGrad >= 0) ? 0 : 1; - - localIndex const er_up = seri[k_up]; - localIndex const esr_up = sesri[k_up]; - localIndex const ei_up = sei[k_up]; - - real64 const mobility = phaseMob[er_up][esr_up][ei_up][ip]; - - // pressure gradient depends on all points in the stencil - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dPhaseFlux_dP[ke] += dPresGrad_dP[ke] - dGravHead_dP[ke]; - dPhaseFlux_dP[ke] *= mobility; - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseFlux_dC[ke][jc] += dPresGrad_dC[ke][jc] - dGravHead_dC[ke][jc]; - dPhaseFlux_dC[ke][jc] *= mobility; - } - } - // compute phase flux using upwind mobility. - phaseFlux = mobility * potGrad; - - real64 const dMob_dP = dPhaseMob[er_up][esr_up][ei_up][ip][Deriv::dP]; - arraySlice1d< real64 const, compflow::USD_PHASE_DC - 2 > dPhaseMobSub = - dPhaseMob[er_up][esr_up][ei_up][ip]; - - // add contribution from upstream cell mobility derivatives - dPhaseFlux_dP[k_up] += dMob_dP * potGrad; - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseFlux_dC[k_up][jc] += dPhaseMobSub[Deriv::dC+jc] * potGrad; - } - - //distribute on phaseComponentFlux here - PhaseComponentFlux::compute( ip, k_up, seri, sesri, sei, phaseCompFrac, dPhaseCompFrac, dCompFrac_dCompDens, phaseFlux - , dPhaseFlux_dP, dPhaseFlux_dC, compFlux, dCompFlux_dP, dCompFlux_dC ); - - } -}; - -struct C1PPUPhaseFlux -{ - /** - * @brief Form the PhasePotentialUpwind from pressure gradient and gravitational head - * @tparam numComp number of components - * @tparam numFluxSupportPoints number of flux support points - * @param numPhase number of phases - * @param ip phase index - * @param hasCapPressure flag indicating if there is capillary pressure - * @param seri arraySlice of the stencil-implied element region index - * @param sesri arraySlice of the stencil-implied element subregion index - * @param sei arraySlice of the stencil-implied element index - * @param trans transmissibility at the connection - * @param dTrans_dPres derivative of transmissibility wrt pressure - * @param pres pressure - * @param gravCoef gravitational coefficient - * @param phaseMob phase mobility - * @param dPhaseMob derivative of phase mobility wrt pressure, temperature, comp density - * @param dPhaseVolFrac derivative of phase volume fraction wrt pressure, temperature, comp density - * @param dCompFrac_dCompDens derivative of component fraction wrt component density - * @param phaseMassDens phase mass density - * @param dPhaseMassDens derivative of phase mass density wrt pressure, temperature, comp fraction - * @param phaseCapPressure phase capillary pressure - * @param dPhaseCapPressure_dPhaseVolFrac derivative of phase capillary pressure wrt phase volume fraction - * @param k_up uptream index for this phase - * @param potGrad potential gradient for this phase - * @param phaseFlux phase flux - * @param dPhaseFlux_dP derivative of phase flux wrt pressure - * @param dPhaseFlux_dC derivative of phase flux wrt comp density - */ - template< integer numComp, integer numFluxSupportPoints > - GEOS_HOST_DEVICE - static void - compute( integer const numPhase, - integer const ip, - integer const hasCapPressure, - localIndex const ( &seri )[numFluxSupportPoints], - localIndex const ( &sesri )[numFluxSupportPoints], - localIndex const ( &sei )[numFluxSupportPoints], - real64 const ( &trans )[2], - real64 const ( &dTrans_dPres )[2], - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseMob, - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseMob, - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, - ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, - ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, - ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, - localIndex & k_up, - real64 & potGrad, - real64 ( &phaseFlux ), - real64 ( & dPhaseFlux_dP )[numFluxSupportPoints], - real64 ( & dPhaseFlux_dC )[numFluxSupportPoints][numComp], - real64 ( & compFlux )[numComp], - real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], - real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) - { - real64 dPresGrad_dP[numFluxSupportPoints]{}; - real64 dPresGrad_dC[numFluxSupportPoints][numComp]{}; - real64 dGravHead_dP[numFluxSupportPoints]{}; - real64 dGravHead_dC[numFluxSupportPoints][numComp]{}; - PotGrad::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, seri, sesri, sei, trans, dTrans_dPres, pres, - gravCoef, dPhaseVolFrac, dCompFrac_dCompDens, phaseMassDens, dPhaseMassDens, - phaseCapPressure, dPhaseCapPressure_dPhaseVolFrac, potGrad, dPresGrad_dP, - dPresGrad_dC, dGravHead_dP, dGravHead_dC ); - - // gravity head - real64 gravHead = 0.0; - for( integer i = 0; i < numFluxSupportPoints; i++ ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - real64 const gravD = trans[i] * gravCoef[er][esr][ei]; - - gravHead += gravD; - } - - // *** upwinding *** - - // phase flux and derivatives - - // assuming TPFA in the code below - - real64 Ttrans = fabs( trans[0] ); - potGrad = potGrad / Ttrans; - - real64 const mobility_i = phaseMob[seri[0]][sesri[0]][sei[0]][ip]; - real64 const mobility_j = phaseMob[seri[1]][sesri[1]][sei[1]][ip]; - - // compute phase flux, see Eqs. (66) and (69) from the reference above - real64 smoEps = epsC1PPU; - if( fabs( gravHead ) <= 1e-20 ) - smoEps = 1000; - real64 const tmpSqrt = sqrt( potGrad * potGrad + smoEps * smoEps ); - real64 const smoMax = 0.5 * (-potGrad + tmpSqrt); - - phaseFlux = Ttrans * ( potGrad * mobility_i - smoMax * (mobility_j - mobility_i) ); - - // derivativess - - // first part, mobility derivative - - // dP - { - real64 const dMob_dP = dPhaseMob[seri[0]][sesri[0]][sei[0]][ip][Deriv::dP]; - dPhaseFlux_dP[0] += Ttrans * potGrad * dMob_dP; - } - - // dC - { - arraySlice1d< real64 const, compflow::USD_PHASE_DC - 2 > - dPhaseMobSub = dPhaseMob[seri[0]][sesri[0]][sei[0]][ip]; - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseFlux_dC[0][jc] += Ttrans * potGrad * dPhaseMobSub[Deriv::dC + jc]; - } - } - - real64 const tmpInv = 1.0 / tmpSqrt; - real64 const dSmoMax_x = 0.5 * (1.0 - potGrad * tmpInv); - - // pressure gradient and mobility difference depend on all points in the stencil - real64 const dMobDiff_sign[numFluxSupportPoints] = {-1.0, 1.0}; - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - // dP - - real64 const dPotGrad_dP = dPresGrad_dP[ke] - dGravHead_dP[ke]; - - // first part - dPhaseFlux_dP[ke] += dPotGrad_dP * mobility_i; - - // second part - real64 const dSmoMax_dP = -dPotGrad_dP * dSmoMax_x; - dPhaseFlux_dP[ke] += -dSmoMax_dP * (mobility_j - mobility_i); - - real64 const dMob_dP = dPhaseMob[seri[ke]][sesri[ke]][sei[ke]][ip][Deriv::dP]; - dPhaseFlux_dP[ke] += -Ttrans * smoMax * dMobDiff_sign[ke] * dMob_dP; - - // dC - - arraySlice1d< real64 const, compflow::USD_PHASE_DC - 2 > - dPhaseMobSub = dPhaseMob[seri[ke]][sesri[ke]][sei[ke]][ip]; - - for( integer jc = 0; jc < numComp; ++jc ) - { - real64 const dPotGrad_dC = dPresGrad_dC[ke][jc] - dGravHead_dC[ke][jc]; - - // first part - dPhaseFlux_dC[ke][jc] += dPotGrad_dC * mobility_i; - - // second part - real64 const dSmoMax_dC = -dPotGrad_dC * dSmoMax_x; - dPhaseFlux_dC[ke][jc] += -dSmoMax_dC * (mobility_j - mobility_i); - dPhaseFlux_dC[ke][jc] += -Ttrans * smoMax * dMobDiff_sign[ke] * dPhaseMobSub[Deriv::dC + jc]; - } - } - - potGrad = potGrad * Ttrans; - - // choose upstream cell for composition upwinding - k_up = (phaseFlux >= 0) ? 0 : 1; - - //distribute on phaseComponentFlux here - PhaseComponentFlux::compute( ip, k_up, seri, sesri, sei, phaseCompFrac, dPhaseCompFrac, dCompFrac_dCompDens, phaseFlux - , dPhaseFlux_dP, dPhaseFlux_dC, compFlux, dCompFlux_dP, dCompFlux_dC ); - } -}; - - - /************************* HELPERS ******************/ namespace UpwindHelpers { @@ -1013,7 +488,6 @@ computeFractionalFlowGravity( localIndex const numPhase, } } - template< localIndex numComp, localIndex numFluxSupportPoints, class UPWIND > GEOS_HOST_DEVICE static void @@ -1064,7 +538,6 @@ computeFractionalFlowCapillary( localIndex const numPhase, } } - localIndex k_up; real64 mob{}; real64 dMob_dP{}; @@ -1094,7 +567,6 @@ computeFractionalFlowCapillary( localIndex const numPhase, dMob_dP, dMob_dC ); - k_up_main = k_up; mainMob = mob; dMMob_dP = dMob_dP; @@ -1327,15 +799,11 @@ struct computePotentialCapillary dPot_dComp[i][jc] += transmissibility[i] * dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dC + jc]; } - } - } - } }; - /// Form potential-related parts of fluxes template< localIndex numComp, localIndex numFluxSupportPoints, class UPWIND > @@ -1712,10 +1180,8 @@ static void computePotentialFluxesCapillary( localIndex const numPhase, } } } - } - }//end of struct UpwindHelpers /************************* UPWIND ******************/ @@ -2262,8 +1728,6 @@ struct IHUPhaseFlux dPhaseFlux_dC[ke][jc] = 0.; } } - - } //fractional flow loop with IHU @@ -2477,11 +1941,9 @@ struct IHUPhaseFlux }; - - } // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities } // namespace geos -#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELUTILITIES_HPP_ +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_IHUPHASEFLUX_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp index 31f39d1e7fb..d16e8ebb775 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp @@ -48,9 +48,10 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -//#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernelUtilities.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp new file mode 100644 index 00000000000..dc24f157f53 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp @@ -0,0 +1,161 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PPUPhaseFlux.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PPUPHASEFLUX_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PPUPHASEFLUX_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "constitutive/fluid/multifluid/Layouts.hpp" +#include "constitutive/capillaryPressure/layouts.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseComponentFlux.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernelUtilities +{ + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +using Deriv = constitutive::multifluid::DerivativeOffset; + +struct PPUPhaseFlux +{ + /** + * @brief Form the PhasePotentialUpwind from pressure gradient and gravitational head + * @tparam numComp number of components + * @tparam numFluxSupportPoints number of flux support points + * @param numPhase number of phases + * @param ip phase index + * @param hasCapPressure flag indicating if there is capillary pressure + * @param seri arraySlice of the stencil-implied element region index + * @param sesri arraySlice of the stencil-implied element subregion index + * @param sei arraySlice of the stencil-implied element index + * @param trans transmissibility at the connection + * @param dTrans_dPres derivative of transmissibility wrt pressure + * @param pres pressure + * @param gravCoef gravitational coefficient + * @param phaseMob phase mobility + * @param dPhaseMob derivative of phase mobility wrt pressure, temperature, comp density + * @param dPhaseVolFrac derivative of phase volume fraction wrt pressure, temperature, comp density + * @param dCompFrac_dCompDens derivative of component fraction wrt component density + * @param phaseMassDens phase mass density + * @param dPhaseMassDens derivative of phase mass density wrt pressure, temperature, comp fraction + * @param phaseCapPressure phase capillary pressure + * @param dPhaseCapPressure_dPhaseVolFrac derivative of phase capillary pressure wrt phase volume fraction + * @param k_up uptream index for this phase + * @param potGrad potential gradient for this phase + * @param phaseFlux phase flux + * @param dPhaseFlux_dP derivative of phase flux wrt pressure + * @param dPhaseFlux_dC derivative of phase flux wrt comp density + */ + template< integer numComp, integer numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + compute( integer const numPhase, + integer const ip, + integer const hasCapPressure, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + real64 const ( &trans )[2], + real64 const ( &dTrans_dPres )[2], + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseMob, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseMob, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, + ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, + ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, + localIndex & k_up, + real64 & potGrad, + real64 ( &phaseFlux ), + real64 ( & dPhaseFlux_dP )[numFluxSupportPoints], + real64 ( & dPhaseFlux_dC )[numFluxSupportPoints][numComp], + real64 ( & compFlux )[numComp], + real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], + real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) + { + real64 dPresGrad_dP[numFluxSupportPoints]{}; + real64 dPresGrad_dC[numFluxSupportPoints][numComp]{}; + real64 dGravHead_dP[numFluxSupportPoints]{}; + real64 dGravHead_dC[numFluxSupportPoints][numComp]{}; + PotGrad::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, seri, sesri, sei, trans, dTrans_dPres, pres, + gravCoef, dPhaseVolFrac, dCompFrac_dCompDens, phaseMassDens, dPhaseMassDens, + phaseCapPressure, dPhaseCapPressure_dPhaseVolFrac, potGrad, dPresGrad_dP, + dPresGrad_dC, dGravHead_dP, dGravHead_dC ); + + // *** upwinding *** + + // choose upstream cell + k_up = (potGrad >= 0) ? 0 : 1; + + localIndex const er_up = seri[k_up]; + localIndex const esr_up = sesri[k_up]; + localIndex const ei_up = sei[k_up]; + + real64 const mobility = phaseMob[er_up][esr_up][ei_up][ip]; + + // pressure gradient depends on all points in the stencil + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dPhaseFlux_dP[ke] += dPresGrad_dP[ke] - dGravHead_dP[ke]; + dPhaseFlux_dP[ke] *= mobility; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[ke][jc] += dPresGrad_dC[ke][jc] - dGravHead_dC[ke][jc]; + dPhaseFlux_dC[ke][jc] *= mobility; + } + } + // compute phase flux using upwind mobility. + phaseFlux = mobility * potGrad; + + real64 const dMob_dP = dPhaseMob[er_up][esr_up][ei_up][ip][Deriv::dP]; + arraySlice1d< real64 const, compflow::USD_PHASE_DC - 2 > dPhaseMobSub = + dPhaseMob[er_up][esr_up][ei_up][ip]; + + // add contribution from upstream cell mobility derivatives + dPhaseFlux_dP[k_up] += dMob_dP * potGrad; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[k_up][jc] += dPhaseMobSub[Deriv::dC+jc] * potGrad; + } + + //distribute on phaseComponentFlux here + PhaseComponentFlux::compute( ip, k_up, seri, sesri, sei, phaseCompFrac, dPhaseCompFrac, dCompFrac_dCompDens, phaseFlux + , dPhaseFlux_dP, dPhaseFlux_dC, compFlux, dCompFlux_dP, dCompFlux_dC ); + + } +}; + +} // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities + +} // namespace geos + + +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PPUPHASEFLUX_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseComponentFlux.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseComponentFlux.hpp new file mode 100644 index 00000000000..812cc19eb3d --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PhaseComponentFlux.hpp @@ -0,0 +1,128 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PhaseComponentFlux.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUX_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUX_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "constitutive/fluid/multifluid/Layouts.hpp" +#include "mesh/ElementRegionManager.hpp" + + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernelUtilities +{ + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +using Deriv = constitutive::multifluid::DerivativeOffset; + +struct PhaseComponentFlux +{ + /** + * @brief Compute the component flux for a given phase + * @tparam numComp number of components + * @tparam numFluxSupportPoints number of flux support points + * @param ip phase index + * @param k_up uptream index for this phase + * @param seri arraySlice of the stencil-implied element region index + * @param sesri arraySlice of the stencil-implied element subregion index + * @param sei arraySlice of the stencil-implied element index + * @param phaseCompFrac phase component fraction + * @param dPhaseCompFrac derivative of phase component fraction wrt pressure, temperature, component fraction + * @param dCompFrac_dCompDens derivative of component fraction wrt component density + * @param phaseFlux phase flux + * @param dPhaseFlux_dP derivative of phase flux wrt pressure + * @param dPhaseFlux_dC derivative of phase flux wrt comp density + * @param compFlux component flux + * @param dCompFlux_dP derivative of phase flux wrt pressure + * @param dCompFlux_dC derivative of phase flux wrt comp density + */ + template< localIndex numComp, localIndex numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + compute( localIndex const ip, + localIndex const k_up, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, + real64 const & phaseFlux, + real64 const ( &dPhaseFlux_dP )[numFluxSupportPoints], + real64 const ( &dPhaseFlux_dC )[numFluxSupportPoints][numComp], + real64 ( & compFlux )[numComp], + real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], + real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) + { + localIndex const er_up = seri[k_up]; + localIndex const esr_up = sesri[k_up]; + localIndex const ei_up = sei[k_up]; + + real64 dProp_dC[numComp]{}; + + // slice some constitutive arrays to avoid too much indexing in component loop + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub = + phaseCompFrac[er_up][esr_up][ei_up][0][ip]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub = + dPhaseCompFrac[er_up][esr_up][ei_up][0][ip]; + + // compute component fluxes and derivatives using upstream cell composition + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = phaseCompFracSub[ic]; + compFlux[ic] += phaseFlux * ycp; + + // derivatives stemming from phase flux + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dCompFlux_dP[ke][ic] += dPhaseFlux_dP[ke] * ycp; + for( integer jc = 0; jc < numComp; ++jc ) + { + dCompFlux_dC[ke][ic][jc] += dPhaseFlux_dC[ke][jc] * ycp; + } + } + + // additional derivatives stemming from upstream cell phase composition + dCompFlux_dP[k_up][ic] += phaseFlux * dPhaseCompFracSub[ic][Deriv::dP]; + + // convert derivatives of comp fraction w.r.t. comp fractions to derivatives w.r.t. comp densities + applyChainRule( numComp, + dCompFrac_dCompDens[er_up][esr_up][ei_up], + dPhaseCompFracSub[ic], + dProp_dC, + Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + dCompFlux_dC[k_up][ic][jc] += phaseFlux * dProp_dC[jc]; + } + } + } +}; + +} // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities + +} // namespace geos + +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUX_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp new file mode 100644 index 00000000000..5d288780182 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp @@ -0,0 +1,187 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PotGrad.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRAD_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRAD_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "constitutive/fluid/multifluid/Layouts.hpp" +#include "constitutive/capillaryPressure/layouts.hpp" +#include "mesh/ElementRegionManager.hpp" + + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernelUtilities +{ + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +using Deriv = constitutive::multifluid::DerivativeOffset; + +struct PotGrad +{ + template< integer numComp, integer numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + compute ( integer const numPhase, + integer const ip, + integer const hasCapPressure, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + real64 const ( &trans )[numFluxSupportPoints], + real64 const ( &dTrans_dPres )[numFluxSupportPoints], + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, + ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, + ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, + real64 & potGrad, + real64 ( & dPresGrad_dP )[numFluxSupportPoints], + real64 ( & dPresGrad_dC )[numFluxSupportPoints][numComp], + real64 ( & dGravHead_dP )[numFluxSupportPoints], + real64 ( & dGravHead_dC )[numFluxSupportPoints][numComp] ) + { + // assign derivatives arrays to zero + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + dPresGrad_dP[i] = 0.0; + dGravHead_dP[i] = 0.0; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPresGrad_dC[i][jc] = 0.0; + dGravHead_dC[i][jc] = 0.0; + } + } + + // create local work arrays + real64 densMean = 0.0; + real64 dDensMean_dP[numFluxSupportPoints]{}; + real64 dDensMean_dC[numFluxSupportPoints][numComp]{}; + + real64 presGrad = 0.0; + real64 gravHead = 0.0; + real64 dCapPressure_dC[numComp]{}; + + real64 dProp_dC[numComp]{}; + + // calculate quantities on primary connected cells + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + // density + real64 const density = phaseMassDens[er][esr][ei][0][ip]; + real64 const dDens_dP = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; + + applyChainRule( numComp, + dCompFrac_dCompDens[er][esr][ei], + dPhaseMassDens[er][esr][ei][0][ip], + dProp_dC, + Deriv::dC ); + + // average density and derivatives + densMean += 0.5 * density; + dDensMean_dP[i] = 0.5 * dDens_dP; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDensMean_dC[i][jc] = 0.5 * dProp_dC[jc]; + } + } + + /// compute the TPFA potential difference + for( integer i = 0; i < numFluxSupportPoints; i++ ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + // capillary pressure + real64 capPressure = 0.0; + real64 dCapPressure_dP = 0.0; + + for( integer ic = 0; ic < numComp; ++ic ) + { + dCapPressure_dC[ic] = 0.0; + } + + if( hasCapPressure ) + { + capPressure = phaseCapPressure[er][esr][ei][0][ip]; + + for( integer jp = 0; jp < numPhase; ++jp ) + { + real64 const dCapPressure_dS = dPhaseCapPressure_dPhaseVolFrac[er][esr][ei][0][ip][jp]; + dCapPressure_dP += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dP]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + dCapPressure_dC[jc] += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dC+jc]; + } + } + } + + presGrad += trans[i] * (pres[er][esr][ei] - capPressure); + dPresGrad_dP[i] += trans[i] * (1 - dCapPressure_dP) + + dTrans_dPres[i] * (pres[er][esr][ei] - capPressure); + for( integer jc = 0; jc < numComp; ++jc ) + { + dPresGrad_dC[i][jc] += -trans[i] * dCapPressure_dC[jc]; + } + + real64 const gravD = trans[i] * gravCoef[er][esr][ei]; + real64 const dGravD_dP = dTrans_dPres[i] * gravCoef[er][esr][ei]; + + // the density used in the potential difference is always a mass density + // unlike the density used in the phase mobility, which is a mass density + // if useMass == 1 and a molar density otherwise + gravHead += densMean * gravD; + + // need to add contributions from both cells the mean density depends on + for( integer j = 0; j < numFluxSupportPoints; ++j ) + { + dGravHead_dP[j] += dDensMean_dP[j] * gravD + dGravD_dP * densMean; + for( integer jc = 0; jc < numComp; ++jc ) + { + dGravHead_dC[j][jc] += dDensMean_dC[j][jc] * gravD; + } + } + } + + // compute phase potential gradient + potGrad = presGrad - gravHead; + + } + +}; + +} // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities + +} // namespace geos + +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELUTILITIES_HPP From 0aa4f1271a3d6c0b436404bcb778f1a707969599 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Sat, 28 Sep 2024 18:43:03 -0500 Subject: [PATCH 24/47] more or less ready --- .../physicsSolvers/fluidFlow/CMakeLists.txt | 46 +- .../fluidFlow/CompositionalMultiphaseBase.cpp | 2 +- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 31 +- .../CompositionalMultiphaseStatistics.cpp | 7 +- .../ReactiveCompositionalMultiphaseOBL.cpp | 2 +- .../kernels/compositional/AquiferBCKernel.cpp | 273 +++ .../kernels/compositional/AquiferBCKernel.hpp | 151 ++ ...MultiphaseFVMKernels.cpp => CFLKernel.cpp} | 266 +- .../kernels/compositional/CFLKernel.hpp | 203 ++ .../DiffusionDispersionFluxComputeKernel.hpp | 793 ++++++ .../DirichletFluxComputeKernel.hpp | 577 +++++ ...s.hpp => DissipationFluxComputeKernel.hpp} | 36 +- .../compositional/FluxComputeKernel.hpp | 594 +++++ .../compositional/FluxComputeKernelBase.cpp | 65 + .../compositional/FluxComputeKernelBase.hpp | 196 ++ ...ermalCompositionalMultiphaseFVMKernels.hpp | 2182 ----------------- .../kernels/compositional/PotGrad.hpp | 2 +- ...ctiveCompositionalMultiphaseOBLKernels.hpp | 24 +- .../SolidInternalEnergyUpdateKernel.hpp | 2 +- .../compositional/SolutionCheckKernel.hpp | 4 +- ... SolutionScalingAndCheckingKernelBase.hpp} | 14 +- .../compositional/SolutionScalingKernel.hpp | 6 +- ...ls.hpp => StabilizedFluxComputeKernel.hpp} | 36 +- .../compositional/StatisticsKernel.hpp | 13 +- ...ermalCompositionalMultiphaseFVMKernels.hpp | 1439 ----------- ...alDiffusionDispersionFluxComputeKernel.hpp | 352 +++ .../ThermalDirichletFluxComputeKernel.hpp | 486 ++++ .../ThermalFluxComputeKernel.hpp | 558 +++++ .../ThermalPhaseMobilityKernel.hpp | 154 ++ ...ePhasePoromechanicsConformingFractures.hpp | 2 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 2 +- ...ePhasePoromechanicsConformingFractures.hpp | 2 +- ...glePhasePoromechanicsEmbeddedFractures.hpp | 2 +- 33 files changed, 4534 insertions(+), 3988 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/{IsothermalCompositionalMultiphaseFVMKernels.cpp => CFLKernel.cpp} (58%) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/{DissipationCompositionalMultiphaseFVMKernels.hpp => DissipationFluxComputeKernel.hpp} (92%) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp rename src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/{ScalingAndCheckingSystemSolutionKernelBase.hpp => SolutionScalingAndCheckingKernelBase.hpp} (91%) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/{StabilizedCompositionalMultiphaseFVMKernels.hpp => StabilizedFluxComputeKernel.hpp} (92%) delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseMobilityKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt index 98cf023f51d..a77be67f377 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/fluidFlow/CMakeLists.txt @@ -45,15 +45,47 @@ set( physicsSolvers_headers fluidFlow/kernels/singlePhase/proppant/ProppantBaseKernels.hpp fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.hpp fluidFlow/kernels/compositional/AccumulationKernel.hpp - fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/compositional/AquiferBCKernel.hpp fluidFlow/kernels/compositional/PPUPhaseFlux.hpp fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp - fluidFlow/kernels/compositional/IHUPhaseFlux.hpp - fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp + fluidFlow/kernels/compositional/CFLKernel.hpp fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp + fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp + fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp + fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp + fluidFlow/kernels/compositional/FluidUpdateKernel.hpp + fluidFlow/kernels/compositional/FluidUpdateKernel.hpp + fluidFlow/kernels/compositional/FluxComputeKernel.hpp + fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp + fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp + fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp + fluidFlow/kernels/compositional/IHUPhaseFlux.hpp + fluidFlow/kernels/compositional/KernelLaunchSelector.hpp + fluidFlow/kernels/compositional/PhaseComponentFlux.hpp + fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp + fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp + fluidFlow/kernels/compositional/PotGrad.hpp + fluidFlow/kernels/compositional/PPUPhaseFlux.hpp + fluidFlow/kernels/compositional/PropertyKernelBase.hpp fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp - fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp + fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp + fluidFlow/kernels/compositional/ResidualNormKernel.hpp + fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp + fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp + fluidFlow/kernels/compositional/SolutionCheckKernel.hpp + fluidFlow/kernels/compositional/SolutionScalingKernel.hpp + fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp + fluidFlow/kernels/compositional/StatisticsKernel.hpp + fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp + fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp + fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp + fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp + fluidFlow/kernels/compositional/ThermalPhaseMobilityKernel.hpp + fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp + fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp + fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp + fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp fluidFlow/wells/CompositionalMultiphaseWell.hpp fluidFlow/wells/CompositionalMultiphaseWellFields.hpp fluidFlow/wells/SinglePhaseWell.hpp @@ -86,7 +118,9 @@ set( physicsSolvers_sources fluidFlow/SourceFluxStatistics.cpp fluidFlow/StencilDataCollection.cpp fluidFlow/kernels/singlePhase/proppant/ProppantFluxKernels.cpp - fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp + fluidFlow/kernels/compositional/AquiferBCKernel.cpp + fluidFlow/kernels/compositional/CFLKernel.cpp + fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.cpp fluidFlow/wells/CompositionalMultiphaseWell.cpp fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.cpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 13d65723666..db4fe4399fb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -42,7 +42,6 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" // TODO this should not be here #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" @@ -53,6 +52,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index a48926fd0bd..5278a83a5e5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -36,16 +36,23 @@ #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ResidualNormKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalResidualNormKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionCheckKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseMobilityKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp" namespace geos { @@ -175,7 +182,7 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, if( m_isThermal ) { thermalCompositionalMultiphaseFVMKernels:: - FaceBasedAssemblyKernelFactory:: + FluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -194,7 +201,7 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, if( m_dbcParams.useDBC ) { dissipationCompositionalMultiphaseFVMKernels:: - FaceBasedAssemblyKernelFactory:: + FluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -217,7 +224,7 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, else { isothermalCompositionalMultiphaseFVMKernels:: - FaceBasedAssemblyKernelFactory:: + FluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -241,7 +248,7 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, if( m_isThermal ) { thermalCompositionalMultiphaseFVMKernels:: - DiffusionDispersionFaceBasedAssemblyKernelFactory:: + DiffusionDispersionFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -259,7 +266,7 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, else { isothermalCompositionalMultiphaseFVMKernels:: - DiffusionDispersionFaceBasedAssemblyKernelFactory:: + DiffusionDispersionFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -308,7 +315,7 @@ void CompositionalMultiphaseFVM::assembleStabilizedFluxTerms( real64 const dt, // Thermal implementation not supported yet stabilizedCompositionalMultiphaseFVMKernels:: - FaceBasedAssemblyKernelFactory:: + FluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -981,7 +988,7 @@ void CompositionalMultiphaseFVM::applyFaceDirichletBC( real64 const time_n, { //todo (jafranc) extend upwindScheme name if satisfied in isothermalCase thermalCompositionalMultiphaseFVMKernels:: - DirichletFaceBasedAssemblyKernelFactory:: + DirichletFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), @@ -999,7 +1006,7 @@ void CompositionalMultiphaseFVM::applyFaceDirichletBC( real64 const time_n, else { isothermalCompositionalMultiphaseFVMKernels:: - DirichletFaceBasedAssemblyKernelFactory:: + DirichletFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp index 80f34fdd364..a0ca9246c47 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp @@ -19,19 +19,14 @@ #include "CompositionalMultiphaseStatistics.hpp" +#include "mesh/DomainPartition.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" #include "constitutive/solid/CoupledSolidBase.hpp" -#include "finiteVolume/FiniteVolumeManager.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "mainInterface/ProblemManager.hpp" -#include "physicsSolvers/PhysicsSolverManager.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/AccumulationKernel.hpp" // check if needed -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" // check if needed #include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp index 3a3e2276582..2f21c64ae61 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp @@ -739,7 +739,7 @@ void ReactiveCompositionalMultiphaseOBL::assembleFluxTerms( real64 const dt, { typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); - FaceBasedAssemblyKernelFactory:: + FluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numPhases, m_numComponents, m_enableEnergyBalance, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp new file mode 100644 index 00000000000..b7a9697f819 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp @@ -0,0 +1,273 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 AquiferBCKernel.cpp + */ + +#include "physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" + +#include "finiteVolume/CellElementStencilTPFA.hpp" +#include "finiteVolume/SurfaceElementStencil.hpp" +#include "finiteVolume/EmbeddedSurfaceToCellStencil.hpp" +#include "finiteVolume/FaceElementToCellStencil.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" + +namespace geos +{ +using namespace constitutive; + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** AquiferBCKernel ********************************/ + +template< integer NC > +GEOS_HOST_DEVICE +void +AquiferBCKernel:: + compute( integer const numPhases, + integer const ipWater, + bool const allowAllPhasesIntoAquifer, + real64 const aquiferVolFlux, + real64 const dAquiferVolFlux_dPres, + real64 const aquiferWaterPhaseDens, + arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, + arraySlice1d< real64 const, multifluid::USD_PHASE - 2 > phaseDens, + arraySlice2d< real64 const, multifluid::USD_PHASE_DC - 2 > dPhaseDens, + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac, + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac, + arraySlice2d< real64 const, multifluid::USD_PHASE_COMP - 2 > phaseCompFrac, + arraySlice3d< real64 const, multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac, + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens, + real64 const dt, + real64 (& localFlux)[NC], + real64 (& localFluxJacobian)[NC][NC+1] ) +{ + using Deriv = multifluid::DerivativeOffset; + + real64 dProp_dC[NC]{}; + real64 dPhaseFlux_dCompDens[NC]{}; + + if( aquiferVolFlux > 0 ) // aquifer is upstream + { + // in this case, we assume that: + // - only the water phase is present in the aquifer + // - the aquifer water phase composition is constant + + for( integer ic = 0; ic < NC; ++ic ) + { + real64 const phaseFlux = aquiferVolFlux * aquiferWaterPhaseDens; + localFlux[ic] -= dt * phaseFlux * aquiferWaterPhaseCompFrac[ic]; + localFluxJacobian[ic][0] -= dt * dAquiferVolFlux_dPres * aquiferWaterPhaseDens * aquiferWaterPhaseCompFrac[ic]; + } + } + else // reservoir is upstream + { + for( integer ip = 0; ip < numPhases; ++ip ) + { + + // Why two options below: + // - The aquifer model assumes single-phase water flow, so ideally, we should only allow water phase flow from the reservoir to the + // aquifer + // - But, if/when the CO2 plume reaches the reservoir cell connected to the aquifer and saturates it, the aquifer flux becomes zero + // if we don't let some CO2 go into the aquifer + + if( ip == ipWater || allowAllPhasesIntoAquifer ) + { + real64 const phaseDensVolFrac = phaseDens[ip] * phaseVolFrac[ip]; + real64 const phaseFlux = aquiferVolFlux * phaseDensVolFrac; + real64 const dPhaseFlux_dPres = dAquiferVolFlux_dPres * phaseDensVolFrac + + aquiferVolFlux * ( dPhaseDens[ip][Deriv::dP] * phaseVolFrac[ip] + phaseDens[ip] * dPhaseVolFrac[ip][Deriv::dP] ); + + applyChainRule( NC, dCompFrac_dCompDens, dPhaseDens[ip], dProp_dC, Deriv::dC ); + for( integer ic = 0; ic < NC; ++ic ) + { + dPhaseFlux_dCompDens[ic] = aquiferVolFlux * ( dProp_dC[ic] * phaseVolFrac[ip] + phaseDens[ip] * dPhaseVolFrac[ip][Deriv::dC+ic] ); + } + + for( integer ic = 0; ic < NC; ++ic ) + { + localFlux[ic] -= dt * phaseFlux * phaseCompFrac[ip][ic]; + localFluxJacobian[ic][0] -= dt * ( dPhaseFlux_dPres * phaseCompFrac[ip][ic] + phaseFlux * dPhaseCompFrac[ip][ic][Deriv::dP] ); + + applyChainRule( NC, dCompFrac_dCompDens, dPhaseCompFrac[ip][ic], dProp_dC, Deriv::dC ); + for( integer jc = 0; jc < NC; ++jc ) + { + localFluxJacobian[ic][jc+1] -= dt * ( dPhaseFlux_dCompDens[jc] * phaseCompFrac[ip][ic] + phaseFlux * dProp_dC[jc] ); + } + } + } + } + } +} + +template< integer NC > +void +AquiferBCKernel:: + launch( integer const numPhases, + integer const ipWater, + bool const allowAllPhasesIntoAquifer, + integer const useTotalMassEquation, + BoundaryStencil const & stencil, + globalIndex const rankOffset, + ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + real64 const aquiferWaterPhaseDens, + arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, + ElementViewConst< arrayView1d< integer const > > const & ghostRank, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & presOld, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, + ElementViewConst< arrayView3d< real64 const, multifluid::USD_PHASE > > const & phaseDens, + ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_DC > > const & dPhaseDens, + ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementViewConst< arrayView5d< real64 const, multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, + real64 const timeAtBeginningOfStep, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) +{ + + using namespace compositionalMultiphaseUtilities; + using Order = BoundaryStencil::Order; + + BoundaryStencil::IndexContainerViewConstType const & seri = stencil.getElementRegionIndices(); + BoundaryStencil::IndexContainerViewConstType const & sesri = stencil.getElementSubRegionIndices(); + BoundaryStencil::IndexContainerViewConstType const & sefi = stencil.getElementIndices(); + BoundaryStencil::WeightContainerViewConstType const & weight = stencil.getWeights(); + + forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + constexpr integer NDOF = NC + 1; + + // working arrays + globalIndex dofColIndices[NDOF]{}; + real64 localFlux[NC]{}; + real64 localFluxJacobian[NC][NDOF]{}; + + localIndex const er = seri( iconn, Order::ELEM ); + localIndex const esr = sesri( iconn, Order::ELEM ); + localIndex const ei = sefi( iconn, Order::ELEM ); + real64 const areaFraction = weight( iconn, Order::ELEM ); + + // compute the aquifer influx rate using the pressure influence function and the aquifer props + real64 dAquiferVolFlux_dPres = 0.0; + real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep, + dt, + pres[er][esr][ei], + presOld[er][esr][ei], + gravCoef[er][esr][ei], + areaFraction, + dAquiferVolFlux_dPres ); + + // compute the phase/component aquifer flux + AquiferBCKernel::compute< NC >( numPhases, + ipWater, + allowAllPhasesIntoAquifer, + aquiferVolFlux, + dAquiferVolFlux_dPres, + aquiferWaterPhaseDens, + aquiferWaterPhaseCompFrac, + phaseDens[er][esr][ei][0], + dPhaseDens[er][esr][ei][0], + phaseVolFrac[er][esr][ei], + dPhaseVolFrac[er][esr][ei], + phaseCompFrac[er][esr][ei][0], + dPhaseCompFrac[er][esr][ei][0], + dCompFrac_dCompDens[er][esr][ei], + dt, + localFlux, + localFluxJacobian ); + + // populate dof indices + globalIndex const offset = dofNumber[er][esr][ei]; + for( integer jdof = 0; jdof < NDOF; ++jdof ) + { + dofColIndices[jdof] = offset + jdof; + } + + if( useTotalMassEquation > 0 ) + { + // Apply equation/variable change transformation(s) + real64 work[NDOF]; + shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( NC, NDOF, localFluxJacobian, work ); + shiftElementsAheadByOneAndReplaceFirstElementWithSum( NC, localFlux ); + } + + // Add to residual/jacobian + if( ghostRank[er][esr][ei] < 0 ) + { + globalIndex const globalRow = dofNumber[er][esr][ei]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( localMatrix.numRows(), localRow + NC ); + + for( integer ic = 0; ic < NC; ++ic ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[localRow + ic], localFlux[ic] ); + localMatrix.addToRow< parallelDeviceAtomic >( localRow + ic, + dofColIndices, + localFluxJacobian[ic], + NDOF ); + } + } + } ); +} + +#define INST_AquiferBCKernel( NC ) \ + template \ + void AquiferBCKernel:: \ + launch< NC >( integer const numPhases, \ + integer const ipWater, \ + bool const allowAllPhasesIntoAquifer, \ + integer const useTotalMassEquation, \ + BoundaryStencil const & stencil, \ + globalIndex const rankOffset, \ + ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, \ + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, \ + real64 const aquiferWaterPhaseDens, \ + arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, \ + ElementViewConst< arrayView1d< integer const > > const & ghostRank, \ + ElementViewConst< arrayView1d< real64 const > > const & pres, \ + ElementViewConst< arrayView1d< real64 const > > const & dPres, \ + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, \ + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, \ + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, \ + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, \ + ElementViewConst< arrayView3d< real64 const, multifluid::USD_PHASE > > const & phaseDens, \ + ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_DC > > const & dPhaseDens, \ + ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_COMP > > const & phaseCompFrac, \ + ElementViewConst< arrayView5d< real64 const, multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, \ + real64 const timeAtBeginningOfStep, \ + real64 const dt, \ + CRSMatrixView< real64, globalIndex const > const & localMatrix, \ + arrayView1d< real64 > const & localRhs ) + +INST_AquiferBCKernel( 1 ); +INST_AquiferBCKernel( 2 ); +INST_AquiferBCKernel( 3 ); +INST_AquiferBCKernel( 4 ); +INST_AquiferBCKernel( 5 ); + +#undef INST_AquiferBCKernel + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp new file mode 100644 index 00000000000..cd7a839ce9d --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp @@ -0,0 +1,151 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 AquiferBCKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_AQUIFERBCKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_AQUIFERBCKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" +#include "constitutive/diffusion/DiffusionFields.hpp" +#include "constitutive/diffusion/DiffusionBase.hpp" +#include "constitutive/dispersion/DispersionFields.hpp" +#include "constitutive/dispersion/DispersionBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" +#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" +#include "constitutive/solid/porosity/PorosityBase.hpp" +#include "constitutive/solid/porosity/PorosityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** AquiferBCKernel ********************************/ + +/** + * @brief Functions to assemble aquifer boundary condition contributions to residual and Jacobian + */ +struct AquiferBCKernel +{ + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using CompFlowAccessors = + StencilAccessors< fields::ghostRank, + fields::flow::pressure, + fields::flow::pressure_n, + fields::flow::gravityCoefficient, + fields::flow::phaseVolumeFraction, + fields::flow::dPhaseVolumeFraction, + fields::flow::dGlobalCompFraction_dGlobalCompDensity >; + + using MultiFluidAccessors = + StencilMaterialAccessors< constitutive::MultiFluidBase, + fields::multifluid::phaseDensity, + fields::multifluid::dPhaseDensity, + fields::multifluid::phaseCompFraction, + fields::multifluid::dPhaseCompFraction >; + + template< integer NC > + GEOS_HOST_DEVICE + inline + static void + compute( integer const numPhases, + integer const ipWater, + bool const allowAllPhasesIntoAquifer, + real64 const aquiferVolFlux, + real64 const dAquiferVolFlux_dPres, + real64 const aquiferWaterPhaseDens, + arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseDens, + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseDens, + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac, + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac, + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 2 > phaseCompFrac, + arraySlice3d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac, + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens, + real64 const dt, + real64 ( &localFlux )[NC], + real64 ( &localFluxJacobian )[NC][NC+1] ); + + template< integer NC > + static void + launch( integer const numPhases, + integer const ipWater, + bool const allowAllPhasesIntoAquifer, + integer const useTotalMassEquation, + BoundaryStencil const & stencil, + globalIndex const rankOffset, + ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, + AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, + real64 const aquiferWaterPhaseDens, + arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, + ElementViewConst< arrayView1d< integer const > > const & ghostRank, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & pres_n, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, + real64 const timeAtBeginningOfStep, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ); + +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_AQUIFERBCKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.cpp similarity index 58% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.cpp index 0f878628377..851b7d8daa3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.cpp @@ -14,10 +14,10 @@ */ /** - * @file IsothermalCompositionalMultiphaseFVMKernels.cpp + * @file CFLKernel.cpp */ -#include "IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "finiteVolume/CellElementStencilTPFA.hpp" @@ -33,33 +33,6 @@ using namespace constitutive; namespace isothermalCompositionalMultiphaseFVMKernels { -/******************************** FaceBasedAssemblyKernel ********************************/ - -FaceBasedAssemblyKernelBase::FaceBasedAssemblyKernelBase( integer const numPhases, - globalIndex const rankOffset, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags ) - : m_numPhases( numPhases ), - m_rankOffset( rankOffset ), - m_dt( dt ), - m_dofNumber( dofNumberAccessor.toNestedViewConst() ), - m_ghostRank( compFlowAccessors.get( fields::ghostRank {} ) ), - m_gravCoef( compFlowAccessors.get( fields::flow::gravityCoefficient {} ) ), - m_pres( compFlowAccessors.get( fields::flow::pressure {} ) ), - m_dCompFrac_dCompDens( compFlowAccessors.get( fields::flow::dGlobalCompFraction_dGlobalCompDensity {} ) ), - m_dPhaseVolFrac( compFlowAccessors.get( fields::flow::dPhaseVolumeFraction {} ) ), - m_phaseCompFrac( multiFluidAccessors.get( fields::multifluid::phaseCompFraction {} ) ), - m_dPhaseCompFrac( multiFluidAccessors.get( fields::multifluid::dPhaseCompFraction {} ) ), - m_localMatrix( localMatrix ), - m_localRhs( localRhs ), - m_kernelFlags( kernelFlags ) -{} - /******************************** CFLFluxKernel ********************************/ template< integer NC, localIndex NUM_ELEMS, localIndex maxStencilSize > @@ -457,241 +430,6 @@ INST_CFLKernel( 5, 3 ); #undef INST_CFLKernel -/******************************** AquiferBCKernel ********************************/ - -template< integer NC > -GEOS_HOST_DEVICE -void -AquiferBCKernel:: - compute( integer const numPhases, - integer const ipWater, - bool const allowAllPhasesIntoAquifer, - real64 const aquiferVolFlux, - real64 const dAquiferVolFlux_dPres, - real64 const aquiferWaterPhaseDens, - arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, - arraySlice1d< real64 const, multifluid::USD_PHASE - 2 > phaseDens, - arraySlice2d< real64 const, multifluid::USD_PHASE_DC - 2 > dPhaseDens, - arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac, - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac, - arraySlice2d< real64 const, multifluid::USD_PHASE_COMP - 2 > phaseCompFrac, - arraySlice3d< real64 const, multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac, - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens, - real64 const dt, - real64 (& localFlux)[NC], - real64 (& localFluxJacobian)[NC][NC+1] ) -{ - using Deriv = multifluid::DerivativeOffset; - - real64 dProp_dC[NC]{}; - real64 dPhaseFlux_dCompDens[NC]{}; - - if( aquiferVolFlux > 0 ) // aquifer is upstream - { - // in this case, we assume that: - // - only the water phase is present in the aquifer - // - the aquifer water phase composition is constant - - for( integer ic = 0; ic < NC; ++ic ) - { - real64 const phaseFlux = aquiferVolFlux * aquiferWaterPhaseDens; - localFlux[ic] -= dt * phaseFlux * aquiferWaterPhaseCompFrac[ic]; - localFluxJacobian[ic][0] -= dt * dAquiferVolFlux_dPres * aquiferWaterPhaseDens * aquiferWaterPhaseCompFrac[ic]; - } - } - else // reservoir is upstream - { - for( integer ip = 0; ip < numPhases; ++ip ) - { - - // Why two options below: - // - The aquifer model assumes single-phase water flow, so ideally, we should only allow water phase flow from the reservoir to the - // aquifer - // - But, if/when the CO2 plume reaches the reservoir cell connected to the aquifer and saturates it, the aquifer flux becomes zero - // if we don't let some CO2 go into the aquifer - - if( ip == ipWater || allowAllPhasesIntoAquifer ) - { - real64 const phaseDensVolFrac = phaseDens[ip] * phaseVolFrac[ip]; - real64 const phaseFlux = aquiferVolFlux * phaseDensVolFrac; - real64 const dPhaseFlux_dPres = dAquiferVolFlux_dPres * phaseDensVolFrac - + aquiferVolFlux * ( dPhaseDens[ip][Deriv::dP] * phaseVolFrac[ip] + phaseDens[ip] * dPhaseVolFrac[ip][Deriv::dP] ); - - applyChainRule( NC, dCompFrac_dCompDens, dPhaseDens[ip], dProp_dC, Deriv::dC ); - for( integer ic = 0; ic < NC; ++ic ) - { - dPhaseFlux_dCompDens[ic] = aquiferVolFlux * ( dProp_dC[ic] * phaseVolFrac[ip] + phaseDens[ip] * dPhaseVolFrac[ip][Deriv::dC+ic] ); - } - - for( integer ic = 0; ic < NC; ++ic ) - { - localFlux[ic] -= dt * phaseFlux * phaseCompFrac[ip][ic]; - localFluxJacobian[ic][0] -= dt * ( dPhaseFlux_dPres * phaseCompFrac[ip][ic] + phaseFlux * dPhaseCompFrac[ip][ic][Deriv::dP] ); - - applyChainRule( NC, dCompFrac_dCompDens, dPhaseCompFrac[ip][ic], dProp_dC, Deriv::dC ); - for( integer jc = 0; jc < NC; ++jc ) - { - localFluxJacobian[ic][jc+1] -= dt * ( dPhaseFlux_dCompDens[jc] * phaseCompFrac[ip][ic] + phaseFlux * dProp_dC[jc] ); - } - } - } - } - } -} - -template< integer NC > -void -AquiferBCKernel:: - launch( integer const numPhases, - integer const ipWater, - bool const allowAllPhasesIntoAquifer, - integer const useTotalMassEquation, - BoundaryStencil const & stencil, - globalIndex const rankOffset, - ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, - real64 const aquiferWaterPhaseDens, - arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, - ElementViewConst< arrayView1d< integer const > > const & ghostRank, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & presOld, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, - ElementViewConst< arrayView3d< real64 const, multifluid::USD_PHASE > > const & phaseDens, - ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_DC > > const & dPhaseDens, - ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_COMP > > const & phaseCompFrac, - ElementViewConst< arrayView5d< real64 const, multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, - real64 const timeAtBeginningOfStep, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) -{ - - using namespace compositionalMultiphaseUtilities; - using Order = BoundaryStencil::Order; - - BoundaryStencil::IndexContainerViewConstType const & seri = stencil.getElementRegionIndices(); - BoundaryStencil::IndexContainerViewConstType const & sesri = stencil.getElementSubRegionIndices(); - BoundaryStencil::IndexContainerViewConstType const & sefi = stencil.getElementIndices(); - BoundaryStencil::WeightContainerViewConstType const & weight = stencil.getWeights(); - - forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - constexpr integer NDOF = NC + 1; - - // working arrays - globalIndex dofColIndices[NDOF]{}; - real64 localFlux[NC]{}; - real64 localFluxJacobian[NC][NDOF]{}; - - localIndex const er = seri( iconn, Order::ELEM ); - localIndex const esr = sesri( iconn, Order::ELEM ); - localIndex const ei = sefi( iconn, Order::ELEM ); - real64 const areaFraction = weight( iconn, Order::ELEM ); - - // compute the aquifer influx rate using the pressure influence function and the aquifer props - real64 dAquiferVolFlux_dPres = 0.0; - real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep, - dt, - pres[er][esr][ei], - presOld[er][esr][ei], - gravCoef[er][esr][ei], - areaFraction, - dAquiferVolFlux_dPres ); - - // compute the phase/component aquifer flux - AquiferBCKernel::compute< NC >( numPhases, - ipWater, - allowAllPhasesIntoAquifer, - aquiferVolFlux, - dAquiferVolFlux_dPres, - aquiferWaterPhaseDens, - aquiferWaterPhaseCompFrac, - phaseDens[er][esr][ei][0], - dPhaseDens[er][esr][ei][0], - phaseVolFrac[er][esr][ei], - dPhaseVolFrac[er][esr][ei], - phaseCompFrac[er][esr][ei][0], - dPhaseCompFrac[er][esr][ei][0], - dCompFrac_dCompDens[er][esr][ei], - dt, - localFlux, - localFluxJacobian ); - - // populate dof indices - globalIndex const offset = dofNumber[er][esr][ei]; - for( integer jdof = 0; jdof < NDOF; ++jdof ) - { - dofColIndices[jdof] = offset + jdof; - } - - if( useTotalMassEquation > 0 ) - { - // Apply equation/variable change transformation(s) - real64 work[NDOF]; - shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( NC, NDOF, localFluxJacobian, work ); - shiftElementsAheadByOneAndReplaceFirstElementWithSum( NC, localFlux ); - } - - // Add to residual/jacobian - if( ghostRank[er][esr][ei] < 0 ) - { - globalIndex const globalRow = dofNumber[er][esr][ei]; - localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - rankOffset ); - GEOS_ASSERT_GE( localRow, 0 ); - GEOS_ASSERT_GT( localMatrix.numRows(), localRow + NC ); - - for( integer ic = 0; ic < NC; ++ic ) - { - RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[localRow + ic], localFlux[ic] ); - localMatrix.addToRow< parallelDeviceAtomic >( localRow + ic, - dofColIndices, - localFluxJacobian[ic], - NDOF ); - } - } - } ); -} - -#define INST_AquiferBCKernel( NC ) \ - template \ - void AquiferBCKernel:: \ - launch< NC >( integer const numPhases, \ - integer const ipWater, \ - bool const allowAllPhasesIntoAquifer, \ - integer const useTotalMassEquation, \ - BoundaryStencil const & stencil, \ - globalIndex const rankOffset, \ - ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, \ - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, \ - real64 const aquiferWaterPhaseDens, \ - arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, \ - ElementViewConst< arrayView1d< integer const > > const & ghostRank, \ - ElementViewConst< arrayView1d< real64 const > > const & pres, \ - ElementViewConst< arrayView1d< real64 const > > const & dPres, \ - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, \ - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, \ - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, \ - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, \ - ElementViewConst< arrayView3d< real64 const, multifluid::USD_PHASE > > const & phaseDens, \ - ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_DC > > const & dPhaseDens, \ - ElementViewConst< arrayView4d< real64 const, multifluid::USD_PHASE_COMP > > const & phaseCompFrac, \ - ElementViewConst< arrayView5d< real64 const, multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, \ - real64 const timeAtBeginningOfStep, \ - real64 const dt, \ - CRSMatrixView< real64, globalIndex const > const & localMatrix, \ - arrayView1d< real64 > const & localRhs ) - -INST_AquiferBCKernel( 1 ); -INST_AquiferBCKernel( 2 ); -INST_AquiferBCKernel( 3 ); -INST_AquiferBCKernel( 4 ); -INST_AquiferBCKernel( 5 ); - -#undef INST_AquiferBCKernel - } // namespace isothermalCompositionalMultiphaseFVMKernels } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp new file mode 100644 index 00000000000..e74a54d03fc --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp @@ -0,0 +1,203 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 CFLKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CFLKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CFLKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" +#include "constitutive/diffusion/DiffusionFields.hpp" +#include "constitutive/diffusion/DiffusionBase.hpp" +#include "constitutive/dispersion/DispersionFields.hpp" +#include "constitutive/dispersion/DispersionBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" +#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" +#include "constitutive/solid/porosity/PorosityBase.hpp" +#include "constitutive/solid/porosity/PorosityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** CFLFluxKernel ********************************/ + +/** + * @brief Functions to compute the (outflux) total volumetric flux needed in the calculation of CFL numbers + */ +struct CFLFluxKernel +{ + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + template< typename VIEWTYPE > + using ElementView = ElementRegionManager::ElementView< VIEWTYPE >; + + using CompFlowAccessors = + StencilAccessors< fields::flow::pressure, + fields::flow::gravityCoefficient, + fields::flow::phaseVolumeFraction, + fields::flow::phaseOutflux, + fields::flow::componentOutflux >; + + using MultiFluidAccessors = + StencilMaterialAccessors< constitutive::MultiFluidBase, + fields::multifluid::phaseViscosity, + fields::multifluid::phaseDensity, + fields::multifluid::phaseMassDensity, + fields::multifluid::phaseCompFraction >; + + using PermeabilityAccessors = + StencilMaterialAccessors< constitutive::PermeabilityBase, + fields::permeability::permeability, + fields::permeability::dPerm_dPressure >; + + + using RelPermAccessors = + StencilMaterialAccessors< constitutive::RelativePermeabilityBase, fields::relperm::phaseRelPerm >; + + template< integer NC, localIndex NUM_ELEMS, localIndex maxStencilSize > + GEOS_HOST_DEVICE + inline + static void + compute( integer const numPhases, + localIndex const stencilSize, + real64 const dt, + arraySlice1d< localIndex const > const seri, + arraySlice1d< localIndex const > const sesri, + arraySlice1d< localIndex const > const sei, + real64 const (&transmissibility)[2], + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, + ElementViewConst< arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > > const & phaseRelPerm, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseVisc, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseDens, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementView< arrayView2d< real64, compflow::USD_PHASE > > const & phaseOutflux, + ElementView< arrayView2d< real64, compflow::USD_COMP > > const & compOutflux ); + + template< integer NC, typename STENCILWRAPPER_TYPE > + static void + launch( integer const numPhases, + real64 const dt, + STENCILWRAPPER_TYPE const & stencil, + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, + ElementViewConst< arrayView3d< real64 const > > const & permeability, + ElementViewConst< arrayView3d< real64 const > > const & dPerm_dPres, + ElementViewConst< arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > > const & phaseRelPerm, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseVisc, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseDens, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementView< arrayView2d< real64, compflow::USD_PHASE > > const & phaseOutflux, + ElementView< arrayView2d< real64, compflow::USD_COMP > > const & compOutflux ); +}; + +/******************************** CFLKernel ********************************/ + +/** + * @brief Functions to compute the CFL number using the phase volumetric outflux and the component mass outflux in each cell + */ +struct CFLKernel +{ + + static constexpr real64 minPhaseMobility = 1e-12; + static constexpr real64 minComponentFraction = 1e-12; + + template< integer NP > + GEOS_HOST_DEVICE + inline + static void + computePhaseCFL( real64 const poreVol, + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac, + arraySlice1d< real64 const, constitutive::relperm::USD_RELPERM - 2 > phaseRelPerm, + arraySlice2d< real64 const, constitutive::relperm::USD_RELPERM_DS - 2 > dPhaseRelPerm_dPhaseVolFrac, + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseVisc, + arraySlice1d< real64 const, compflow::USD_PHASE- 1 > phaseOutflux, + real64 & phaseCFLNumber ); + + template< integer NC > + GEOS_HOST_DEVICE + inline + static void + computeCompCFL( real64 const poreVol, + arraySlice1d< real64 const, compflow::USD_COMP - 1 > compDens, + arraySlice1d< real64 const, compflow::USD_COMP - 1 > compFrac, + arraySlice1d< real64 const, compflow::USD_COMP - 1 > compOutflux, + real64 & compCFLNumber ); + + template< integer NC, integer NP > + static void + launch( localIndex const size, + arrayView1d< real64 const > const & volume, + arrayView2d< real64 const > const & porosity, + arrayView2d< real64 const, compflow::USD_COMP > const & compDens, + arrayView2d< real64 const, compflow::USD_COMP > const & compFrac, + arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac, + arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > const & phaseRelPerm, + arrayView4d< real64 const, constitutive::relperm::USD_RELPERM_DS > const & dPhaseRelPerm_dPhaseVolFrac, + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const & phaseVisc, + arrayView2d< real64 const, compflow::USD_PHASE > const & phaseOutflux, + arrayView2d< real64 const, compflow::USD_COMP > const & compOutflux, + arrayView1d< real64 > const & phaseCFLNumber, + arrayView1d< real64 > const & compCFLNumber, + real64 & maxPhaseCFLNumber, + real64 & maxCompCFLNumber ); + +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CFLKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp new file mode 100644 index 00000000000..a6c6dc84a5a --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp @@ -0,0 +1,793 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 DiffusionDispersionFluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" +#include "constitutive/diffusion/DiffusionFields.hpp" +#include "constitutive/diffusion/DiffusionBase.hpp" +#include "constitutive/dispersion/DispersionFields.hpp" +#include "constitutive/dispersion/DispersionBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" +#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" +#include "constitutive/solid/porosity/PorosityBase.hpp" +#include "constitutive/solid/porosity/PorosityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** DiffusionDispersionFluxComputeKernel ********************************/ + +/** + * @class DiffusionDispersionFluxComputeKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @brief Define the interface for the assembly kernel in charge of diffusion/dispersion flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > +class DiffusionDispersionFluxComputeKernel : public FluxComputeKernelBase +{ +public: + + /// Compile time value for the number of components + static constexpr integer numComp = NUM_COMP; + + /// Compute time value for the number of degrees of freedom + static constexpr integer numDof = NUM_DOF; + + /// Compute time value for the number of equations (all of them, except the volume balance equation) + static constexpr integer numEqn = NUM_DOF-1; + + /// Maximum number of elements at the face + static constexpr localIndex maxNumElems = STENCILWRAPPER::maxNumPointsInFlux; + + /// Maximum number of connections at the face + static constexpr localIndex maxNumConns = STENCILWRAPPER::maxNumConnections; + + /// Maximum number of points in the stencil + static constexpr localIndex maxStencilSize = STENCILWRAPPER::maxStencilSize; + + /// Number of flux support points (hard-coded for TFPA) + static constexpr integer numFluxSupportPoints = 2; + + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; + using AbstractBase::m_dPhaseVolFrac; + using AbstractBase::m_kernelFlags; + + using DiffusionAccessors = + StencilMaterialAccessors< constitutive::DiffusionBase, + fields::diffusion::diffusivity, + fields::diffusion::dDiffusivity_dTemperature, + fields::diffusion::phaseDiffusivityMultiplier >; + + using DispersionAccessors = + StencilMaterialAccessors< constitutive::DispersionBase, + fields::dispersion::dispersivity >; + + using PorosityAccessors = + StencilMaterialAccessors< constitutive::PorosityBase, + fields::porosity::referencePorosity >; + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dofNumberAccessor + * @param[in] compFlowAccessors + * @param[in] multiFluidAccessors + * @param[in] diffusionAccessors + * @param[in] dispersionAccessors + * @param[in] porosityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed together + */ + DiffusionDispersionFluxComputeKernel( integer const numPhases, + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + DiffusionAccessors const & diffusionAccessors, + DispersionAccessors const & dispersionAccessors, + PorosityAccessors const & porosityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) + : FluxComputeKernelBase( numPhases, + rankOffset, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), + m_phaseVolFrac( compFlowAccessors.get( fields::flow::phaseVolumeFraction {} ) ), + m_phaseDens( multiFluidAccessors.get( fields::multifluid::phaseDensity {} ) ), + m_dPhaseDens( multiFluidAccessors.get( fields::multifluid::dPhaseDensity {} ) ), + m_diffusivity( diffusionAccessors.get( fields::diffusion::diffusivity {} ) ), + m_dDiffusivity_dTemp( diffusionAccessors.get( fields::diffusion::dDiffusivity_dTemperature {} ) ), + m_phaseDiffusivityMultiplier( diffusionAccessors.get( fields::diffusion::phaseDiffusivityMultiplier {} ) ), + m_dispersivity( dispersionAccessors.get( fields::dispersion::dispersivity {} ) ), + m_referencePorosity( porosityAccessors.get( fields::porosity::referencePorosity {} ) ), + m_stencilWrapper( stencilWrapper ), + m_seri( stencilWrapper.getElementRegionIndices() ), + m_sesri( stencilWrapper.getElementSubRegionIndices() ), + m_sei( stencilWrapper.getElementIndices() ) + { } + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const size, localIndex numElems ) + : stencilSize( size ), + numConnectedElems( numElems ), + dofColIndices( size * numDof ), + localFlux( numElems * numEqn ), + localFluxJacobian( numElems * numEqn, size * numDof ) + {} + + // Stencil information + + /// Stencil size for a given connection + localIndex const stencilSize; + /// Number of elements connected at a given connection + localIndex const numConnectedElems; + + /// Transmissibility + real64 transmissibility[maxNumConns][numFluxSupportPoints]{}; + /// Derivatives of transmissibility with respect to pressure + real64 dTrans_dTemp[maxNumConns][numFluxSupportPoints]{}; + + // Local degrees of freedom and local residual/jacobian + + /// Indices of the matrix rows/columns corresponding to the dofs in this face + stackArray1d< globalIndex, maxNumElems * numDof > dofColIndices; + + /// Storage for the face local residual vector (all equations except volume balance) + stackArray1d< real64, maxNumElems * numEqn > localFlux; + /// Storage for the face local Jacobian matrix + stackArray2d< real64, maxNumElems * numEqn * maxStencilSize * numDof > localFluxJacobian; + }; + + + /** + * @brief Getter for the stencil size at this connection + * @param[in] iconn the connection index + * @return the size of the stencil at this connection + */ + GEOS_HOST_DEVICE + inline + localIndex stencilSize( localIndex const iconn ) const + { return m_sei[iconn].size(); } + + /** + * @brief Getter for the number of elements at this connection + * @param[in] iconn the connection index + * @return the number of elements at this connection + */ + GEOS_HOST_DEVICE + inline + localIndex numPointsInFlux( localIndex const iconn ) const + { return m_stencilWrapper.numPointsInFlux( iconn ); } + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] iconn the connection index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + inline + void setup( localIndex const iconn, + StackVariables & stack ) const + { + // set degrees of freedom indices for this face + for( integer i = 0; i < stack.stencilSize; ++i ) + { + globalIndex const offset = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + + for( integer jdof = 0; jdof < numDof; ++jdof ) + { + stack.dofColIndices[i * numDof + jdof] = offset + jdof; + } + } + } + + /** + * @brief Compute the local diffusion flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] diffusionFluxKernelOp the function used to customize the computation of the component fluxes + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + inline + void computeDiffusionFlux( localIndex const iconn, + StackVariables & stack, + FUNC && diffusionFluxKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + // first, compute the transmissibilities at this face + m_stencilWrapper.computeWeights( iconn, + m_diffusivity, + m_dDiffusivity_dTemp, + stack.transmissibility, + stack.dTrans_dTemp ); + + + localIndex k[numFluxSupportPoints]{}; + localIndex connectionIndex = 0; + for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) + { + for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) + { + /// cell indices + localIndex const seri[numFluxSupportPoints] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; + localIndex const sesri[numFluxSupportPoints] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; + localIndex const sei[numFluxSupportPoints] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; + + // clear working arrays + real64 diffusionFlux[numComp]{}; + real64 dDiffusionFlux_dP[numFluxSupportPoints][numComp]{}; + real64 dDiffusionFlux_dC[numFluxSupportPoints][numComp][numComp]{}; + real64 dDens_dC[numComp]{}; + + real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], + stack.transmissibility[connectionIndex][1] }; + + //***** calculation of flux ***** + // loop over phases, compute and upwind phase flux and sum contributions to each component's flux + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + + // loop over components + for( integer ic = 0; ic < numComp; ++ic ) + { + + real64 compFracGrad = 0.0; + real64 dCompFracGrad_dP[numFluxSupportPoints]{}; + real64 dCompFracGrad_dC[numFluxSupportPoints][numComp]{}; + + // compute the component fraction gradient using the diffusion transmissibility + computeCompFractionGradient( ip, ic, + seri, sesri, sei, + trans, + compFracGrad, + dCompFracGrad_dP, + dCompFracGrad_dC ); + + // choose upstream cell for composition upwinding + localIndex const k_up = (compFracGrad >= 0) ? 0 : 1; + + localIndex const er_up = seri[k_up]; + localIndex const esr_up = sesri[k_up]; + localIndex const ei_up = sei[k_up]; + + // computation of the upwinded mass flux + real64 const upwindCoefficient = + m_referencePorosity[er_up][esr_up][ei_up] * + m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * + m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_phaseVolFrac[er_up][esr_up][ei_up][ip]; + diffusionFlux[ic] += upwindCoefficient * compFracGrad; + + // add contributions of the derivatives of component fractions wrt pressure/component fractions + for( integer ke = 0; ke < numFluxSupportPoints; ke++ ) + { + dDiffusionFlux_dP[ke][ic] += upwindCoefficient * dCompFracGrad_dP[ke]; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDiffusionFlux_dC[ke][ic][jc] += upwindCoefficient * dCompFracGrad_dC[ke][jc]; + } + } + + // add contributions of the derivatives of upwind coefficient wrt pressure/component fractions + real64 const dUpwindCoefficient_dP = + m_referencePorosity[er_up][esr_up][ei_up] * + m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * + ( m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] * m_phaseVolFrac[er_up][esr_up][ei_up][ip] + + m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dP] ); + dDiffusionFlux_dP[k_up][ic] += dUpwindCoefficient_dP * compFracGrad; + + applyChainRule( numComp, + m_dCompFrac_dCompDens[er_up][esr_up][ei_up], + m_dPhaseDens[er_up][esr_up][ei_up][0][ip], + dDens_dC, + Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + real64 const dUpwindCoefficient_dC = + m_referencePorosity[er_up][esr_up][ei_up] * + m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * + ( dDens_dC[jc] * m_phaseVolFrac[er_up][esr_up][ei_up][ip] + + m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dC+jc] ); + dDiffusionFlux_dC[k_up][ic][jc] += dUpwindCoefficient_dC * compFracGrad; + } + + // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives + // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase + diffusionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex, + k_up, seri[k_up], sesri[k_up], sei[k_up], + compFracGrad, upwindCoefficient ); + + } // loop over components + } // loop over phases + + // add diffusion flux to local flux and local flux jacobian + addToLocalFluxAndJacobian( k, + stack, + diffusionFlux, + dDiffusionFlux_dP, + dDiffusionFlux_dC ); + + connectionIndex++; + } // loop over k[1] + } // loop over k[0] + } + + /** + * @brief Compute the local dispersion flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] dispersionFluxKernelOp the function used to customize the computation of the component fluxes + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + inline + void computeDispersionFlux( localIndex const iconn, + StackVariables & stack, + FUNC && dispersionFluxKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + // first, compute the transmissibilities at this face + // note that the dispersion tensor is lagged in iteration + m_stencilWrapper.computeWeights( iconn, + m_dispersivity, + m_dispersivity, // this is just to pass something, but the resulting derivative won't be used + stack.transmissibility, + stack.dTrans_dTemp ); // will not be used + + + localIndex k[numFluxSupportPoints]{}; + localIndex connectionIndex = 0; + for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) + { + for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) + { + /// cell indices + localIndex const seri[numFluxSupportPoints] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; + localIndex const sesri[numFluxSupportPoints] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; + localIndex const sei[numFluxSupportPoints] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; + + // clear working arrays + real64 dispersionFlux[numComp]{}; + real64 dDispersionFlux_dP[numFluxSupportPoints][numComp]{}; + real64 dDispersionFlux_dC[numFluxSupportPoints][numComp][numComp]{}; + real64 dDens_dC[numComp]{}; + + real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], + stack.transmissibility[connectionIndex][1] }; + + //***** calculation of flux ***** + // loop over phases, compute and upwind phase flux and sum contributions to each component's flux + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + + // loop over components + for( integer ic = 0; ic < numComp; ++ic ) + { + + real64 compFracGrad = 0.0; + real64 dCompFracGrad_dP[numFluxSupportPoints]{}; + real64 dCompFracGrad_dC[numFluxSupportPoints][numComp]{}; + + // compute the component fraction gradient using the dispersion transmissibility + computeCompFractionGradient( ip, ic, + seri, sesri, sei, + trans, + compFracGrad, + dCompFracGrad_dP, + dCompFracGrad_dC ); + + // choose upstream cell for composition upwinding + localIndex const k_up = (compFracGrad >= 0) ? 0 : 1; + + localIndex const er_up = seri[k_up]; + localIndex const esr_up = sesri[k_up]; + localIndex const ei_up = sei[k_up]; + + // computation of the upwinded mass flux + dispersionFlux[ic] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * compFracGrad; + + // add contributions of the derivatives of component fractions wrt pressure/component fractions + for( integer ke = 0; ke < numFluxSupportPoints; ke++ ) + { + dDispersionFlux_dP[ke][ic] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dP[ke]; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDispersionFlux_dC[ke][ic][jc] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dC[ke][jc]; + } + } + + // add contributions of the derivatives of upwind coefficient wrt pressure/component fractions + dDispersionFlux_dP[k_up][ic] += m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] * compFracGrad; + + applyChainRule( numComp, + m_dCompFrac_dCompDens[er_up][esr_up][ei_up], + m_dPhaseDens[er_up][esr_up][ei_up][0][ip], + dDens_dC, + Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + dDispersionFlux_dC[k_up][ic][jc] += dDens_dC[jc] * compFracGrad; + } + + // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives + // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase + dispersionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex, + k_up, seri[k_up], sesri[k_up], sei[k_up], + compFracGrad ); + + } // loop over components + } // loop over phases + + // add dispersion flux to local flux and local flux jacobian + addToLocalFluxAndJacobian( k, + stack, + dispersionFlux, + dDispersionFlux_dP, + dDispersionFlux_dC ); + + connectionIndex++; + } // loop over k[1] + } // loop over k[0] + } + + /** + * @brief Compute the component fraction gradient at this interface + * @param[in] ip the phase index + * @param[in] ic the component index + * @param[in] seri the region indices + * @param[in] sesri the subregion indices + * @param[in] sei the element indices + * @param[out] compFracGrad the component fraction gradient + * @param[out] dCompFracGrad_dP the derivatives of the component fraction gradient wrt pressure + * @param[out] dCompFracGrad_dC the derivatives of the component fraction gradient wrt component densities + */ + GEOS_HOST_DEVICE + inline + void computeCompFractionGradient( integer const ip, + integer const ic, + localIndex const (&seri)[numFluxSupportPoints], + localIndex const (&sesri)[numFluxSupportPoints], + localIndex const (&sei)[numFluxSupportPoints], + real64 const (&trans)[numFluxSupportPoints], + real64 & compFracGrad, + real64 (& dCompFracGrad_dP)[numFluxSupportPoints], + real64 (& dCompFracGrad_dC)[numFluxSupportPoints][numComp] ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + real64 dCompFrac_dC[numComp]{}; + + for( integer i = 0; i < numFluxSupportPoints; i++ ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + compFracGrad += trans[i] * m_phaseCompFrac[er][esr][ei][0][ip][ic]; + dCompFracGrad_dP[i] += trans[i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dP]; + + applyChainRule( numComp, + m_dCompFrac_dCompDens[er][esr][ei], + m_dPhaseCompFrac[er][esr][ei][0][ip][ic], + dCompFrac_dC, + Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + dCompFracGrad_dC[i][jc] += trans[i] * dCompFrac_dC[jc]; + } + } + } + + /** + * @brief Add the local diffusion/dispersion flux contributions to the residual and Jacobian + * @param[in] k the cell indices + * @param[in] stack the stack variables + * @param[in] flux the diffusion/dispersion flux + * @param[in] dFlux_dP the derivative of the diffusion/dispersion flux wrt pressure + * @param[in] dFlux_dC the derivative of the diffusion/dispersion flux wrt compositions + */ + GEOS_HOST_DEVICE + inline + void addToLocalFluxAndJacobian( localIndex const (&k)[numFluxSupportPoints], + StackVariables & stack, + real64 const (&flux)[numComp], + real64 const (&dFlux_dP)[numFluxSupportPoints][numComp], + real64 const (&dFlux_dC)[numFluxSupportPoints][numComp][numComp] ) const + { + // loop over components + for( integer ic = 0; ic < numComp; ++ic ) + { + // finally, increment local flux and local Jacobian + integer const eqIndex0 = k[0] * numEqn + ic; + integer const eqIndex1 = k[1] * numEqn + ic; + + stack.localFlux[eqIndex0] += m_dt * flux[ic]; + stack.localFlux[eqIndex1] -= m_dt * flux[ic]; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + localIndex const localDofIndexPres = k[ke] * numDof; + stack.localFluxJacobian[eqIndex0][localDofIndexPres] += m_dt * dFlux_dP[ke][ic]; + stack.localFluxJacobian[eqIndex1][localDofIndexPres] -= m_dt * dFlux_dP[ke][ic]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + localIndex const localDofIndexComp = localDofIndexPres + jc + 1; + stack.localFluxJacobian[eqIndex0][localDofIndexComp] += m_dt * dFlux_dC[ke][ic][jc]; + stack.localFluxJacobian[eqIndex1][localDofIndexComp] -= m_dt * dFlux_dC[ke][ic][jc]; + } + } + } + } + + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + inline + void complete( localIndex const iconn, + StackVariables & stack, + FUNC && assemblyKernelOp = NoOpFunc{} ) const + { + using namespace compositionalMultiphaseUtilities; + + if( m_kernelFlags.isSet( FluxComputeKernelFlags::TotalMassEquation ) ) + { + // Apply equation/variable change transformation(s) + stackArray1d< real64, maxStencilSize * numDof > work( stack.stencilSize * numDof ); + shiftBlockRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numEqn, numDof*stack.stencilSize, stack.numConnectedElems, + stack.localFluxJacobian, work ); + shiftBlockElementsAheadByOneAndReplaceFirstElementWithSum( numComp, numEqn, stack.numConnectedElems, + stack.localFlux ); + } + + // add contribution to residual and jacobian into: + // - the component mass balance equations (i = 0 to i = numComp-1) + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + for( integer i = 0; i < stack.numConnectedElems; ++i ) + { + if( m_ghostRank[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 ) + { + globalIndex const globalRow = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( m_localMatrix.numRows(), localRow + numComp ); + + for( integer ic = 0; ic < numComp; ++ic ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &m_localRhs[localRow + ic], stack.localFlux[i * numEqn + ic] ); + m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + ic, + stack.dofColIndices.data(), + stack.localFluxJacobian[i * numEqn + ic].dataIfContiguous(), + stack.stencilSize * numDof ); + } + + // call the lambda to assemble additional terms, such as thermal terms + assemblyKernelOp( i, localRow ); + } + } + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numConnections the number of connections + * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numConnections, + integer const hasDiffusion, + integer const hasDispersion, + KERNEL_TYPE const & kernelComponent ) + { + GEOS_MARK_FUNCTION; + forAll< POLICY >( numConnections, [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ), + kernelComponent.numPointsInFlux( iconn ) ); + + kernelComponent.setup( iconn, stack ); + if( hasDiffusion ) + { + kernelComponent.computeDiffusionFlux( iconn, stack ); + } + if( hasDispersion ) + { + kernelComponent.computeDispersionFlux( iconn, stack ); + } + kernelComponent.complete( iconn, stack ); + } ); + } + +protected: + + /// Views on phase volume fraction + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const m_phaseVolFrac; + + /// Views on phase densities + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseDens; + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseDens; + + /// Views on diffusivity + ElementViewConst< arrayView3d< real64 const > > const m_diffusivity; + ElementViewConst< arrayView3d< real64 const > > const m_dDiffusivity_dTemp; + ElementViewConst< arrayView3d< real64 const > > const m_phaseDiffusivityMultiplier; + + /// Views on dispersivity + ElementViewConst< arrayView3d< real64 const > > const m_dispersivity; + + /// View on the reference porosity + ElementViewConst< arrayView1d< real64 const > > const m_referencePorosity; + + // Stencil information + + /// Reference to the stencil wrapper + STENCILWRAPPER const m_stencilWrapper; + + /// Connection to element maps + typename STENCILWRAPPER::IndexContainerViewConstType const m_seri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sesri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sei; + +}; + +/** + * @class DiffusionDispersionFluxComputeKernelFactory + */ +class DiffusionDispersionFluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] hasDiffusion flag specifying whether diffusion is used or not + * @param[in] hasDispersion flag specifying whether dispersion is used or not + * @param[in] solverName the name of the solver + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename STENCILWRAPPER > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + string const & dofKey, + integer const hasDiffusion, + integer const hasDispersion, + integer const useTotalMassEquation, + string const & solverName, + ElementRegionManager const & elemManager, + STENCILWRAPPER const & stencilWrapper, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) + { + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 1; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + BitFlags< FluxComputeKernelFlags > kernelFlags; + if( useTotalMassEquation ) + kernelFlags.set( FluxComputeKernelFlags::TotalMassEquation ); + + using kernelType = DiffusionDispersionFluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename kernelType::DiffusionAccessors diffusionAccessors( elemManager, solverName ); + typename kernelType::DispersionAccessors dispersionAccessors( elemManager, solverName ); + typename kernelType::PorosityAccessors porosityAccessors( elemManager, solverName ); + + kernelType kernel( numPhases, rankOffset, stencilWrapper, + dofNumberAccessor, compFlowAccessors, multiFluidAccessors, + diffusionAccessors, dispersionAccessors, porosityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + kernelType::template launch< POLICY >( stencilWrapper.size(), + hasDiffusion, hasDispersion, + kernel ); + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp new file mode 100644 index 00000000000..8b84a977bd7 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp @@ -0,0 +1,577 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 DirichletFluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" +#include "constitutive/diffusion/DiffusionFields.hpp" +#include "constitutive/diffusion/DiffusionBase.hpp" +#include "constitutive/dispersion/DispersionFields.hpp" +#include "constitutive/dispersion/DispersionBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" +#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" +#include "constitutive/solid/porosity/PorosityBase.hpp" +#include "constitutive/solid/porosity/PorosityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** DirichletFluxComputeKernel ********************************/ + +/** + * @class DirichletFluxComputeKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam FLUIDWRAPPER the type of the fluid wrapper + * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename FLUIDWRAPPER > +class DirichletFluxComputeKernel : public FluxComputeKernel< NUM_COMP, + NUM_DOF, + BoundaryStencilWrapper > +{ +public: + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; + using DofNumberAccessor = AbstractBase::DofNumberAccessor; + using CompFlowAccessors = AbstractBase::CompFlowAccessors; + using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; + using CapPressureAccessors = AbstractBase::CapPressureAccessors; + using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; + + using AbstractBase::m_dt; + using AbstractBase::m_numPhases; + using AbstractBase::m_rankOffset; + using AbstractBase::m_dofNumber; + using AbstractBase::m_ghostRank; + using AbstractBase::m_gravCoef; + using AbstractBase::m_pres; + using AbstractBase::m_phaseCompFrac; + using AbstractBase::m_dPhaseCompFrac; + using AbstractBase::m_dCompFrac_dCompDens; + using AbstractBase::m_localMatrix; + using AbstractBase::m_localRhs; + using AbstractBase::m_kernelFlags; + + using Base = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, BoundaryStencilWrapper >; + using Base::numComp; + using Base::numDof; + using Base::numEqn; + using Base::m_stencilWrapper; + using Base::m_phaseMob; + using Base::m_dPhaseMob; + using Base::m_phaseMassDens; + using Base::m_dPhaseMassDens; + using Base::m_permeability; + using Base::m_dPerm_dPres; + using Base::m_seri; + using Base::m_sesri; + using Base::m_sei; + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] faceManager the face manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] fluidWrapper reference to the fluid wrapper + * @param[in] dofNumberAccessor + * @param[in] compFlowAccessors + * @param[in] multiFluidAccessors + * @param[in] capPressureAccessors + * @param[in] permeabilityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed together + */ + DirichletFluxComputeKernel( integer const numPhases, + globalIndex const rankOffset, + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) + : Base( numPhases, + rankOffset, + stencilWrapper, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + capPressureAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), + m_facePres( faceManager.getField< fields::flow::facePressure >() ), + m_faceTemp( faceManager.getField< fields::flow::faceTemperature >() ), + m_faceCompFrac( faceManager.getField< fields::flow::faceGlobalCompFraction >() ), + m_faceGravCoef( faceManager.getField< fields::flow::gravityCoefficient >() ), + m_fluidWrapper( fluidWrapper ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const GEOS_UNUSED_PARAM( size ), + localIndex GEOS_UNUSED_PARAM( numElems )) {} + + // Transmissibility + real64 transmissibility = 0.0; + + // Component fluxes and derivatives + + /// Component fluxes + real64 compFlux[numComp]{}; + /// Derivatives of component fluxes wrt pressure + real64 dCompFlux_dP[numComp]{}; + /// Derivatives of component fluxes wrt component densities + real64 dCompFlux_dC[numComp][numComp]{}; + + // Local degrees of freedom and local residual/jacobian + + /// Indices of the matrix rows/columns corresponding to the dofs in this face + globalIndex dofColIndices[numDof]{}; + + /// Storage for the face local residual vector + real64 localFlux[numEqn]{}; + /// Storage for the face local Jacobian matrix + real64 localFluxJacobian[numEqn][numDof]{}; + + }; + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] iconn the connection index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const iconn, + StackVariables & stack ) const + { + globalIndex const offset = + m_dofNumber[m_seri( iconn, BoundaryStencil::Order::ELEM )][m_sesri( iconn, BoundaryStencil::Order::ELEM )][m_sei( iconn, BoundaryStencil::Order::ELEM )]; + + for( integer jdof = 0; jdof < numDof; ++jdof ) + { + stack.dofColIndices[jdof] = offset + jdof; + } + } + + + /** + * @brief Compute the local Dirichlet face flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeFlux( localIndex const iconn, + StackVariables & stack, + FUNC && compFluxKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + using Order = BoundaryStencil::Order; + + localIndex const er = m_seri( iconn, Order::ELEM ); + localIndex const esr = m_sesri( iconn, Order::ELEM ); + localIndex const ei = m_sei( iconn, Order::ELEM ); + localIndex const kf = m_sei( iconn, Order::FACE ); + + // Step 1: compute the transmissibility at the boundary face + + real64 dTrans_dPerm[3]{}; + m_stencilWrapper.computeWeights( iconn, + m_permeability, + stack.transmissibility, + dTrans_dPerm ); + real64 const dTrans_dPres = LvArray::tensorOps::AiBi< 3 >( dTrans_dPerm, m_dPerm_dPres[er][esr][ei][0] ); + + // Step 2: compute the fluid properties on the face + // This is needed to get the phase mass density and the phase comp fraction at the face + // Because we approximate the face mobility using the total element mobility + + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseFrac( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseDens( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseMassDens( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseVisc( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseEnthalpy( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseInternalEnergy( 1, 1, m_numPhases ); + StackArray< real64, 4, constitutive::MultiFluidBase::MAX_NUM_PHASES * NUM_COMP, + constitutive::multifluid::LAYOUT_PHASE_COMP > facePhaseCompFrac( 1, 1, m_numPhases, NUM_COMP ); + real64 faceTotalDens = 0.0; + + constitutive::MultiFluidBase::KernelWrapper::computeValues( m_fluidWrapper, + m_facePres[kf], + m_faceTemp[kf], + m_faceCompFrac[kf], + facePhaseFrac[0][0], + facePhaseDens[0][0], + facePhaseMassDens[0][0], + facePhaseVisc[0][0], + facePhaseEnthalpy[0][0], + facePhaseInternalEnergy[0][0], + facePhaseCompFrac[0][0], + faceTotalDens ); + + // Step 3: loop over phases, compute and upwind phase flux and sum contributions to each component's flux + + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + + // working variables + real64 dDensMean_dC[numComp]{}; + real64 dF_dC[numComp]{}; + real64 dProp_dC[numComp]{}; + + real64 phaseFlux = 0.0; // for the lambda + real64 dPhaseFlux_dP = 0.0; + real64 dPhaseFlux_dC[numComp]{}; + + + // Step 3.1: compute the average phase mass density at the face + + applyChainRule( numComp, + m_dCompFrac_dCompDens[er][esr][ei], + m_dPhaseMassDens[er][esr][ei][0][ip], + dProp_dC, + Deriv::dC ); + + // average density and derivatives + real64 const densMean = 0.5 * ( m_phaseMassDens[er][esr][ei][0][ip] + facePhaseMassDens[0][0][ip] ); + real64 const dDensMean_dP = 0.5 * m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDensMean_dC[jc] = 0.5 * dProp_dC[jc]; + } + + + // Step 3.2: compute the (TPFA) potential difference at the face + + real64 const gravTimesDz = m_gravCoef[er][esr][ei] - m_faceGravCoef[kf]; + real64 const potDif = m_pres[er][esr][ei] - m_facePres[kf] - densMean * gravTimesDz; + real64 const f = stack.transmissibility * potDif; + real64 const dF_dP = stack.transmissibility * ( 1.0 - dDensMean_dP * gravTimesDz ) + dTrans_dPres * potDif; + for( integer jc = 0; jc < numComp; ++jc ) + { + dF_dC[jc] = -stack.transmissibility * dDensMean_dC[jc] * gravTimesDz; + } + + // Step 3.3: computation of the mobility + // We do that before the if/else statement to be able to pass it to the compFluxOpKernel + + // recomputing the exact mobility at the face would be quite complex, as it would require: + // 1) computing the saturation + // 2) computing the relperm + // 3) computing the mobility as \lambda_p = \rho_p kr_p( S_p ) / \mu_p + // the second step in particular would require yet another dispatch to get the relperm model + // so, for simplicity, we approximate the face mobility as + // \lambda^approx_p = \rho_p S_p / \mu_p + // = \rho_p ( (nu_p / rho_p) * rho_t ) / \mu_p (plugging the expression of saturation) + // = \nu_p * rho_t / \mu_p + // fortunately, we don't need the derivatives + real64 const facePhaseMob = ( facePhaseFrac[0][0][ip] > 0.0 ) + ? facePhaseFrac[0][0][ip] * faceTotalDens / facePhaseVisc[0][0][ip] + : 0.0; + + // *** upwinding *** + // Step 3.4: upwinding based on the sign of the phase potential gradient + // It is easier to hard-code the if/else because it is difficult to address elem and face variables in a uniform way + + if( potDif >= 0 ) // the element is upstream + { + + // compute the phase flux and derivatives using the element mobility + phaseFlux = m_phaseMob[er][esr][ei][ip] * f; + dPhaseFlux_dP = m_phaseMob[er][esr][ei][ip] * dF_dP + m_dPhaseMob[er][esr][ei][ip][Deriv::dP] * f; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[jc] = + m_phaseMob[er][esr][ei][ip] * dF_dC[jc] + m_dPhaseMob[er][esr][ei][ip][Deriv::dC+jc] * f; + } + + // slice some constitutive arrays to avoid too much indexing in component loop + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub = + m_phaseCompFrac[er][esr][ei][0][ip]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub = + m_dPhaseCompFrac[er][esr][ei][0][ip]; + + // compute component fluxes and derivatives using element composition + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = phaseCompFracSub[ic]; + stack.compFlux[ic] += phaseFlux * ycp; + stack.dCompFlux_dP[ic] += dPhaseFlux_dP * ycp + phaseFlux * dPhaseCompFracSub[ic][Deriv::dP]; + + applyChainRule( numComp, + m_dCompFrac_dCompDens[er][esr][ei], + dPhaseCompFracSub[ic], + dProp_dC, + Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.dCompFlux_dC[ic][jc] += dPhaseFlux_dC[jc] * ycp + phaseFlux * dProp_dC[jc]; + } + } + + } + else // the face is upstream + { + + // compute the phase flux and derivatives using the approximated face mobility + // we only have to take derivatives of the potential gradient in this case + phaseFlux = facePhaseMob * f; + dPhaseFlux_dP = facePhaseMob * dF_dP; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[jc] = facePhaseMob * dF_dC[jc]; + } + + // compute component fluxes and derivatives using the face composition + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = facePhaseCompFrac[0][0][ip][ic]; + stack.compFlux[ic] += phaseFlux * ycp; + stack.dCompFlux_dP[ic] += dPhaseFlux_dP * ycp; + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.dCompFlux_dC[ic][jc] += dPhaseFlux_dC[jc] * ycp; + } + } + } + + // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives + // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase + compFluxKernelOp( ip, er, esr, ei, kf, f, + facePhaseMob, facePhaseEnthalpy[0][0], facePhaseCompFrac[0][0], + phaseFlux, dPhaseFlux_dP, dPhaseFlux_dC ); + + } + + // *** end of upwinding + + // Step 4: populate local flux vector and derivatives + for( integer ic = 0; ic < numComp; ++ic ) + { + stack.localFlux[ic] = m_dt * stack.compFlux[ic]; + stack.localFluxJacobian[ic][0] = m_dt * stack.dCompFlux_dP[ic]; + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.localFluxJacobian[ic][jc+1] = m_dt * stack.dCompFlux_dC[ic][jc]; + } + } + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void complete( localIndex const iconn, + StackVariables & stack, + FUNC && assemblyKernelOp = NoOpFunc{} ) const + { + using namespace compositionalMultiphaseUtilities; + using Order = BoundaryStencil::Order; + + if( AbstractBase::m_kernelFlags.isSet( FluxComputeKernelFlags::TotalMassEquation ) ) + { + // Apply equation/variable change transformation(s) + real64 work[numDof]{}; + shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numDof, stack.localFluxJacobian, work ); + shiftElementsAheadByOneAndReplaceFirstElementWithSum( numComp, stack.localFlux ); + } + + // add contribution to residual and jacobian into: + // - the component mass balance equations (i = 0 to i = numComp-1) + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + if( m_ghostRank[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )] < 0 ) + { + globalIndex const globalRow = m_dofNumber[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( AbstractBase::m_localMatrix.numRows(), localRow + numComp ); + + for( integer ic = 0; ic < numComp; ++ic ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + ic], stack.localFlux[ic] ); + AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + ic, + stack.dofColIndices, + stack.localFluxJacobian[ic], + numDof ); + } + + // call the lambda to assemble additional terms, such as thermal terms + assemblyKernelOp( localRow ); + } + } + +protected: + + /// Views on face pressure, temperature, and composition + arrayView1d< real64 const > const m_facePres; + arrayView1d< real64 const > const m_faceTemp; + arrayView2d< real64 const, compflow::USD_COMP > const m_faceCompFrac; + + /// View on the face gravity coefficient + arrayView1d< real64 const > const m_faceGravCoef; + + /// Reference to the fluid wrapper + FLUIDWRAPPER const m_fluidWrapper; + +}; + + +/** + * @class DirichletFluxComputeKernelFactory + */ +class DirichletFluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] solverName name of the solver (to name accessors) + * @param[in] faceManager reference to the face manager + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the boundary stencil wrapper + * @param[in] fluidBase the multifluid constitutive model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + integer const useTotalMassEquation, + string const & dofKey, + string const & solverName, + FaceManager const & faceManager, + ElementRegionManager const & elemManager, + BoundaryStencilWrapper const & stencilWrapper, + constitutive::MultiFluidBase & fluidBase, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + constitutive::constitutiveComponentUpdatePassThru( fluidBase, numComps, [&]( auto & fluid, auto NC ) + { + using FluidType = TYPEOFREF( fluid ); + typename FluidType::KernelWrapper const fluidWrapper = fluid.createKernelWrapper(); + + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 1; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + // for now, we neglect capillary pressure in the kernel + BitFlags< FluxComputeKernelFlags > kernelFlags; + if( useTotalMassEquation ) + kernelFlags.set( FluxComputeKernelFlags::TotalMassEquation ); + + using kernelType = DirichletFluxComputeKernel< NUM_COMP, NUM_DOF, typename FluidType::KernelWrapper >; + typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename kernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); + typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + + kernelType kernel( numPhases, rankOffset, faceManager, stencilWrapper, fluidWrapper, + dofNumberAccessor, compFlowAccessors, multiFluidAccessors, capPressureAccessors, permeabilityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp similarity index 92% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp index 7a316a92355..fc597c9cda0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp @@ -14,13 +14,13 @@ */ /** - * @file DissipationCompositionalMultiphaseFVMKernels.hpp + * @file DissipationFluxComputeKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_DISSIPATIONCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_DISSIPATIONCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DISSIPATIONFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DISSIPATIONFLUXCOMPUTEKERNEL_HPP -#include "IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp" #include "constitutive/solid/porosity/PorosityBase.hpp" #include "constitutive/solid/porosity/PorosityFields.hpp" @@ -34,17 +34,17 @@ static constexpr integer newtonContinuationCutoffIteration = 5; static constexpr real64 initialDirectionalCoef = 100; static constexpr real64 multiplierDirectionalCoef = 1000; -/******************************** FaceBasedAssemblyKernel ********************************/ +/******************************** FluxComputeKernel ********************************/ /** - * @class FaceBasedAssemblyKernel + * @class FluxComputeKernel * @tparam NUM_COMP number of fluid components * @tparam NUM_DOF number of degrees of freedom * @tparam STENCILWRAPPER the type of the stencil wrapper * @brief Define the interface for the assembly kernel in charge of flux terms */ template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > +class FluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > { public: @@ -57,7 +57,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelBase; + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = AbstractBase::DofNumberAccessor; using CompFlowAccessors = AbstractBase::CompFlowAccessors; using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; @@ -68,7 +68,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne using AbstractBase::m_gravCoef; using AbstractBase::m_dCompFrac_dCompDens; - using Base = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + using Base = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; using Base::numComp; using Base::numDof; using Base::numEqn; @@ -110,7 +110,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne * @param[in] kappamin minimum value for kappa coefficient in DBC * @param[in] contMultiplier continuation multiplier factor (should be < 1) */ - FaceBasedAssemblyKernel( integer const numPhases, + FluxComputeKernel( integer const numPhases, globalIndex const rankOffset, STENCILWRAPPER const & stencilWrapper, DofNumberAccessor const & dofNumberAccessor, @@ -123,7 +123,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne real64 const & dt, CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags, real64 const omega, integer const curNewton, integer const continuation, @@ -319,9 +319,9 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne }; /** - * @class FaceBasedAssemblyKernelFactory + * @class FluxComputeKernelFactory */ -class FaceBasedAssemblyKernelFactory +class FluxComputeKernelFactory { public: @@ -372,13 +372,13 @@ class FaceBasedAssemblyKernelFactory elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags; + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags; if( hasCapPressure ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::CapPressure ); + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::CapPressure ); if( useTotalMassEquation ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::TotalMassEquation ); + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::TotalMassEquation ); - using KERNEL_TYPE = FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + using KERNEL_TYPE = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; typename KERNEL_TYPE::CompFlowAccessors compFlowAccessors( elemManager, solverName ); typename KERNEL_TYPE::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); typename KERNEL_TYPE::CapPressureAccessors capPressureAccessors( elemManager, solverName ); @@ -399,4 +399,4 @@ class FaceBasedAssemblyKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_DISSIPATIONCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DISSIPATIONFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp new file mode 100644 index 00000000000..6d550ddd22a --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp @@ -0,0 +1,594 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp" + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" +#include "constitutive/diffusion/DiffusionFields.hpp" +#include "constitutive/diffusion/DiffusionBase.hpp" +#include "constitutive/dispersion/DispersionFields.hpp" +#include "constitutive/dispersion/DispersionBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" +#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" +#include "constitutive/solid/porosity/PorosityBase.hpp" +#include "constitutive/solid/porosity/PorosityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/** + * @class FluxComputeKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @brief Define the interface for the assembly kernel in charge of flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > +class FluxComputeKernel : public FluxComputeKernelBase +{ +public: + + /// Compile time value for the number of components + static constexpr integer numComp = NUM_COMP; + + /// Compute time value for the number of degrees of freedom + static constexpr integer numDof = NUM_DOF; + + /// Compute time value for the number of equations (all of them, except the volume balance equation) + static constexpr integer numEqn = NUM_DOF-1; + + /// Maximum number of elements at the face + static constexpr localIndex maxNumElems = STENCILWRAPPER::maxNumPointsInFlux; + + /// Maximum number of connections at the face + static constexpr localIndex maxNumConns = STENCILWRAPPER::maxNumConnections; + + /// Maximum number of points in the stencil + static constexpr localIndex maxStencilSize = STENCILWRAPPER::maxStencilSize; + + /// Number of flux support points (hard-coded for TFPA) + static constexpr integer numFluxSupportPoints = 2; + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dofNumberAccessor + * @param[in] compFlowAccessors + * @param[in] multiFluidAccessors + * @param[in] capPressureAccessors + * @param[in] permeabilityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed together + */ + FluxComputeKernel( integer const numPhases, + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) + : FluxComputeKernelBase( numPhases, + rankOffset, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), + m_permeability( permeabilityAccessors.get( fields::permeability::permeability {} ) ), + m_dPerm_dPres( permeabilityAccessors.get( fields::permeability::dPerm_dPressure {} ) ), + m_phaseMob( compFlowAccessors.get( fields::flow::phaseMobility {} ) ), + m_dPhaseMob( compFlowAccessors.get( fields::flow::dPhaseMobility {} ) ), + m_phaseMassDens( multiFluidAccessors.get( fields::multifluid::phaseMassDensity {} ) ), + m_dPhaseMassDens( multiFluidAccessors.get( fields::multifluid::dPhaseMassDensity {} ) ), + m_phaseCapPressure( capPressureAccessors.get( fields::cappres::phaseCapPressure {} ) ), + m_dPhaseCapPressure_dPhaseVolFrac( capPressureAccessors.get( fields::cappres::dPhaseCapPressure_dPhaseVolFraction {} ) ), + m_stencilWrapper( stencilWrapper ), + m_seri( stencilWrapper.getElementRegionIndices() ), + m_sesri( stencilWrapper.getElementSubRegionIndices() ), + m_sei( stencilWrapper.getElementIndices() ) + { } + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const size, localIndex numElems ) + : stencilSize( size ), + numConnectedElems( numElems ), + dofColIndices( size * numDof ), + localFlux( numElems * numEqn ), + localFluxJacobian( numElems * numEqn, size * numDof ) + {} + + // Stencil information + + /// Stencil size for a given connection + localIndex const stencilSize; + /// Number of elements connected at a given connection + localIndex const numConnectedElems; + + // Transmissibility and derivatives + + /// Transmissibility + real64 transmissibility[maxNumConns][numFluxSupportPoints]{}; + /// Derivatives of transmissibility with respect to pressure + real64 dTrans_dPres[maxNumConns][numFluxSupportPoints]{}; + + // Local degrees of freedom and local residual/jacobian + + /// Indices of the matrix rows/columns corresponding to the dofs in this face + stackArray1d< globalIndex, maxNumElems * numDof > dofColIndices; + + /// Storage for the face local residual vector (all equations except volume balance) + stackArray1d< real64, maxNumElems * numEqn > localFlux; + /// Storage for the face local Jacobian matrix + stackArray2d< real64, maxNumElems * numEqn * maxStencilSize * numDof > localFluxJacobian; + }; + + + /** + * @brief Getter for the stencil size at this connection + * @param[in] iconn the connection index + * @return the size of the stencil at this connection + */ + GEOS_HOST_DEVICE + inline + localIndex stencilSize( localIndex const iconn ) const { return m_sei[iconn].size(); } + + /** + * @brief Getter for the number of elements at this connection + * @param[in] iconn the connection index + * @return the number of elements at this connection + */ + GEOS_HOST_DEVICE + inline + localIndex numPointsInFlux( localIndex const iconn ) const { return m_stencilWrapper.numPointsInFlux( iconn ); } + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] iconn the connection index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + inline + void setup( localIndex const iconn, + StackVariables & stack ) const + { + // set degrees of freedom indices for this face + for( integer i = 0; i < stack.stencilSize; ++i ) + { + globalIndex const offset = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + + for( integer jdof = 0; jdof < numDof; ++jdof ) + { + stack.dofColIndices[i * numDof + jdof] = offset + jdof; + } + } + } + + /** + * @brief Compute the local flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + inline + void computeFlux( localIndex const iconn, + StackVariables & stack, + FUNC && compFluxKernelOp = NoOpFunc{} ) const + { + + // first, compute the transmissibilities at this face + m_stencilWrapper.computeWeights( iconn, + m_permeability, + m_dPerm_dPres, + stack.transmissibility, + stack.dTrans_dPres ); + + + localIndex k[numFluxSupportPoints]; + localIndex connectionIndex = 0; + for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) + { + for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) + { + /// cell indices + localIndex const seri[numFluxSupportPoints] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; + localIndex const sesri[numFluxSupportPoints] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; + localIndex const sei[numFluxSupportPoints] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; + + // clear working arrays + real64 compFlux[numComp]{}; + real64 dCompFlux_dP[numFluxSupportPoints][numComp]{}; + real64 dCompFlux_dC[numFluxSupportPoints][numComp][numComp]{}; + + real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], + stack.transmissibility[connectionIndex][1] }; + + real64 const dTrans_dPres[numFluxSupportPoints] = { stack.dTrans_dPres[connectionIndex][0], + stack.dTrans_dPres[connectionIndex][1] }; + + //***** calculation of flux ***** + // loop over phases, compute and upwind phase flux and sum contributions to each component's flux + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + // create local work arrays + real64 potGrad = 0.0; + real64 phaseFlux = 0.0; + real64 dPhaseFlux_dP[numFluxSupportPoints]{}; + real64 dPhaseFlux_dC[numFluxSupportPoints][numComp]{}; + + localIndex k_up = -1; + + if( m_kernelFlags.isSet( FluxComputeKernelFlags::C1PPU ) ) + { + isothermalCompositionalMultiphaseFVMKernelUtilities::C1PPUPhaseFlux::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_dCompFrac_dCompDens, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + else if( m_kernelFlags.isSet( FluxComputeKernelFlags::IHU ) ) + { + isothermalCompositionalMultiphaseFVMKernelUtilities::IHUPhaseFlux::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_dCompFrac_dCompDens, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + else + { + isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFlux::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_dCompFrac_dCompDens, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + + // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives + // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase + compFluxKernelOp( ip, k, seri, sesri, sei, connectionIndex, + k_up, seri[k_up], sesri[k_up], sei[k_up], potGrad, + phaseFlux, dPhaseFlux_dP, dPhaseFlux_dC ); + + } // loop over phases + + /// populate local flux vector and derivatives + for( integer ic = 0; ic < numComp; ++ic ) + { + integer const eqIndex0 = k[0] * numEqn + ic; + integer const eqIndex1 = k[1] * numEqn + ic; + + stack.localFlux[eqIndex0] += m_dt * compFlux[ic]; + stack.localFlux[eqIndex1] -= m_dt * compFlux[ic]; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + localIndex const localDofIndexPres = k[ke] * numDof; + stack.localFluxJacobian[eqIndex0][localDofIndexPres] += m_dt * dCompFlux_dP[ke][ic]; + stack.localFluxJacobian[eqIndex1][localDofIndexPres] -= m_dt * dCompFlux_dP[ke][ic]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + localIndex const localDofIndexComp = localDofIndexPres + jc + 1; + stack.localFluxJacobian[eqIndex0][localDofIndexComp] += m_dt * dCompFlux_dC[ke][ic][jc]; + stack.localFluxJacobian[eqIndex1][localDofIndexComp] -= m_dt * dCompFlux_dC[ke][ic][jc]; + } + } + } + connectionIndex++; + } // loop over k[1] + } // loop over k[0] + + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + inline + void complete( localIndex const iconn, + StackVariables & stack, + FUNC && assemblyKernelOp = NoOpFunc{} ) const + { + using namespace compositionalMultiphaseUtilities; + + if( m_kernelFlags.isSet( FluxComputeKernelFlags::TotalMassEquation ) ) + { + // Apply equation/variable change transformation(s) + stackArray1d< real64, maxStencilSize * numDof > work( stack.stencilSize * numDof ); + shiftBlockRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numEqn, numDof * stack.stencilSize, stack.numConnectedElems, + stack.localFluxJacobian, work ); + shiftBlockElementsAheadByOneAndReplaceFirstElementWithSum( numComp, numEqn, stack.numConnectedElems, + stack.localFlux ); + } + + // add contribution to residual and jacobian into: + // - the component mass balance equations (i = 0 to i = numComp-1) + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + for( integer i = 0; i < stack.numConnectedElems; ++i ) + { + if( m_ghostRank[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 ) + { + globalIndex const globalRow = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( m_localMatrix.numRows(), localRow + numComp ); + + for( integer ic = 0; ic < numComp; ++ic ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &m_localRhs[localRow + ic], + stack.localFlux[i * numEqn + ic] ); + m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + ic, + stack.dofColIndices.data(), + stack.localFluxJacobian[i * numEqn + ic].dataIfContiguous(), + stack.stencilSize * numDof ); + } + + // call the lambda to assemble additional terms, such as thermal terms + assemblyKernelOp( i, localRow ); + } + } + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numConnections the number of connections + * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numConnections, + KERNEL_TYPE const & kernelComponent ) + { + GEOS_MARK_FUNCTION; + forAll< POLICY >( numConnections, [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ), + kernelComponent.numPointsInFlux( iconn ) ); + + kernelComponent.setup( iconn, stack ); + kernelComponent.computeFlux( iconn, stack ); + kernelComponent.complete( iconn, stack ); + } ); + } + +protected: + + /// Views on permeability + ElementViewConst< arrayView3d< real64 const > > const m_permeability; + ElementViewConst< arrayView3d< real64 const > > const m_dPerm_dPres; + + /// Views on phase mobilities + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const m_phaseMob; + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const m_dPhaseMob; + + /// Views on phase mass densities + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseMassDens; + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseMassDens; + + /// Views on phase capillary pressure + ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const m_phaseCapPressure; + ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const m_dPhaseCapPressure_dPhaseVolFrac; + + // Stencil information + + /// Reference to the stencil wrapper + STENCILWRAPPER const m_stencilWrapper; + + /// Connection to element maps + typename STENCILWRAPPER::IndexContainerViewConstType const m_seri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sesri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sei; + +}; + +/** + * @class FluxComputeKernelFactory + */ +class FluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] hasCapPressure flag specifying whether capillary pressure is used or not + * @param[in] solverName name of the solver (to name accessors) + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename STENCILWRAPPER > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + string const & dofKey, + integer const hasCapPressure, + integer const useTotalMassEquation, + UpwindingParameters upwindingParams, + string const & solverName, + ElementRegionManager const & elemManager, + STENCILWRAPPER const & stencilWrapper, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) + { + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 1; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + BitFlags< FluxComputeKernelFlags > kernelFlags; + if( hasCapPressure ) + kernelFlags.set( FluxComputeKernelFlags::CapPressure ); + if( useTotalMassEquation ) + kernelFlags.set( FluxComputeKernelFlags::TotalMassEquation ); + if( upwindingParams.upwindingScheme == UpwindingScheme::C1PPU && + isothermalCompositionalMultiphaseFVMKernelUtilities::epsC1PPU > 0 ) + kernelFlags.set( FluxComputeKernelFlags::C1PPU ); + else if( upwindingParams.upwindingScheme == UpwindingScheme::IHU ) + kernelFlags.set( FluxComputeKernelFlags::IHU ); + + + using kernelType = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename kernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); + typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + + kernelType kernel( numPhases, rankOffset, stencilWrapper, dofNumberAccessor, + compFlowAccessors, multiFluidAccessors, capPressureAccessors, permeabilityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp new file mode 100644 index 00000000000..a28e0f93864 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp @@ -0,0 +1,65 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluxComputeKernelBase.cpp + */ + +#include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" + +#include "finiteVolume/CellElementStencilTPFA.hpp" +#include "finiteVolume/SurfaceElementStencil.hpp" +#include "finiteVolume/EmbeddedSurfaceToCellStencil.hpp" +#include "finiteVolume/FaceElementToCellStencil.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" + +namespace geos +{ +using namespace constitutive; + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** FluxComputeKernelBase ********************************/ + +FluxComputeKernelBase::FluxComputeKernelBase( integer const numPhases, + globalIndex const rankOffset, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) + : m_numPhases( numPhases ), + m_rankOffset( rankOffset ), + m_dt( dt ), + m_dofNumber( dofNumberAccessor.toNestedViewConst() ), + m_ghostRank( compFlowAccessors.get( fields::ghostRank {} ) ), + m_gravCoef( compFlowAccessors.get( fields::flow::gravityCoefficient {} ) ), + m_pres( compFlowAccessors.get( fields::flow::pressure {} ) ), + m_dCompFrac_dCompDens( compFlowAccessors.get( fields::flow::dGlobalCompFraction_dGlobalCompDensity {} ) ), + m_dPhaseVolFrac( compFlowAccessors.get( fields::flow::dPhaseVolumeFraction {} ) ), + m_phaseCompFrac( multiFluidAccessors.get( fields::multifluid::phaseCompFraction {} ) ), + m_dPhaseCompFrac( multiFluidAccessors.get( fields::multifluid::dPhaseCompFraction {} ) ), + m_localMatrix( localMatrix ), + m_localRhs( localRhs ), + m_kernelFlags( kernelFlags ) +{} + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp new file mode 100644 index 00000000000..2c6f7083162 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp @@ -0,0 +1,196 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluxComputeKernelBase.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNELBASE_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNELBASE_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" +#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" +#include "constitutive/diffusion/DiffusionFields.hpp" +#include "constitutive/diffusion/DiffusionBase.hpp" +#include "constitutive/dispersion/DispersionFields.hpp" +#include "constitutive/dispersion/DispersionBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" +#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "constitutive/permeability/PermeabilityBase.hpp" +#include "constitutive/permeability/PermeabilityFields.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" +#include "constitutive/solid/porosity/PorosityBase.hpp" +#include "constitutive/solid/porosity/PorosityFields.hpp" +#include "fieldSpecification/AquiferBoundaryCondition.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "mesh/utilities/MeshMapUtilities.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +enum class FluxComputeKernelFlags +{ + /// Flag to specify whether capillary pressure is used or not + CapPressure = 1 << 0, // 1 + /// Flag indicating whether total mass equation is formed or not + TotalMassEquation = 1 << 1, // 2 + /// Flag indicating whether C1-PPU is used or not + C1PPU = 1 << 2, // 4 + /// Flag indicating whether IHU is used or not + IHU = 1 << 3 // 8 + /// Add more flags like that if needed: + // Flag5 = 1 << 4, // 16 + // Flag6 = 1 << 5, // 32 + // Flag7 = 1 << 6, // 64 + // Flag8 = 1 << 7 //128 +}; + +/******************************** FluxComputeKernelBase ********************************/ + +/** + * @brief Base class for FluxComputeKernel that holds all data not dependent + * on template parameters (like stencil type and number of components/dofs). + */ +class FluxComputeKernelBase +{ +public: + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using DofNumberAccessor = ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > >; + + using CompFlowAccessors = + StencilAccessors< fields::ghostRank, + fields::flow::gravityCoefficient, + fields::flow::pressure, + fields::flow::dGlobalCompFraction_dGlobalCompDensity, + fields::flow::phaseVolumeFraction, + fields::flow::dPhaseVolumeFraction, + fields::flow::phaseMobility, + fields::flow::dPhaseMobility >; + using MultiFluidAccessors = + StencilMaterialAccessors< constitutive::MultiFluidBase, + fields::multifluid::phaseDensity, + fields::multifluid::dPhaseDensity, + fields::multifluid::phaseMassDensity, + fields::multifluid::dPhaseMassDensity, + fields::multifluid::phaseCompFraction, + fields::multifluid::dPhaseCompFraction >; + + using CapPressureAccessors = + StencilMaterialAccessors< constitutive::CapillaryPressureBase, + fields::cappres::phaseCapPressure, + fields::cappres::dPhaseCapPressure_dPhaseVolFraction >; + + using PermeabilityAccessors = + StencilMaterialAccessors< constitutive::PermeabilityBase, + fields::permeability::permeability, + fields::permeability::dPerm_dPressure >; + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofNumberAccessor accessor for the dof numbers + * @param[in] compFlowAccessors accessor for wrappers registered by the solver + * @param[in] multiFluidAccessors accessor for wrappers registered by the multifluid model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed all together + */ + FluxComputeKernelBase( integer const numPhases, + globalIndex const rankOffset, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ); + +protected: + + /// Number of fluid phases + integer const m_numPhases; + + /// Offset for my MPI rank + globalIndex const m_rankOffset; + + /// Time step size + real64 const m_dt; + + /// Views on dof numbers + ElementViewConst< arrayView1d< globalIndex const > > const m_dofNumber; + + /// Views on ghost rank numbers and gravity coefficients + ElementViewConst< arrayView1d< integer const > > const m_ghostRank; + ElementViewConst< arrayView1d< real64 const > > const m_gravCoef; + + // Primary and secondary variables + + /// Views on pressure + ElementViewConst< arrayView1d< real64 const > > const m_pres; + + /// Views on derivatives of phase volume fractions and comp fractions + ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const m_dCompFrac_dCompDens; + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const m_dPhaseVolFrac; + + /// Views on phase component fractions + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const m_phaseCompFrac; + ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const m_dPhaseCompFrac; + + // Residual and jacobian + + /// View on the local CRS matrix + CRSMatrixView< real64, globalIndex const > const m_localMatrix; + /// View on the local RHS + arrayView1d< real64 > const m_localRhs; + + BitFlags< FluxComputeKernelFlags > const m_kernelFlags; +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNELBASE_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp deleted file mode 100644 index d16e8ebb775..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp +++ /dev/null @@ -1,2182 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 IsothermalCompositionalMultiphaseFVMKernels.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP - -#include "codingUtilities/Utilities.hpp" -#include "common/DataLayouts.hpp" -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" -#include "constitutive/diffusion/DiffusionFields.hpp" -#include "constitutive/diffusion/DiffusionBase.hpp" -#include "constitutive/dispersion/DispersionFields.hpp" -#include "constitutive/dispersion/DispersionBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" -#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" -#include "constitutive/solid/porosity/PorosityBase.hpp" -#include "constitutive/solid/porosity/PorosityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "finiteVolume/BoundaryStencil.hpp" -#include "mesh/ElementRegionManager.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" - -namespace geos -{ - -namespace isothermalCompositionalMultiphaseFVMKernels -{ - -enum class FaceBasedAssemblyKernelFlags -{ - /// Flag to specify whether capillary pressure is used or not - CapPressure = 1 << 0, // 1 - /// Flag indicating whether total mass equation is formed or not - TotalMassEquation = 1 << 1, // 2 - /// Flag indicating whether C1-PPU is used or not - C1PPU = 1 << 2, // 4 - /// Flag indicating whether IHU is used or not - IHU = 1 << 3 // 8 - /// Add more flags like that if needed: - // Flag5 = 1 << 4, // 16 - // Flag6 = 1 << 5, // 32 - // Flag7 = 1 << 6, // 64 - // Flag8 = 1 << 7 //128 -}; - -/******************************** FaceBasedAssemblyKernel ********************************/ - -/** - * @brief Base class for FaceBasedAssemblyKernel that holds all data not dependent - * on template parameters (like stencil type and number of components/dofs). - */ -class FaceBasedAssemblyKernelBase -{ -public: - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using DofNumberAccessor = ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > >; - - using CompFlowAccessors = - StencilAccessors< fields::ghostRank, - fields::flow::gravityCoefficient, - fields::flow::pressure, - fields::flow::dGlobalCompFraction_dGlobalCompDensity, - fields::flow::phaseVolumeFraction, - fields::flow::dPhaseVolumeFraction, - fields::flow::phaseMobility, - fields::flow::dPhaseMobility >; - using MultiFluidAccessors = - StencilMaterialAccessors< constitutive::MultiFluidBase, - fields::multifluid::phaseDensity, - fields::multifluid::dPhaseDensity, - fields::multifluid::phaseMassDensity, - fields::multifluid::dPhaseMassDensity, - fields::multifluid::phaseCompFraction, - fields::multifluid::dPhaseCompFraction >; - - using CapPressureAccessors = - StencilMaterialAccessors< constitutive::CapillaryPressureBase, - fields::cappres::phaseCapPressure, - fields::cappres::dPhaseCapPressure_dPhaseVolFraction >; - - using PermeabilityAccessors = - StencilMaterialAccessors< constitutive::PermeabilityBase, - fields::permeability::permeability, - fields::permeability::dPerm_dPressure >; - - /** - * @brief Constructor for the kernel interface - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofNumberAccessor accessor for the dof numbers - * @param[in] compFlowAccessors accessor for wrappers registered by the solver - * @param[in] multiFluidAccessors accessor for wrappers registered by the multifluid model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - * @param[in] kernelFlags flags packed all together - */ - FaceBasedAssemblyKernelBase( integer const numPhases, - globalIndex const rankOffset, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags ); - -protected: - - /// Number of fluid phases - integer const m_numPhases; - - /// Offset for my MPI rank - globalIndex const m_rankOffset; - - /// Time step size - real64 const m_dt; - - /// Views on dof numbers - ElementViewConst< arrayView1d< globalIndex const > > const m_dofNumber; - - /// Views on ghost rank numbers and gravity coefficients - ElementViewConst< arrayView1d< integer const > > const m_ghostRank; - ElementViewConst< arrayView1d< real64 const > > const m_gravCoef; - - // Primary and secondary variables - - /// Views on pressure - ElementViewConst< arrayView1d< real64 const > > const m_pres; - - /// Views on derivatives of phase volume fractions and comp fractions - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const m_dCompFrac_dCompDens; - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const m_dPhaseVolFrac; - - /// Views on phase component fractions - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const m_phaseCompFrac; - ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const m_dPhaseCompFrac; - - // Residual and jacobian - - /// View on the local CRS matrix - CRSMatrixView< real64, globalIndex const > const m_localMatrix; - /// View on the local RHS - arrayView1d< real64 > const m_localRhs; - - BitFlags< FaceBasedAssemblyKernelFlags > const m_kernelFlags; -}; - -/** - * @class FaceBasedAssemblyKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @brief Define the interface for the assembly kernel in charge of flux terms - */ -template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase -{ -public: - - /// Compile time value for the number of components - static constexpr integer numComp = NUM_COMP; - - /// Compute time value for the number of degrees of freedom - static constexpr integer numDof = NUM_DOF; - - /// Compute time value for the number of equations (all of them, except the volume balance equation) - static constexpr integer numEqn = NUM_DOF-1; - - /// Maximum number of elements at the face - static constexpr localIndex maxNumElems = STENCILWRAPPER::maxNumPointsInFlux; - - /// Maximum number of connections at the face - static constexpr localIndex maxNumConns = STENCILWRAPPER::maxNumConnections; - - /// Maximum number of points in the stencil - static constexpr localIndex maxStencilSize = STENCILWRAPPER::maxStencilSize; - - /// Number of flux support points (hard-coded for TFPA) - static constexpr integer numFluxSupportPoints = 2; - - /** - * @brief Constructor for the kernel interface - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dofNumberAccessor - * @param[in] compFlowAccessors - * @param[in] multiFluidAccessors - * @param[in] capPressureAccessors - * @param[in] permeabilityAccessors - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - * @param[in] kernelFlags flags packed together - */ - FaceBasedAssemblyKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags ) - : FaceBasedAssemblyKernelBase( numPhases, - rankOffset, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ), - m_permeability( permeabilityAccessors.get( fields::permeability::permeability {} ) ), - m_dPerm_dPres( permeabilityAccessors.get( fields::permeability::dPerm_dPressure {} ) ), - m_phaseMob( compFlowAccessors.get( fields::flow::phaseMobility {} ) ), - m_dPhaseMob( compFlowAccessors.get( fields::flow::dPhaseMobility {} ) ), - m_phaseMassDens( multiFluidAccessors.get( fields::multifluid::phaseMassDensity {} ) ), - m_dPhaseMassDens( multiFluidAccessors.get( fields::multifluid::dPhaseMassDensity {} ) ), - m_phaseCapPressure( capPressureAccessors.get( fields::cappres::phaseCapPressure {} ) ), - m_dPhaseCapPressure_dPhaseVolFrac( capPressureAccessors.get( fields::cappres::dPhaseCapPressure_dPhaseVolFraction {} ) ), - m_stencilWrapper( stencilWrapper ), - m_seri( stencilWrapper.getElementRegionIndices() ), - m_sesri( stencilWrapper.getElementSubRegionIndices() ), - m_sei( stencilWrapper.getElementIndices() ) - { } - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables - { -public: - - /** - * @brief Constructor for the stack variables - * @param[in] size size of the stencil for this connection - * @param[in] numElems number of elements for this connection - */ - GEOS_HOST_DEVICE - StackVariables( localIndex const size, localIndex numElems ) - : stencilSize( size ), - numConnectedElems( numElems ), - dofColIndices( size * numDof ), - localFlux( numElems * numEqn ), - localFluxJacobian( numElems * numEqn, size * numDof ) - {} - - // Stencil information - - /// Stencil size for a given connection - localIndex const stencilSize; - /// Number of elements connected at a given connection - localIndex const numConnectedElems; - - // Transmissibility and derivatives - - /// Transmissibility - real64 transmissibility[maxNumConns][numFluxSupportPoints]{}; - /// Derivatives of transmissibility with respect to pressure - real64 dTrans_dPres[maxNumConns][numFluxSupportPoints]{}; - - // Local degrees of freedom and local residual/jacobian - - /// Indices of the matrix rows/columns corresponding to the dofs in this face - stackArray1d< globalIndex, maxNumElems * numDof > dofColIndices; - - /// Storage for the face local residual vector (all equations except volume balance) - stackArray1d< real64, maxNumElems * numEqn > localFlux; - /// Storage for the face local Jacobian matrix - stackArray2d< real64, maxNumElems * numEqn * maxStencilSize * numDof > localFluxJacobian; - }; - - - /** - * @brief Getter for the stencil size at this connection - * @param[in] iconn the connection index - * @return the size of the stencil at this connection - */ - GEOS_HOST_DEVICE - inline - localIndex stencilSize( localIndex const iconn ) const { return m_sei[iconn].size(); } - - /** - * @brief Getter for the number of elements at this connection - * @param[in] iconn the connection index - * @return the number of elements at this connection - */ - GEOS_HOST_DEVICE - inline - localIndex numPointsInFlux( localIndex const iconn ) const { return m_stencilWrapper.numPointsInFlux( iconn ); } - - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] iconn the connection index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - inline - void setup( localIndex const iconn, - StackVariables & stack ) const - { - // set degrees of freedom indices for this face - for( integer i = 0; i < stack.stencilSize; ++i ) - { - globalIndex const offset = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; - - for( integer jdof = 0; jdof < numDof; ++jdof ) - { - stack.dofColIndices[i * numDof + jdof] = offset + jdof; - } - } - } - - /** - * @brief Compute the local flux contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - inline - void computeFlux( localIndex const iconn, - StackVariables & stack, - FUNC && compFluxKernelOp = NoOpFunc{} ) const - { - - // first, compute the transmissibilities at this face - m_stencilWrapper.computeWeights( iconn, - m_permeability, - m_dPerm_dPres, - stack.transmissibility, - stack.dTrans_dPres ); - - - localIndex k[numFluxSupportPoints]; - localIndex connectionIndex = 0; - for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) - { - for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) - { - /// cell indices - localIndex const seri[numFluxSupportPoints] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; - localIndex const sesri[numFluxSupportPoints] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; - localIndex const sei[numFluxSupportPoints] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; - - // clear working arrays - real64 compFlux[numComp]{}; - real64 dCompFlux_dP[numFluxSupportPoints][numComp]{}; - real64 dCompFlux_dC[numFluxSupportPoints][numComp][numComp]{}; - - real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], - stack.transmissibility[connectionIndex][1] }; - - real64 const dTrans_dPres[numFluxSupportPoints] = { stack.dTrans_dPres[connectionIndex][0], - stack.dTrans_dPres[connectionIndex][1] }; - - //***** calculation of flux ***** - // loop over phases, compute and upwind phase flux and sum contributions to each component's flux - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - // create local work arrays - real64 potGrad = 0.0; - real64 phaseFlux = 0.0; - real64 dPhaseFlux_dP[numFluxSupportPoints]{}; - real64 dPhaseFlux_dC[numFluxSupportPoints][numComp]{}; - - localIndex k_up = -1; - - if( m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::C1PPU ) ) - { - isothermalCompositionalMultiphaseFVMKernelUtilities::C1PPUPhaseFlux::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_dCompFrac_dCompDens, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - else if( m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::IHU ) ) - { - isothermalCompositionalMultiphaseFVMKernelUtilities::IHUPhaseFlux::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_dCompFrac_dCompDens, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - else - { - isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFlux::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_dCompFrac_dCompDens, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - - // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives - // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase - compFluxKernelOp( ip, k, seri, sesri, sei, connectionIndex, - k_up, seri[k_up], sesri[k_up], sei[k_up], potGrad, - phaseFlux, dPhaseFlux_dP, dPhaseFlux_dC ); - - } // loop over phases - - /// populate local flux vector and derivatives - for( integer ic = 0; ic < numComp; ++ic ) - { - integer const eqIndex0 = k[0] * numEqn + ic; - integer const eqIndex1 = k[1] * numEqn + ic; - - stack.localFlux[eqIndex0] += m_dt * compFlux[ic]; - stack.localFlux[eqIndex1] -= m_dt * compFlux[ic]; - - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - localIndex const localDofIndexPres = k[ke] * numDof; - stack.localFluxJacobian[eqIndex0][localDofIndexPres] += m_dt * dCompFlux_dP[ke][ic]; - stack.localFluxJacobian[eqIndex1][localDofIndexPres] -= m_dt * dCompFlux_dP[ke][ic]; - - for( integer jc = 0; jc < numComp; ++jc ) - { - localIndex const localDofIndexComp = localDofIndexPres + jc + 1; - stack.localFluxJacobian[eqIndex0][localDofIndexComp] += m_dt * dCompFlux_dC[ke][ic][jc]; - stack.localFluxJacobian[eqIndex1][localDofIndexComp] -= m_dt * dCompFlux_dC[ke][ic][jc]; - } - } - } - connectionIndex++; - } // loop over k[1] - } // loop over k[0] - - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - inline - void complete( localIndex const iconn, - StackVariables & stack, - FUNC && assemblyKernelOp = NoOpFunc{} ) const - { - using namespace compositionalMultiphaseUtilities; - - if( m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::TotalMassEquation ) ) - { - // Apply equation/variable change transformation(s) - stackArray1d< real64, maxStencilSize * numDof > work( stack.stencilSize * numDof ); - shiftBlockRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numEqn, numDof * stack.stencilSize, stack.numConnectedElems, - stack.localFluxJacobian, work ); - shiftBlockElementsAheadByOneAndReplaceFirstElementWithSum( numComp, numEqn, stack.numConnectedElems, - stack.localFlux ); - } - - // add contribution to residual and jacobian into: - // - the component mass balance equations (i = 0 to i = numComp-1) - // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels - for( integer i = 0; i < stack.numConnectedElems; ++i ) - { - if( m_ghostRank[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 ) - { - globalIndex const globalRow = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; - localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); - GEOS_ASSERT_GE( localRow, 0 ); - GEOS_ASSERT_GT( m_localMatrix.numRows(), localRow + numComp ); - - for( integer ic = 0; ic < numComp; ++ic ) - { - RAJA::atomicAdd( parallelDeviceAtomic{}, &m_localRhs[localRow + ic], - stack.localFlux[i * numEqn + ic] ); - m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > - ( localRow + ic, - stack.dofColIndices.data(), - stack.localFluxJacobian[i * numEqn + ic].dataIfContiguous(), - stack.stencilSize * numDof ); - } - - // call the lambda to assemble additional terms, such as thermal terms - assemblyKernelOp( i, localRow ); - } - } - } - - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numConnections the number of connections - * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables - */ - template< typename POLICY, typename KERNEL_TYPE > - static void - launch( localIndex const numConnections, - KERNEL_TYPE const & kernelComponent ) - { - GEOS_MARK_FUNCTION; - forAll< POLICY >( numConnections, [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ), - kernelComponent.numPointsInFlux( iconn ) ); - - kernelComponent.setup( iconn, stack ); - kernelComponent.computeFlux( iconn, stack ); - kernelComponent.complete( iconn, stack ); - } ); - } - -protected: - - /// Views on permeability - ElementViewConst< arrayView3d< real64 const > > const m_permeability; - ElementViewConst< arrayView3d< real64 const > > const m_dPerm_dPres; - - /// Views on phase mobilities - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const m_phaseMob; - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const m_dPhaseMob; - - /// Views on phase mass densities - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseMassDens; - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseMassDens; - - /// Views on phase capillary pressure - ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const m_phaseCapPressure; - ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const m_dPhaseCapPressure_dPhaseVolFrac; - - // Stencil information - - /// Reference to the stencil wrapper - STENCILWRAPPER const m_stencilWrapper; - - /// Connection to element maps - typename STENCILWRAPPER::IndexContainerViewConstType const m_seri; - typename STENCILWRAPPER::IndexContainerViewConstType const m_sesri; - typename STENCILWRAPPER::IndexContainerViewConstType const m_sei; - -}; - -/** - * @class FaceBasedAssemblyKernelFactory - */ -class FaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] hasCapPressure flag specifying whether capillary pressure is used or not - * @param[in] solverName name of the solver (to name accessors) - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY, typename STENCILWRAPPER > - static void - createAndLaunch( integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - string const & dofKey, - integer const hasCapPressure, - integer const useTotalMassEquation, - UpwindingParameters upwindingParams, - string const & solverName, - ElementRegionManager const & elemManager, - STENCILWRAPPER const & stencilWrapper, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) - { - integer constexpr NUM_COMP = NC(); - integer constexpr NUM_DOF = NC() + 1; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags; - if( hasCapPressure ) - kernelFlags.set( FaceBasedAssemblyKernelFlags::CapPressure ); - if( useTotalMassEquation ) - kernelFlags.set( FaceBasedAssemblyKernelFlags::TotalMassEquation ); - if( upwindingParams.upwindingScheme == UpwindingScheme::C1PPU && - isothermalCompositionalMultiphaseFVMKernelUtilities::epsC1PPU > 0 ) - kernelFlags.set( FaceBasedAssemblyKernelFlags::C1PPU ); - else if( upwindingParams.upwindingScheme == UpwindingScheme::IHU ) - kernelFlags.set( FaceBasedAssemblyKernelFlags::IHU ); - - - using kernelType = FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; - typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); - typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); - typename kernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); - typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); - - kernelType kernel( numPhases, rankOffset, stencilWrapper, dofNumberAccessor, - compFlowAccessors, multiFluidAccessors, capPressureAccessors, permeabilityAccessors, - dt, localMatrix, localRhs, kernelFlags ); - kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); - } ); - } -}; - -/******************************** DiffusionDispersionFaceBasedAssemblyKernel ********************************/ - -/** - * @class DiffusionDispersionFaceBasedAssemblyKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @brief Define the interface for the assembly kernel in charge of diffusion/dispersion flux terms - */ -template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > -class DiffusionDispersionFaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase -{ -public: - - /// Compile time value for the number of components - static constexpr integer numComp = NUM_COMP; - - /// Compute time value for the number of degrees of freedom - static constexpr integer numDof = NUM_DOF; - - /// Compute time value for the number of equations (all of them, except the volume balance equation) - static constexpr integer numEqn = NUM_DOF-1; - - /// Maximum number of elements at the face - static constexpr localIndex maxNumElems = STENCILWRAPPER::maxNumPointsInFlux; - - /// Maximum number of connections at the face - static constexpr localIndex maxNumConns = STENCILWRAPPER::maxNumConnections; - - /// Maximum number of points in the stencil - static constexpr localIndex maxStencilSize = STENCILWRAPPER::maxStencilSize; - - /// Number of flux support points (hard-coded for TFPA) - static constexpr integer numFluxSupportPoints = 2; - - using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelBase; - using AbstractBase::m_dPhaseVolFrac; - using AbstractBase::m_kernelFlags; - - using DiffusionAccessors = - StencilMaterialAccessors< constitutive::DiffusionBase, - fields::diffusion::diffusivity, - fields::diffusion::dDiffusivity_dTemperature, - fields::diffusion::phaseDiffusivityMultiplier >; - - using DispersionAccessors = - StencilMaterialAccessors< constitutive::DispersionBase, - fields::dispersion::dispersivity >; - - using PorosityAccessors = - StencilMaterialAccessors< constitutive::PorosityBase, - fields::porosity::referencePorosity >; - - /** - * @brief Constructor for the kernel interface - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dofNumberAccessor - * @param[in] compFlowAccessors - * @param[in] multiFluidAccessors - * @param[in] diffusionAccessors - * @param[in] dispersionAccessors - * @param[in] porosityAccessors - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - * @param[in] kernelFlags flags packed together - */ - DiffusionDispersionFaceBasedAssemblyKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - DiffusionAccessors const & diffusionAccessors, - DispersionAccessors const & dispersionAccessors, - PorosityAccessors const & porosityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags ) - : FaceBasedAssemblyKernelBase( numPhases, - rankOffset, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ), - m_phaseVolFrac( compFlowAccessors.get( fields::flow::phaseVolumeFraction {} ) ), - m_phaseDens( multiFluidAccessors.get( fields::multifluid::phaseDensity {} ) ), - m_dPhaseDens( multiFluidAccessors.get( fields::multifluid::dPhaseDensity {} ) ), - m_diffusivity( diffusionAccessors.get( fields::diffusion::diffusivity {} ) ), - m_dDiffusivity_dTemp( diffusionAccessors.get( fields::diffusion::dDiffusivity_dTemperature {} ) ), - m_phaseDiffusivityMultiplier( diffusionAccessors.get( fields::diffusion::phaseDiffusivityMultiplier {} ) ), - m_dispersivity( dispersionAccessors.get( fields::dispersion::dispersivity {} ) ), - m_referencePorosity( porosityAccessors.get( fields::porosity::referencePorosity {} ) ), - m_stencilWrapper( stencilWrapper ), - m_seri( stencilWrapper.getElementRegionIndices() ), - m_sesri( stencilWrapper.getElementSubRegionIndices() ), - m_sei( stencilWrapper.getElementIndices() ) - { } - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables - { -public: - - /** - * @brief Constructor for the stack variables - * @param[in] size size of the stencil for this connection - * @param[in] numElems number of elements for this connection - */ - GEOS_HOST_DEVICE - StackVariables( localIndex const size, localIndex numElems ) - : stencilSize( size ), - numConnectedElems( numElems ), - dofColIndices( size * numDof ), - localFlux( numElems * numEqn ), - localFluxJacobian( numElems * numEqn, size * numDof ) - {} - - // Stencil information - - /// Stencil size for a given connection - localIndex const stencilSize; - /// Number of elements connected at a given connection - localIndex const numConnectedElems; - - /// Transmissibility - real64 transmissibility[maxNumConns][numFluxSupportPoints]{}; - /// Derivatives of transmissibility with respect to pressure - real64 dTrans_dTemp[maxNumConns][numFluxSupportPoints]{}; - - // Local degrees of freedom and local residual/jacobian - - /// Indices of the matrix rows/columns corresponding to the dofs in this face - stackArray1d< globalIndex, maxNumElems * numDof > dofColIndices; - - /// Storage for the face local residual vector (all equations except volume balance) - stackArray1d< real64, maxNumElems * numEqn > localFlux; - /// Storage for the face local Jacobian matrix - stackArray2d< real64, maxNumElems * numEqn * maxStencilSize * numDof > localFluxJacobian; - }; - - - /** - * @brief Getter for the stencil size at this connection - * @param[in] iconn the connection index - * @return the size of the stencil at this connection - */ - GEOS_HOST_DEVICE - inline - localIndex stencilSize( localIndex const iconn ) const - { return m_sei[iconn].size(); } - - /** - * @brief Getter for the number of elements at this connection - * @param[in] iconn the connection index - * @return the number of elements at this connection - */ - GEOS_HOST_DEVICE - inline - localIndex numPointsInFlux( localIndex const iconn ) const - { return m_stencilWrapper.numPointsInFlux( iconn ); } - - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] iconn the connection index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - inline - void setup( localIndex const iconn, - StackVariables & stack ) const - { - // set degrees of freedom indices for this face - for( integer i = 0; i < stack.stencilSize; ++i ) - { - globalIndex const offset = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; - - for( integer jdof = 0; jdof < numDof; ++jdof ) - { - stack.dofColIndices[i * numDof + jdof] = offset + jdof; - } - } - } - - /** - * @brief Compute the local diffusion flux contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - * @param[in] diffusionFluxKernelOp the function used to customize the computation of the component fluxes - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - inline - void computeDiffusionFlux( localIndex const iconn, - StackVariables & stack, - FUNC && diffusionFluxKernelOp = NoOpFunc{} ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - // first, compute the transmissibilities at this face - m_stencilWrapper.computeWeights( iconn, - m_diffusivity, - m_dDiffusivity_dTemp, - stack.transmissibility, - stack.dTrans_dTemp ); - - - localIndex k[numFluxSupportPoints]{}; - localIndex connectionIndex = 0; - for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) - { - for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) - { - /// cell indices - localIndex const seri[numFluxSupportPoints] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; - localIndex const sesri[numFluxSupportPoints] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; - localIndex const sei[numFluxSupportPoints] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; - - // clear working arrays - real64 diffusionFlux[numComp]{}; - real64 dDiffusionFlux_dP[numFluxSupportPoints][numComp]{}; - real64 dDiffusionFlux_dC[numFluxSupportPoints][numComp][numComp]{}; - real64 dDens_dC[numComp]{}; - - real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], - stack.transmissibility[connectionIndex][1] }; - - //***** calculation of flux ***** - // loop over phases, compute and upwind phase flux and sum contributions to each component's flux - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - - // loop over components - for( integer ic = 0; ic < numComp; ++ic ) - { - - real64 compFracGrad = 0.0; - real64 dCompFracGrad_dP[numFluxSupportPoints]{}; - real64 dCompFracGrad_dC[numFluxSupportPoints][numComp]{}; - - // compute the component fraction gradient using the diffusion transmissibility - computeCompFractionGradient( ip, ic, - seri, sesri, sei, - trans, - compFracGrad, - dCompFracGrad_dP, - dCompFracGrad_dC ); - - // choose upstream cell for composition upwinding - localIndex const k_up = (compFracGrad >= 0) ? 0 : 1; - - localIndex const er_up = seri[k_up]; - localIndex const esr_up = sesri[k_up]; - localIndex const ei_up = sei[k_up]; - - // computation of the upwinded mass flux - real64 const upwindCoefficient = - m_referencePorosity[er_up][esr_up][ei_up] * - m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * - m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_phaseVolFrac[er_up][esr_up][ei_up][ip]; - diffusionFlux[ic] += upwindCoefficient * compFracGrad; - - // add contributions of the derivatives of component fractions wrt pressure/component fractions - for( integer ke = 0; ke < numFluxSupportPoints; ke++ ) - { - dDiffusionFlux_dP[ke][ic] += upwindCoefficient * dCompFracGrad_dP[ke]; - for( integer jc = 0; jc < numComp; ++jc ) - { - dDiffusionFlux_dC[ke][ic][jc] += upwindCoefficient * dCompFracGrad_dC[ke][jc]; - } - } - - // add contributions of the derivatives of upwind coefficient wrt pressure/component fractions - real64 const dUpwindCoefficient_dP = - m_referencePorosity[er_up][esr_up][ei_up] * - m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * - ( m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] * m_phaseVolFrac[er_up][esr_up][ei_up][ip] - + m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dP] ); - dDiffusionFlux_dP[k_up][ic] += dUpwindCoefficient_dP * compFracGrad; - - applyChainRule( numComp, - m_dCompFrac_dCompDens[er_up][esr_up][ei_up], - m_dPhaseDens[er_up][esr_up][ei_up][0][ip], - dDens_dC, - Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - real64 const dUpwindCoefficient_dC = - m_referencePorosity[er_up][esr_up][ei_up] * - m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * - ( dDens_dC[jc] * m_phaseVolFrac[er_up][esr_up][ei_up][ip] - + m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dC+jc] ); - dDiffusionFlux_dC[k_up][ic][jc] += dUpwindCoefficient_dC * compFracGrad; - } - - // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives - // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase - diffusionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex, - k_up, seri[k_up], sesri[k_up], sei[k_up], - compFracGrad, upwindCoefficient ); - - } // loop over components - } // loop over phases - - // add diffusion flux to local flux and local flux jacobian - addToLocalFluxAndJacobian( k, - stack, - diffusionFlux, - dDiffusionFlux_dP, - dDiffusionFlux_dC ); - - connectionIndex++; - } // loop over k[1] - } // loop over k[0] - } - - /** - * @brief Compute the local dispersion flux contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - * @param[in] dispersionFluxKernelOp the function used to customize the computation of the component fluxes - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - inline - void computeDispersionFlux( localIndex const iconn, - StackVariables & stack, - FUNC && dispersionFluxKernelOp = NoOpFunc{} ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - // first, compute the transmissibilities at this face - // note that the dispersion tensor is lagged in iteration - m_stencilWrapper.computeWeights( iconn, - m_dispersivity, - m_dispersivity, // this is just to pass something, but the resulting derivative won't be used - stack.transmissibility, - stack.dTrans_dTemp ); // will not be used - - - localIndex k[numFluxSupportPoints]{}; - localIndex connectionIndex = 0; - for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) - { - for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) - { - /// cell indices - localIndex const seri[numFluxSupportPoints] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; - localIndex const sesri[numFluxSupportPoints] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; - localIndex const sei[numFluxSupportPoints] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; - - // clear working arrays - real64 dispersionFlux[numComp]{}; - real64 dDispersionFlux_dP[numFluxSupportPoints][numComp]{}; - real64 dDispersionFlux_dC[numFluxSupportPoints][numComp][numComp]{}; - real64 dDens_dC[numComp]{}; - - real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], - stack.transmissibility[connectionIndex][1] }; - - //***** calculation of flux ***** - // loop over phases, compute and upwind phase flux and sum contributions to each component's flux - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - - // loop over components - for( integer ic = 0; ic < numComp; ++ic ) - { - - real64 compFracGrad = 0.0; - real64 dCompFracGrad_dP[numFluxSupportPoints]{}; - real64 dCompFracGrad_dC[numFluxSupportPoints][numComp]{}; - - // compute the component fraction gradient using the dispersion transmissibility - computeCompFractionGradient( ip, ic, - seri, sesri, sei, - trans, - compFracGrad, - dCompFracGrad_dP, - dCompFracGrad_dC ); - - // choose upstream cell for composition upwinding - localIndex const k_up = (compFracGrad >= 0) ? 0 : 1; - - localIndex const er_up = seri[k_up]; - localIndex const esr_up = sesri[k_up]; - localIndex const ei_up = sei[k_up]; - - // computation of the upwinded mass flux - dispersionFlux[ic] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * compFracGrad; - - // add contributions of the derivatives of component fractions wrt pressure/component fractions - for( integer ke = 0; ke < numFluxSupportPoints; ke++ ) - { - dDispersionFlux_dP[ke][ic] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dP[ke]; - for( integer jc = 0; jc < numComp; ++jc ) - { - dDispersionFlux_dC[ke][ic][jc] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dC[ke][jc]; - } - } - - // add contributions of the derivatives of upwind coefficient wrt pressure/component fractions - dDispersionFlux_dP[k_up][ic] += m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dP] * compFracGrad; - - applyChainRule( numComp, - m_dCompFrac_dCompDens[er_up][esr_up][ei_up], - m_dPhaseDens[er_up][esr_up][ei_up][0][ip], - dDens_dC, - Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - dDispersionFlux_dC[k_up][ic][jc] += dDens_dC[jc] * compFracGrad; - } - - // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives - // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase - dispersionFluxKernelOp( ip, ic, k, seri, sesri, sei, connectionIndex, - k_up, seri[k_up], sesri[k_up], sei[k_up], - compFracGrad ); - - } // loop over components - } // loop over phases - - // add dispersion flux to local flux and local flux jacobian - addToLocalFluxAndJacobian( k, - stack, - dispersionFlux, - dDispersionFlux_dP, - dDispersionFlux_dC ); - - connectionIndex++; - } // loop over k[1] - } // loop over k[0] - } - - /** - * @brief Compute the component fraction gradient at this interface - * @param[in] ip the phase index - * @param[in] ic the component index - * @param[in] seri the region indices - * @param[in] sesri the subregion indices - * @param[in] sei the element indices - * @param[out] compFracGrad the component fraction gradient - * @param[out] dCompFracGrad_dP the derivatives of the component fraction gradient wrt pressure - * @param[out] dCompFracGrad_dC the derivatives of the component fraction gradient wrt component densities - */ - GEOS_HOST_DEVICE - inline - void computeCompFractionGradient( integer const ip, - integer const ic, - localIndex const (&seri)[numFluxSupportPoints], - localIndex const (&sesri)[numFluxSupportPoints], - localIndex const (&sei)[numFluxSupportPoints], - real64 const (&trans)[numFluxSupportPoints], - real64 & compFracGrad, - real64 (& dCompFracGrad_dP)[numFluxSupportPoints], - real64 (& dCompFracGrad_dC)[numFluxSupportPoints][numComp] ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - real64 dCompFrac_dC[numComp]{}; - - for( integer i = 0; i < numFluxSupportPoints; i++ ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - compFracGrad += trans[i] * m_phaseCompFrac[er][esr][ei][0][ip][ic]; - dCompFracGrad_dP[i] += trans[i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dP]; - - applyChainRule( numComp, - m_dCompFrac_dCompDens[er][esr][ei], - m_dPhaseCompFrac[er][esr][ei][0][ip][ic], - dCompFrac_dC, - Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - dCompFracGrad_dC[i][jc] += trans[i] * dCompFrac_dC[jc]; - } - } - } - - /** - * @brief Add the local diffusion/dispersion flux contributions to the residual and Jacobian - * @param[in] k the cell indices - * @param[in] stack the stack variables - * @param[in] flux the diffusion/dispersion flux - * @param[in] dFlux_dP the derivative of the diffusion/dispersion flux wrt pressure - * @param[in] dFlux_dC the derivative of the diffusion/dispersion flux wrt compositions - */ - GEOS_HOST_DEVICE - inline - void addToLocalFluxAndJacobian( localIndex const (&k)[numFluxSupportPoints], - StackVariables & stack, - real64 const (&flux)[numComp], - real64 const (&dFlux_dP)[numFluxSupportPoints][numComp], - real64 const (&dFlux_dC)[numFluxSupportPoints][numComp][numComp] ) const - { - // loop over components - for( integer ic = 0; ic < numComp; ++ic ) - { - // finally, increment local flux and local Jacobian - integer const eqIndex0 = k[0] * numEqn + ic; - integer const eqIndex1 = k[1] * numEqn + ic; - - stack.localFlux[eqIndex0] += m_dt * flux[ic]; - stack.localFlux[eqIndex1] -= m_dt * flux[ic]; - - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - localIndex const localDofIndexPres = k[ke] * numDof; - stack.localFluxJacobian[eqIndex0][localDofIndexPres] += m_dt * dFlux_dP[ke][ic]; - stack.localFluxJacobian[eqIndex1][localDofIndexPres] -= m_dt * dFlux_dP[ke][ic]; - - for( integer jc = 0; jc < numComp; ++jc ) - { - localIndex const localDofIndexComp = localDofIndexPres + jc + 1; - stack.localFluxJacobian[eqIndex0][localDofIndexComp] += m_dt * dFlux_dC[ke][ic][jc]; - stack.localFluxJacobian[eqIndex1][localDofIndexComp] -= m_dt * dFlux_dC[ke][ic][jc]; - } - } - } - } - - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - inline - void complete( localIndex const iconn, - StackVariables & stack, - FUNC && assemblyKernelOp = NoOpFunc{} ) const - { - using namespace compositionalMultiphaseUtilities; - - if( m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::TotalMassEquation ) ) - { - // Apply equation/variable change transformation(s) - stackArray1d< real64, maxStencilSize * numDof > work( stack.stencilSize * numDof ); - shiftBlockRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numEqn, numDof*stack.stencilSize, stack.numConnectedElems, - stack.localFluxJacobian, work ); - shiftBlockElementsAheadByOneAndReplaceFirstElementWithSum( numComp, numEqn, stack.numConnectedElems, - stack.localFlux ); - } - - // add contribution to residual and jacobian into: - // - the component mass balance equations (i = 0 to i = numComp-1) - // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels - for( integer i = 0; i < stack.numConnectedElems; ++i ) - { - if( m_ghostRank[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 ) - { - globalIndex const globalRow = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; - localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); - GEOS_ASSERT_GE( localRow, 0 ); - GEOS_ASSERT_GT( m_localMatrix.numRows(), localRow + numComp ); - - for( integer ic = 0; ic < numComp; ++ic ) - { - RAJA::atomicAdd( parallelDeviceAtomic{}, &m_localRhs[localRow + ic], stack.localFlux[i * numEqn + ic] ); - m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > - ( localRow + ic, - stack.dofColIndices.data(), - stack.localFluxJacobian[i * numEqn + ic].dataIfContiguous(), - stack.stencilSize * numDof ); - } - - // call the lambda to assemble additional terms, such as thermal terms - assemblyKernelOp( i, localRow ); - } - } - } - - /** - * @brief Performs the kernel launch - * @tparam POLICY the policy used in the RAJA kernels - * @tparam KERNEL_TYPE the kernel type - * @param[in] numConnections the number of connections - * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables - */ - template< typename POLICY, typename KERNEL_TYPE > - static void - launch( localIndex const numConnections, - integer const hasDiffusion, - integer const hasDispersion, - KERNEL_TYPE const & kernelComponent ) - { - GEOS_MARK_FUNCTION; - forAll< POLICY >( numConnections, [=] GEOS_HOST_DEVICE ( localIndex const iconn ) - { - typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ), - kernelComponent.numPointsInFlux( iconn ) ); - - kernelComponent.setup( iconn, stack ); - if( hasDiffusion ) - { - kernelComponent.computeDiffusionFlux( iconn, stack ); - } - if( hasDispersion ) - { - kernelComponent.computeDispersionFlux( iconn, stack ); - } - kernelComponent.complete( iconn, stack ); - } ); - } - -protected: - - /// Views on phase volume fraction - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const m_phaseVolFrac; - - /// Views on phase densities - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseDens; - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseDens; - - /// Views on diffusivity - ElementViewConst< arrayView3d< real64 const > > const m_diffusivity; - ElementViewConst< arrayView3d< real64 const > > const m_dDiffusivity_dTemp; - ElementViewConst< arrayView3d< real64 const > > const m_phaseDiffusivityMultiplier; - - /// Views on dispersivity - ElementViewConst< arrayView3d< real64 const > > const m_dispersivity; - - /// View on the reference porosity - ElementViewConst< arrayView1d< real64 const > > const m_referencePorosity; - - // Stencil information - - /// Reference to the stencil wrapper - STENCILWRAPPER const m_stencilWrapper; - - /// Connection to element maps - typename STENCILWRAPPER::IndexContainerViewConstType const m_seri; - typename STENCILWRAPPER::IndexContainerViewConstType const m_sesri; - typename STENCILWRAPPER::IndexContainerViewConstType const m_sei; - -}; - -/** - * @class DiffusionDispersionFaceBasedAssemblyKernelFactory - */ -class DiffusionDispersionFaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] hasDiffusion flag specifying whether diffusion is used or not - * @param[in] hasDispersion flag specifying whether dispersion is used or not - * @param[in] solverName the name of the solver - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY, typename STENCILWRAPPER > - static void - createAndLaunch( integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - string const & dofKey, - integer const hasDiffusion, - integer const hasDispersion, - integer const useTotalMassEquation, - string const & solverName, - ElementRegionManager const & elemManager, - STENCILWRAPPER const & stencilWrapper, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) - { - integer constexpr NUM_COMP = NC(); - integer constexpr NUM_DOF = NC() + 1; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags; - if( useTotalMassEquation ) - kernelFlags.set( FaceBasedAssemblyKernelFlags::TotalMassEquation ); - - using kernelType = DiffusionDispersionFaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; - typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); - typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); - typename kernelType::DiffusionAccessors diffusionAccessors( elemManager, solverName ); - typename kernelType::DispersionAccessors dispersionAccessors( elemManager, solverName ); - typename kernelType::PorosityAccessors porosityAccessors( elemManager, solverName ); - - kernelType kernel( numPhases, rankOffset, stencilWrapper, - dofNumberAccessor, compFlowAccessors, multiFluidAccessors, - diffusionAccessors, dispersionAccessors, porosityAccessors, - dt, localMatrix, localRhs, kernelFlags ); - kernelType::template launch< POLICY >( stencilWrapper.size(), - hasDiffusion, hasDispersion, - kernel ); - } ); - } -}; - - -/******************************** DirichletFaceBasedAssemblyKernel ********************************/ - -/** - * @class DirichFaceBasedAssemblyKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @tparam FLUIDWRAPPER the type of the fluid wrapper - * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms - */ -template< integer NUM_COMP, integer NUM_DOF, typename FLUIDWRAPPER > -class DirichletFaceBasedAssemblyKernel : public FaceBasedAssemblyKernel< NUM_COMP, - NUM_DOF, - BoundaryStencilWrapper > -{ -public: - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelBase; - using DofNumberAccessor = AbstractBase::DofNumberAccessor; - using CompFlowAccessors = AbstractBase::CompFlowAccessors; - using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; - using CapPressureAccessors = AbstractBase::CapPressureAccessors; - using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; - - using AbstractBase::m_dt; - using AbstractBase::m_numPhases; - using AbstractBase::m_rankOffset; - using AbstractBase::m_dofNumber; - using AbstractBase::m_ghostRank; - using AbstractBase::m_gravCoef; - using AbstractBase::m_pres; - using AbstractBase::m_phaseCompFrac; - using AbstractBase::m_dPhaseCompFrac; - using AbstractBase::m_dCompFrac_dCompDens; - using AbstractBase::m_localMatrix; - using AbstractBase::m_localRhs; - using AbstractBase::m_kernelFlags; - - using Base = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, BoundaryStencilWrapper >; - using Base::numComp; - using Base::numDof; - using Base::numEqn; - using Base::m_stencilWrapper; - using Base::m_phaseMob; - using Base::m_dPhaseMob; - using Base::m_phaseMassDens; - using Base::m_dPhaseMassDens; - using Base::m_permeability; - using Base::m_dPerm_dPres; - using Base::m_seri; - using Base::m_sesri; - using Base::m_sei; - - /** - * @brief Constructor for the kernel interface - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] faceManager the face manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] fluidWrapper reference to the fluid wrapper - * @param[in] dofNumberAccessor - * @param[in] compFlowAccessors - * @param[in] multiFluidAccessors - * @param[in] capPressureAccessors - * @param[in] permeabilityAccessors - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - * @param[in] kernelFlags flags packed together - */ - DirichletFaceBasedAssemblyKernel( integer const numPhases, - globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags ) - : Base( numPhases, - rankOffset, - stencilWrapper, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - capPressureAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ), - m_facePres( faceManager.getField< fields::flow::facePressure >() ), - m_faceTemp( faceManager.getField< fields::flow::faceTemperature >() ), - m_faceCompFrac( faceManager.getField< fields::flow::faceGlobalCompFraction >() ), - m_faceGravCoef( faceManager.getField< fields::flow::gravityCoefficient >() ), - m_fluidWrapper( fluidWrapper ) - {} - - /** - * @struct StackVariables - * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack - */ - struct StackVariables - { -public: - - /** - * @brief Constructor for the stack variables - * @param[in] size size of the stencil for this connection - * @param[in] numElems number of elements for this connection - */ - GEOS_HOST_DEVICE - StackVariables( localIndex const GEOS_UNUSED_PARAM( size ), - localIndex GEOS_UNUSED_PARAM( numElems )) {} - - // Transmissibility - real64 transmissibility = 0.0; - - // Component fluxes and derivatives - - /// Component fluxes - real64 compFlux[numComp]{}; - /// Derivatives of component fluxes wrt pressure - real64 dCompFlux_dP[numComp]{}; - /// Derivatives of component fluxes wrt component densities - real64 dCompFlux_dC[numComp][numComp]{}; - - // Local degrees of freedom and local residual/jacobian - - /// Indices of the matrix rows/columns corresponding to the dofs in this face - globalIndex dofColIndices[numDof]{}; - - /// Storage for the face local residual vector - real64 localFlux[numEqn]{}; - /// Storage for the face local Jacobian matrix - real64 localFluxJacobian[numEqn][numDof]{}; - - }; - - - /** - * @brief Performs the setup phase for the kernel. - * @param[in] iconn the connection index - * @param[in] stack the stack variables - */ - GEOS_HOST_DEVICE - void setup( localIndex const iconn, - StackVariables & stack ) const - { - globalIndex const offset = - m_dofNumber[m_seri( iconn, BoundaryStencil::Order::ELEM )][m_sesri( iconn, BoundaryStencil::Order::ELEM )][m_sei( iconn, BoundaryStencil::Order::ELEM )]; - - for( integer jdof = 0; jdof < numDof; ++jdof ) - { - stack.dofColIndices[jdof] = offset + jdof; - } - } - - - /** - * @brief Compute the local Dirichlet face flux contributions to the residual and Jacobian - * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void computeFlux( localIndex const iconn, - StackVariables & stack, - FUNC && compFluxKernelOp = NoOpFunc{} ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - using Order = BoundaryStencil::Order; - - localIndex const er = m_seri( iconn, Order::ELEM ); - localIndex const esr = m_sesri( iconn, Order::ELEM ); - localIndex const ei = m_sei( iconn, Order::ELEM ); - localIndex const kf = m_sei( iconn, Order::FACE ); - - // Step 1: compute the transmissibility at the boundary face - - real64 dTrans_dPerm[3]{}; - m_stencilWrapper.computeWeights( iconn, - m_permeability, - stack.transmissibility, - dTrans_dPerm ); - real64 const dTrans_dPres = LvArray::tensorOps::AiBi< 3 >( dTrans_dPerm, m_dPerm_dPres[er][esr][ei][0] ); - - // Step 2: compute the fluid properties on the face - // This is needed to get the phase mass density and the phase comp fraction at the face - // Because we approximate the face mobility using the total element mobility - - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseFrac( 1, 1, m_numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseDens( 1, 1, m_numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseMassDens( 1, 1, m_numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseVisc( 1, 1, m_numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseEnthalpy( 1, 1, m_numPhases ); - StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseInternalEnergy( 1, 1, m_numPhases ); - StackArray< real64, 4, constitutive::MultiFluidBase::MAX_NUM_PHASES * NUM_COMP, - constitutive::multifluid::LAYOUT_PHASE_COMP > facePhaseCompFrac( 1, 1, m_numPhases, NUM_COMP ); - real64 faceTotalDens = 0.0; - - constitutive::MultiFluidBase::KernelWrapper::computeValues( m_fluidWrapper, - m_facePres[kf], - m_faceTemp[kf], - m_faceCompFrac[kf], - facePhaseFrac[0][0], - facePhaseDens[0][0], - facePhaseMassDens[0][0], - facePhaseVisc[0][0], - facePhaseEnthalpy[0][0], - facePhaseInternalEnergy[0][0], - facePhaseCompFrac[0][0], - faceTotalDens ); - - // Step 3: loop over phases, compute and upwind phase flux and sum contributions to each component's flux - - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - - // working variables - real64 dDensMean_dC[numComp]{}; - real64 dF_dC[numComp]{}; - real64 dProp_dC[numComp]{}; - - real64 phaseFlux = 0.0; // for the lambda - real64 dPhaseFlux_dP = 0.0; - real64 dPhaseFlux_dC[numComp]{}; - - - // Step 3.1: compute the average phase mass density at the face - - applyChainRule( numComp, - m_dCompFrac_dCompDens[er][esr][ei], - m_dPhaseMassDens[er][esr][ei][0][ip], - dProp_dC, - Deriv::dC ); - - // average density and derivatives - real64 const densMean = 0.5 * ( m_phaseMassDens[er][esr][ei][0][ip] + facePhaseMassDens[0][0][ip] ); - real64 const dDensMean_dP = 0.5 * m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; - for( integer jc = 0; jc < numComp; ++jc ) - { - dDensMean_dC[jc] = 0.5 * dProp_dC[jc]; - } - - - // Step 3.2: compute the (TPFA) potential difference at the face - - real64 const gravTimesDz = m_gravCoef[er][esr][ei] - m_faceGravCoef[kf]; - real64 const potDif = m_pres[er][esr][ei] - m_facePres[kf] - densMean * gravTimesDz; - real64 const f = stack.transmissibility * potDif; - real64 const dF_dP = stack.transmissibility * ( 1.0 - dDensMean_dP * gravTimesDz ) + dTrans_dPres * potDif; - for( integer jc = 0; jc < numComp; ++jc ) - { - dF_dC[jc] = -stack.transmissibility * dDensMean_dC[jc] * gravTimesDz; - } - - // Step 3.3: computation of the mobility - // We do that before the if/else statement to be able to pass it to the compFluxOpKernel - - // recomputing the exact mobility at the face would be quite complex, as it would require: - // 1) computing the saturation - // 2) computing the relperm - // 3) computing the mobility as \lambda_p = \rho_p kr_p( S_p ) / \mu_p - // the second step in particular would require yet another dispatch to get the relperm model - // so, for simplicity, we approximate the face mobility as - // \lambda^approx_p = \rho_p S_p / \mu_p - // = \rho_p ( (nu_p / rho_p) * rho_t ) / \mu_p (plugging the expression of saturation) - // = \nu_p * rho_t / \mu_p - // fortunately, we don't need the derivatives - real64 const facePhaseMob = ( facePhaseFrac[0][0][ip] > 0.0 ) - ? facePhaseFrac[0][0][ip] * faceTotalDens / facePhaseVisc[0][0][ip] - : 0.0; - - // *** upwinding *** - // Step 3.4: upwinding based on the sign of the phase potential gradient - // It is easier to hard-code the if/else because it is difficult to address elem and face variables in a uniform way - - if( potDif >= 0 ) // the element is upstream - { - - // compute the phase flux and derivatives using the element mobility - phaseFlux = m_phaseMob[er][esr][ei][ip] * f; - dPhaseFlux_dP = m_phaseMob[er][esr][ei][ip] * dF_dP + m_dPhaseMob[er][esr][ei][ip][Deriv::dP] * f; - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseFlux_dC[jc] = - m_phaseMob[er][esr][ei][ip] * dF_dC[jc] + m_dPhaseMob[er][esr][ei][ip][Deriv::dC+jc] * f; - } - - // slice some constitutive arrays to avoid too much indexing in component loop - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub = - m_phaseCompFrac[er][esr][ei][0][ip]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub = - m_dPhaseCompFrac[er][esr][ei][0][ip]; - - // compute component fluxes and derivatives using element composition - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const ycp = phaseCompFracSub[ic]; - stack.compFlux[ic] += phaseFlux * ycp; - stack.dCompFlux_dP[ic] += dPhaseFlux_dP * ycp + phaseFlux * dPhaseCompFracSub[ic][Deriv::dP]; - - applyChainRule( numComp, - m_dCompFrac_dCompDens[er][esr][ei], - dPhaseCompFracSub[ic], - dProp_dC, - Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.dCompFlux_dC[ic][jc] += dPhaseFlux_dC[jc] * ycp + phaseFlux * dProp_dC[jc]; - } - } - - } - else // the face is upstream - { - - // compute the phase flux and derivatives using the approximated face mobility - // we only have to take derivatives of the potential gradient in this case - phaseFlux = facePhaseMob * f; - dPhaseFlux_dP = facePhaseMob * dF_dP; - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseFlux_dC[jc] = facePhaseMob * dF_dC[jc]; - } - - // compute component fluxes and derivatives using the face composition - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const ycp = facePhaseCompFrac[0][0][ip][ic]; - stack.compFlux[ic] += phaseFlux * ycp; - stack.dCompFlux_dP[ic] += dPhaseFlux_dP * ycp; - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.dCompFlux_dC[ic][jc] += dPhaseFlux_dC[jc] * ycp; - } - } - } - - // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives - // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase - compFluxKernelOp( ip, er, esr, ei, kf, f, - facePhaseMob, facePhaseEnthalpy[0][0], facePhaseCompFrac[0][0], - phaseFlux, dPhaseFlux_dP, dPhaseFlux_dC ); - - } - - // *** end of upwinding - - // Step 4: populate local flux vector and derivatives - for( integer ic = 0; ic < numComp; ++ic ) - { - stack.localFlux[ic] = m_dt * stack.compFlux[ic]; - stack.localFluxJacobian[ic][0] = m_dt * stack.dCompFlux_dP[ic]; - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.localFluxJacobian[ic][jc+1] = m_dt * stack.dCompFlux_dC[ic][jc]; - } - } - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void complete( localIndex const iconn, - StackVariables & stack, - FUNC && assemblyKernelOp = NoOpFunc{} ) const - { - using namespace compositionalMultiphaseUtilities; - using Order = BoundaryStencil::Order; - - if( AbstractBase::m_kernelFlags.isSet( FaceBasedAssemblyKernelFlags::TotalMassEquation ) ) - { - // Apply equation/variable change transformation(s) - real64 work[numDof]{}; - shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numDof, stack.localFluxJacobian, work ); - shiftElementsAheadByOneAndReplaceFirstElementWithSum( numComp, stack.localFlux ); - } - - // add contribution to residual and jacobian into: - // - the component mass balance equations (i = 0 to i = numComp-1) - // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels - if( m_ghostRank[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )] < 0 ) - { - globalIndex const globalRow = m_dofNumber[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )]; - localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); - GEOS_ASSERT_GE( localRow, 0 ); - GEOS_ASSERT_GT( AbstractBase::m_localMatrix.numRows(), localRow + numComp ); - - for( integer ic = 0; ic < numComp; ++ic ) - { - RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + ic], stack.localFlux[ic] ); - AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > - ( localRow + ic, - stack.dofColIndices, - stack.localFluxJacobian[ic], - numDof ); - } - - // call the lambda to assemble additional terms, such as thermal terms - assemblyKernelOp( localRow ); - } - } - -protected: - - /// Views on face pressure, temperature, and composition - arrayView1d< real64 const > const m_facePres; - arrayView1d< real64 const > const m_faceTemp; - arrayView2d< real64 const, compflow::USD_COMP > const m_faceCompFrac; - - /// View on the face gravity coefficient - arrayView1d< real64 const > const m_faceGravCoef; - - /// Reference to the fluid wrapper - FLUIDWRAPPER const m_fluidWrapper; - -}; - - -/** - * @class DirichletFaceBasedAssemblyKernelFactory - */ -class DirichletFaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] solverName name of the solver (to name accessors) - * @param[in] faceManager reference to the face manager - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the boundary stencil wrapper - * @param[in] fluidBase the multifluid constitutive model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY > - static void - createAndLaunch( integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - integer const useTotalMassEquation, - string const & dofKey, - string const & solverName, - FaceManager const & faceManager, - ElementRegionManager const & elemManager, - BoundaryStencilWrapper const & stencilWrapper, - constitutive::MultiFluidBase & fluidBase, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - constitutive::constitutiveComponentUpdatePassThru( fluidBase, numComps, [&]( auto & fluid, auto NC ) - { - using FluidType = TYPEOFREF( fluid ); - typename FluidType::KernelWrapper const fluidWrapper = fluid.createKernelWrapper(); - - integer constexpr NUM_COMP = NC(); - integer constexpr NUM_DOF = NC() + 1; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - // for now, we neglect capillary pressure in the kernel - BitFlags< FaceBasedAssemblyKernelFlags > kernelFlags; - if( useTotalMassEquation ) - kernelFlags.set( FaceBasedAssemblyKernelFlags::TotalMassEquation ); - - using kernelType = DirichletFaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, typename FluidType::KernelWrapper >; - typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); - typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); - typename kernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); - typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); - - kernelType kernel( numPhases, rankOffset, faceManager, stencilWrapper, fluidWrapper, - dofNumberAccessor, compFlowAccessors, multiFluidAccessors, capPressureAccessors, permeabilityAccessors, - dt, localMatrix, localRhs, kernelFlags ); - kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); - } ); - } -}; - - -/******************************** CFLFluxKernel ********************************/ - -/** - * @brief Functions to compute the (outflux) total volumetric flux needed in the calculation of CFL numbers - */ -struct CFLFluxKernel -{ - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - template< typename VIEWTYPE > - using ElementView = ElementRegionManager::ElementView< VIEWTYPE >; - - using CompFlowAccessors = - StencilAccessors< fields::flow::pressure, - fields::flow::gravityCoefficient, - fields::flow::phaseVolumeFraction, - fields::flow::phaseOutflux, - fields::flow::componentOutflux >; - - using MultiFluidAccessors = - StencilMaterialAccessors< constitutive::MultiFluidBase, - fields::multifluid::phaseViscosity, - fields::multifluid::phaseDensity, - fields::multifluid::phaseMassDensity, - fields::multifluid::phaseCompFraction >; - - using PermeabilityAccessors = - StencilMaterialAccessors< constitutive::PermeabilityBase, - fields::permeability::permeability, - fields::permeability::dPerm_dPressure >; - - - using RelPermAccessors = - StencilMaterialAccessors< constitutive::RelativePermeabilityBase, fields::relperm::phaseRelPerm >; - - template< integer NC, localIndex NUM_ELEMS, localIndex maxStencilSize > - GEOS_HOST_DEVICE - inline - static void - compute( integer const numPhases, - localIndex const stencilSize, - real64 const dt, - arraySlice1d< localIndex const > const seri, - arraySlice1d< localIndex const > const sesri, - arraySlice1d< localIndex const > const sei, - real64 const (&transmissibility)[2], - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, - ElementViewConst< arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > > const & phaseRelPerm, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseVisc, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseDens, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, - ElementView< arrayView2d< real64, compflow::USD_PHASE > > const & phaseOutflux, - ElementView< arrayView2d< real64, compflow::USD_COMP > > const & compOutflux ); - - template< integer NC, typename STENCILWRAPPER_TYPE > - static void - launch( integer const numPhases, - real64 const dt, - STENCILWRAPPER_TYPE const & stencil, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, - ElementViewConst< arrayView3d< real64 const > > const & permeability, - ElementViewConst< arrayView3d< real64 const > > const & dPerm_dPres, - ElementViewConst< arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > > const & phaseRelPerm, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseVisc, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseDens, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, - ElementView< arrayView2d< real64, compflow::USD_PHASE > > const & phaseOutflux, - ElementView< arrayView2d< real64, compflow::USD_COMP > > const & compOutflux ); -}; - -/******************************** CFLKernel ********************************/ - -/** - * @brief Functions to compute the CFL number using the phase volumetric outflux and the component mass outflux in each cell - */ -struct CFLKernel -{ - - static constexpr real64 minPhaseMobility = 1e-12; - static constexpr real64 minComponentFraction = 1e-12; - - template< integer NP > - GEOS_HOST_DEVICE - inline - static void - computePhaseCFL( real64 const poreVol, - arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac, - arraySlice1d< real64 const, constitutive::relperm::USD_RELPERM - 2 > phaseRelPerm, - arraySlice2d< real64 const, constitutive::relperm::USD_RELPERM_DS - 2 > dPhaseRelPerm_dPhaseVolFrac, - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseVisc, - arraySlice1d< real64 const, compflow::USD_PHASE- 1 > phaseOutflux, - real64 & phaseCFLNumber ); - - template< integer NC > - GEOS_HOST_DEVICE - inline - static void - computeCompCFL( real64 const poreVol, - arraySlice1d< real64 const, compflow::USD_COMP - 1 > compDens, - arraySlice1d< real64 const, compflow::USD_COMP - 1 > compFrac, - arraySlice1d< real64 const, compflow::USD_COMP - 1 > compOutflux, - real64 & compCFLNumber ); - - template< integer NC, integer NP > - static void - launch( localIndex const size, - arrayView1d< real64 const > const & volume, - arrayView2d< real64 const > const & porosity, - arrayView2d< real64 const, compflow::USD_COMP > const & compDens, - arrayView2d< real64 const, compflow::USD_COMP > const & compFrac, - arrayView2d< real64 const, compflow::USD_PHASE > const & phaseVolFrac, - arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > const & phaseRelPerm, - arrayView4d< real64 const, constitutive::relperm::USD_RELPERM_DS > const & dPhaseRelPerm_dPhaseVolFrac, - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const & phaseVisc, - arrayView2d< real64 const, compflow::USD_PHASE > const & phaseOutflux, - arrayView2d< real64 const, compflow::USD_COMP > const & compOutflux, - arrayView1d< real64 > const & phaseCFLNumber, - arrayView1d< real64 > const & compCFLNumber, - real64 & maxPhaseCFLNumber, - real64 & maxCompCFLNumber ); - -}; - -/******************************** AquiferBCKernel ********************************/ - -/** - * @brief Functions to assemble aquifer boundary condition contributions to residual and Jacobian - */ -struct AquiferBCKernel -{ - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using CompFlowAccessors = - StencilAccessors< fields::ghostRank, - fields::flow::pressure, - fields::flow::pressure_n, - fields::flow::gravityCoefficient, - fields::flow::phaseVolumeFraction, - fields::flow::dPhaseVolumeFraction, - fields::flow::dGlobalCompFraction_dGlobalCompDensity >; - - using MultiFluidAccessors = - StencilMaterialAccessors< constitutive::MultiFluidBase, - fields::multifluid::phaseDensity, - fields::multifluid::dPhaseDensity, - fields::multifluid::phaseCompFraction, - fields::multifluid::dPhaseCompFraction >; - - template< integer NC > - GEOS_HOST_DEVICE - inline - static void - compute( integer const numPhases, - integer const ipWater, - bool const allowAllPhasesIntoAquifer, - real64 const aquiferVolFlux, - real64 const dAquiferVolFlux_dPres, - real64 const aquiferWaterPhaseDens, - arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > phaseDens, - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > dPhaseDens, - arraySlice1d< real64 const, compflow::USD_PHASE - 1 > phaseVolFrac, - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > dPhaseVolFrac, - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 2 > phaseCompFrac, - arraySlice3d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 2 > dPhaseCompFrac, - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > dCompFrac_dCompDens, - real64 const dt, - real64 ( &localFlux )[NC], - real64 ( &localFluxJacobian )[NC][NC+1] ); - - template< integer NC > - static void - launch( integer const numPhases, - integer const ipWater, - bool const allowAllPhasesIntoAquifer, - integer const useTotalMassEquation, - BoundaryStencil const & stencil, - globalIndex const rankOffset, - ElementViewConst< arrayView1d< globalIndex const > > const & dofNumber, - AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper, - real64 const aquiferWaterPhaseDens, - arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac, - ElementViewConst< arrayView1d< integer const > > const & ghostRank, - ElementViewConst< arrayView1d< real64 const > > const & pres, - ElementViewConst< arrayView1d< real64 const > > const & pres_n, - ElementViewConst< arrayView1d< real64 const > > const & gravCoef, - ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, - ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens, - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseDens, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseDens, - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, - ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, - real64 const timeAtBeginningOfStep, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ); - -}; - -} // namespace isothermalCompositionalMultiphaseFVMKernels - -} // namespace geos - - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp index 5d288780182..f24e8ceef87 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp @@ -184,4 +184,4 @@ struct PotGrad } // namespace geos -#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_ISOTHERMALCOMPOSITIONALMULTIPHASEFVMKERNELUTILITIES_HPP +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRAD_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp index 168bb83da93..3093131fb13 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp @@ -584,13 +584,13 @@ class ElementBasedAssemblyKernelFactory }; -/******************************** FaceBasedAssemblyKernel ********************************/ +/******************************** FluxComputeKernel ********************************/ /** - * @brief Base class for FaceBasedAssemblyKernel that holds all data not dependent + * @brief Base class for FluxComputeKernel that holds all data not dependent * on template parameters (like stencil type and number of components/dofs). * - * FaceBasedAssemblyKernel is used for flux terms calculation. + * FluxComputeKernel is used for flux terms calculation. * In case mesh geometry/configuration is not changing during simulation, * all connections can be pre-computed, sorted by element, and stored. * Then, ElementBasedAssemblyKernel can be used for flux calculation: every flux will be computed twice, @@ -598,7 +598,7 @@ class ElementBasedAssemblyKernelFactory * and therefore overall performance can significantly improve * */ -class FaceBasedAssemblyKernelBase +class FluxComputeKernelBase { public: @@ -656,7 +656,7 @@ class FaceBasedAssemblyKernelBase * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - FaceBasedAssemblyKernelBase( globalIndex const rankOffset, + FluxComputeKernelBase( globalIndex const rankOffset, DofNumberAccessor const & dofNumberAccessor, CompFlowAccessors const & compFlowAccessors, PermeabilityAccessors const & permeabilityAccessors, @@ -724,7 +724,7 @@ class FaceBasedAssemblyKernelBase }; /** - * @class FaceBasedAssemblyKernel + * @class FluxComputeKernel * @tparam NUM_PHASES number of phases * @tparam NUM_COMPS number of components * @tparam ENABLE_ENERGY flag if energy balance equation is assembled @@ -732,7 +732,7 @@ class FaceBasedAssemblyKernelBase * @brief Compute flux term for an element */ template< integer NUM_PHASES, integer NUM_COMPS, bool ENABLE_ENERGY, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase +class FluxComputeKernel : public FluxComputeKernelBase { public: @@ -790,7 +790,7 @@ class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase * @param[inout] localMatrix the local CRS matrix * @param[inout] localRhs the local right-hand side vector */ - FaceBasedAssemblyKernel( globalIndex const rankOffset, + FluxComputeKernel( globalIndex const rankOffset, STENCILWRAPPER const & stencilWrapper, DofNumberAccessor const & dofNumberAccessor, CompFlowAccessors const & compFlowAccessors, @@ -799,7 +799,7 @@ class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase real64 const & transMultExp, CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) - : FaceBasedAssemblyKernelBase( rankOffset, + : FluxComputeKernelBase( rankOffset, dofNumberAccessor, compFlowAccessors, permeabilityAccessors, @@ -1168,9 +1168,9 @@ class FaceBasedAssemblyKernel : public FaceBasedAssemblyKernelBase }; /** - * @class FaceBasedAssemblyKernelFactory + * @class FluxComputeKernelFactory */ -class FaceBasedAssemblyKernelFactory +class FluxComputeKernelFactory { public: @@ -1216,7 +1216,7 @@ class FaceBasedAssemblyKernelFactory elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - using KERNEL_TYPE = FaceBasedAssemblyKernel< NUM_PHASES, NUM_COMPS, ENABLE_ENERGY, STENCILWRAPPER >; + using KERNEL_TYPE = FluxComputeKernel< NUM_PHASES, NUM_COMPS, ENABLE_ENERGY, STENCILWRAPPER >; typename KERNEL_TYPE::CompFlowAccessors compFlowAccessors( elemManager, solverName ); typename KERNEL_TYPE::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp index 059be14db29..67a37d81282 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp @@ -52,4 +52,4 @@ struct SolidInternalEnergyUpdateKernel } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALACCUMULATIONKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLIDINTERNALENERGYUPDATEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index ddef53d3bf9..42c0325a8f2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -47,11 +47,11 @@ namespace isothermalCompositionalMultiphaseBaseKernels * @class SolutionCheckKernel * @brief Define the kernel for checking the updated solution */ -class SolutionCheckKernel : public ScalingAndCheckingSystemSolutionKernelBase< integer > +class SolutionCheckKernel : public SolutionScalingAndCheckingKernelBase< integer > { public: - using Base = ScalingAndCheckingSystemSolutionKernelBase< integer >; + using Base = SolutionScalingAndCheckingKernelBase< integer >; using Base::m_rankOffset; using Base::m_numComp; using Base::m_dofNumber; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp similarity index 91% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp index e24c36797c3..8bcbb477f84 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp @@ -14,11 +14,11 @@ */ /** - * @file ScalingAndCheckingSystemSolutionKernelBase.hpp + * @file SolutionScalingAndCheckingKernelBase.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SCALINGANDCHECKINGSYSTEMSOLUTIONKERNELBASE_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SCALINGANDCHECKINGSYSTEMSOLUTIONKERNELBASE_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGKERNELBASE_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGKERNELBASE_HPP #include "codingUtilities/Utilities.hpp" #include "common/DataLayouts.hpp" @@ -42,11 +42,11 @@ namespace isothermalCompositionalMultiphaseBaseKernels { /** - * @class ScalingAndCheckingSystemSolutionKernelBase + * @class SolutionScalingAndCheckingKernelBase * @brief Define the kernel for scaling the solution and check its validity */ template< typename TYPE > -class ScalingAndCheckingSystemSolutionKernelBase +class SolutionScalingAndCheckingKernelBase { public: @@ -62,7 +62,7 @@ class ScalingAndCheckingSystemSolutionKernelBase * @param[in] pressureScalingFactor the pressure local scaling factor * @param[in] compDensScalingFactor the component local scaling factor */ - ScalingAndCheckingSystemSolutionKernelBase( globalIndex const rankOffset, + SolutionScalingAndCheckingKernelBase( globalIndex const rankOffset, integer const numComp, string const dofKey, ElementSubRegionBase const & subRegion, @@ -189,4 +189,4 @@ class ScalingAndCheckingSystemSolutionKernelBase } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SCALINGANDCHECKINGSYSTEMSOLUTIONKERNELBASE_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGKERNELBASE_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp index 53634692622..b3ae5bac125 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP -#include "physicsSolvers/fluidFlow/kernels/compositional/ScalingAndCheckingSystemSolutionKernelBase.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" namespace geos { @@ -34,11 +34,11 @@ namespace isothermalCompositionalMultiphaseBaseKernels * @class SolutionScalingKernel * @brief Define the kernel for scaling the Newton update */ -class SolutionScalingKernel : public ScalingAndCheckingSystemSolutionKernelBase< real64 > +class SolutionScalingKernel : public SolutionScalingAndCheckingKernelBase< real64 > { public: - using Base = ScalingAndCheckingSystemSolutionKernelBase< real64 >; + using Base = SolutionScalingAndCheckingKernelBase< real64 >; using Base::m_rankOffset; using Base::m_numComp; using Base::m_dofNumber; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp similarity index 92% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp index 62bab9f3a23..9986bd6cb24 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedCompositionalMultiphaseFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp @@ -14,13 +14,13 @@ */ /** - * @file StabilizedCompositionalMultiphaseFVMKernels.hpp + * @file StabilizedFluxComputeKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STABILIZEDFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STABILIZEDFLUXCOMPUTEKERNEL_HPP -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp" namespace geos { @@ -28,17 +28,17 @@ namespace geos namespace stabilizedCompositionalMultiphaseFVMKernels { -/******************************** FaceBasedAssemblyKernel ********************************/ +/******************************** FluxComputeKernel ********************************/ /** - * @class FaceBasedAssemblyKernel + * @class FluxComputeKernel * @tparam NUM_COMP number of fluid components * @tparam NUM_DOF number of degrees of freedom * @tparam STENCILWRAPPER the type of the stencil wrapper * @brief Define the interface for the assembly kernel in charge of flux terms */ template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > +class FluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > { public: @@ -51,7 +51,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne template< typename VIEWTYPE > using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelBase; + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; using DofNumberAccessor = AbstractBase::DofNumberAccessor; using CompFlowAccessors = AbstractBase::CompFlowAccessors; using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; @@ -82,7 +82,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne using AbstractBase::m_dCompFrac_dCompDens; using AbstractBase::m_pres; - using Base = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + using Base = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; using Base::numComp; using Base::numDof; using Base::numEqn; @@ -115,7 +115,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne * @param[inout] localRhs the local right-hand side vector * @param[in] kernelFlags flags packed together */ - FaceBasedAssemblyKernel( integer const numPhases, + FluxComputeKernel( integer const numPhases, globalIndex const rankOffset, STENCILWRAPPER const & stencilWrapper, DofNumberAccessor const & dofNumberAccessor, @@ -129,7 +129,7 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne real64 const & dt, CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags ) + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) : Base( numPhases, rankOffset, stencilWrapper, @@ -296,9 +296,9 @@ class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKerne }; /** - * @class FaceBasedAssemblyKernelFactory + * @class FluxComputeKernelFactory */ -class FaceBasedAssemblyKernelFactory +class FluxComputeKernelFactory { public: @@ -343,13 +343,13 @@ class FaceBasedAssemblyKernelFactory elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags; + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags; if( hasCapPressure ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::CapPressure ); + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::CapPressure ); if( useTotalMassEquation ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::TotalMassEquation ); + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::TotalMassEquation ); - using KERNEL_TYPE = FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + using KERNEL_TYPE = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; typename KERNEL_TYPE::CompFlowAccessors compFlowAccessors( elemManager, solverName ); typename KERNEL_TYPE::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); typename KERNEL_TYPE::StabCompFlowAccessors stabCompFlowAccessors( elemManager, solverName ); @@ -372,4 +372,4 @@ class FaceBasedAssemblyKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_STABILIZEDCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STABILIZEDFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp index 41caa82c81c..ae7c91fcc6e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp @@ -20,20 +20,11 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STATISTICSKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STATISTICSKERNEL_HPP -#include "codingUtilities/Utilities.hpp" #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "functions/TableFunction.hpp" -#include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" +#include "constitutive/relativePermeability/layouts.hpp" + namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp deleted file mode 100644 index efe3acdc89a..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalCompositionalMultiphaseFVMKernels.hpp +++ /dev/null @@ -1,1439 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 ThermalCompositionalMultiphaseFVMKernels.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP - -#include "physicsSolvers/fluidFlow/kernels/compositional/IsothermalCompositionalMultiphaseFVMKernels.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" - -#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" -#include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" -#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityFields.hpp" - -namespace geos -{ - -namespace thermalCompositionalMultiphaseFVMKernels -{ - -/******************************** PhaseMobilityKernel ********************************/ - -/** - * @class PhaseMobilityKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_PHASE number of fluid phases - * @brief Define the interface for the property kernel in charge of computing the phase mobilities - */ -template< integer NUM_COMP, integer NUM_PHASE > -class PhaseMobilityKernel : public isothermalCompositionalMultiphaseFVMKernels::PhaseMobilityKernel< NUM_COMP, NUM_PHASE > -{ -public: - - using Base = isothermalCompositionalMultiphaseFVMKernels::PhaseMobilityKernel< NUM_COMP, NUM_PHASE >; - using Base::numPhase; - using Base::m_dPhaseVolFrac; - using Base::m_dPhaseMob; - using Base::m_phaseDens; - using Base::m_dPhaseDens; - using Base::m_phaseVisc; - using Base::m_dPhaseVisc; - using Base::m_dPhaseRelPerm_dPhaseVolFrac; - - /** - * @brief Constructor - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] relperm the relperm model - */ - PhaseMobilityKernel( ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::RelativePermeabilityBase const & relperm ) - : Base( subRegion, fluid, relperm ) - {} - - /** - * @brief Compute the phase mobilities in an element - * @param[in] ei the element index - */ - GEOS_HOST_DEVICE - inline - void compute( localIndex const ei ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseVisc = m_phaseVisc[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseVisc = m_dPhaseVisc[ei][0]; - arraySlice2d< real64 const, constitutive::relperm::USD_RELPERM_DS - 2 > const dPhaseRelPerm_dPhaseVolFrac = m_dPhaseRelPerm_dPhaseVolFrac[ei][0]; - arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; - - Base::compute( ei, [&] ( localIndex const ip, - real64 const & phaseMob, - arraySlice1d< real64, compflow::USD_PHASE_DC - 2 > const & dPhaseMob ) - { - // Step 1: compute the derivative of relPerm[ip] wrt temperature - real64 dRelPerm_dT = 0.0; - for( integer jp = 0; jp < numPhase; ++jp ) - { - dRelPerm_dT += dPhaseRelPerm_dPhaseVolFrac[ip][jp] * dPhaseVolFrac[jp][Deriv::dT]; - } - - // Step 2: compute the derivative of phaseMob[ip] wrt temperature - dPhaseMob[Deriv::dT] = dRelPerm_dT * phaseDens[ip] / phaseVisc[ip] - + phaseMob * (dPhaseDens[ip][Deriv::dT] / phaseDens[ip] - dPhaseVisc[ip][Deriv::dT] / phaseVisc[ip] ); - } ); - } - -}; - -/** - * @class PhaseMobilityKernelFactory - */ -class PhaseMobilityKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComp the number of fluid components - * @param[in] numPhase the number of fluid phases - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - * @param[in] relperm the relperm model - */ - template< typename POLICY > - static void - createAndLaunch( integer const numComp, - integer const numPhase, - ObjectManagerBase & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::RelativePermeabilityBase const & relperm ) - { - if( numPhase == 2 ) - { - isothermalCompositionalMultiphaseBaseKernels:: - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseMobilityKernel< NUM_COMP, 2 > kernel( subRegion, fluid, relperm ); - PhaseMobilityKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - else if( numPhase == 3 ) - { - isothermalCompositionalMultiphaseBaseKernels:: - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - PhaseMobilityKernel< NUM_COMP, 3 > kernel( subRegion, fluid, relperm ); - PhaseMobilityKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - } -}; - - -/******************************** FaceBasedAssemblyKernel ********************************/ - -/** - * @class FaceBasedAssemblyKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @brief Define the interface for the assembly kernel in charge of flux terms - */ -template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > -class FaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > -{ -public: - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelBase; - using DofNumberAccessor = AbstractBase::DofNumberAccessor; - using CompFlowAccessors = AbstractBase::CompFlowAccessors; - using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; - using CapPressureAccessors = AbstractBase::CapPressureAccessors; - using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; - - using AbstractBase::m_dt; - using AbstractBase::m_numPhases; - using AbstractBase::m_rankOffset; - using AbstractBase::m_dofNumber; - using AbstractBase::m_gravCoef; - using AbstractBase::m_dPhaseVolFrac; - using AbstractBase::m_phaseCompFrac; - using AbstractBase::m_dPhaseCompFrac; - using AbstractBase::m_dCompFrac_dCompDens; - - using Base = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; - using Base::numComp; - using Base::numDof; - using Base::numEqn; - using Base::maxNumElems; - using Base::maxNumConns; - using Base::maxStencilSize; - using Base::numFluxSupportPoints; - using Base::m_phaseMob; - using Base::m_dPhaseMob; - using Base::m_dPhaseMassDens; - using Base::m_dPhaseCapPressure_dPhaseVolFrac; - using Base::m_stencilWrapper; - using Base::m_seri; - using Base::m_sesri; - using Base::m_sei; - - using ThermalCompFlowAccessors = - StencilAccessors< fields::flow::temperature >; - - using ThermalMultiFluidAccessors = - StencilMaterialAccessors< constitutive::MultiFluidBase, - fields::multifluid::phaseEnthalpy, - fields::multifluid::dPhaseEnthalpy >; - - using ThermalConductivityAccessors = - StencilMaterialAccessors< constitutive::MultiPhaseThermalConductivityBase, - fields::thermalconductivity::effectiveConductivity >; - // for now, we treat thermal conductivity explicitly - - /** - * @brief Constructor for the kernel interface - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dofNumberAccessor accessor for the dofs numbers - * @param[in] compFlowAccessor accessor for wrappers registered by the solver - * @param[in] thermalCompFlowAccessors accessor for *thermal* wrappers registered by the solver - * @param[in] multiFluidAccessor accessor for wrappers registered by the multifluid model - * @param[in] thermalMultiFluidAccessors accessor for *thermal* wrappers registered by the multifluid model - * @param[in] capPressureAccessors accessor for wrappers registered by the cap pressure model - * @param[in] permeabilityAccessors accessor for wrappers registered by the permeability model - * @param[in] thermalConductivityAccessors accessor for wrappers registered by the thermal conductivity model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - * @param[in] kernelFlags flags packed all together - */ - FaceBasedAssemblyKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - ThermalCompFlowAccessors const & thermalCompFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - ThermalConductivityAccessors const & thermalConductivityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags ) - : Base( numPhases, - rankOffset, - stencilWrapper, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - capPressureAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ), - m_temp( thermalCompFlowAccessors.get( fields::flow::temperature {} ) ), - m_phaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::phaseEnthalpy {} ) ), - m_dPhaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::dPhaseEnthalpy {} ) ), - m_thermalConductivity( thermalConductivityAccessors.get( fields::thermalconductivity::effectiveConductivity {} ) ) - {} - - struct StackVariables : public Base::StackVariables - { -public: - - GEOS_HOST_DEVICE - StackVariables( localIndex const size, localIndex numElems ) - : Base::StackVariables( size, numElems ) - {} - - using Base::StackVariables::stencilSize; - using Base::StackVariables::numConnectedElems; - using Base::StackVariables::transmissibility; - using Base::StackVariables::dTrans_dPres; - using Base::StackVariables::dofColIndices; - using Base::StackVariables::localFlux; - using Base::StackVariables::localFluxJacobian; - - // Thermal transmissibility (for now, no derivatives) - - real64 thermalTransmissibility[maxNumConns][2]{}; - }; - - /** - * @brief Compute the local flux contributions to the residual and Jacobian - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - inline - void computeFlux( localIndex const iconn, - StackVariables & stack ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - // *********************************************** - // First, we call the base computeFlux to compute: - // 1) compFlux and its derivatives (including derivatives wrt temperature), - // 2) enthalpy part of convectiveEnergyFlux and its derivatives (including derivatives wrt temperature) - // - // Computing dCompFlux_dT and the enthalpy flux requires quantities already computed in the base computeFlux, - // such as potGrad, phaseFlux, and the indices of the upwind cell - // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables - Base::computeFlux( iconn, stack, [&] ( integer const ip, - localIndex const (&k)[2], - localIndex const (&seri)[2], - localIndex const (&sesri)[2], - localIndex const (&sei)[2], - localIndex const connectionIndex, - localIndex const k_up, - localIndex const er_up, - localIndex const esr_up, - localIndex const ei_up, - real64 const potGrad, - real64 const phaseFlux, - real64 const (&dPhaseFlux_dP)[2], - real64 const (&dPhaseFlux_dC)[2][numComp] ) - { - // We are in the loop over phases, ip provides the current phase index. - - // Step 1: compute the derivatives of the mean density at the interface wrt temperature - - real64 dDensMean_dT[numFluxSupportPoints]{}; - - real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], - stack.transmissibility[connectionIndex][1] }; - - real64 convectiveEnergyFlux = 0.0; - real64 dConvectiveEnergyFlux_dP[numFluxSupportPoints]{}; - real64 dConvectiveEnergyFlux_dT[numFluxSupportPoints]{}; - real64 dConvectiveEnergyFlux_dC[numFluxSupportPoints][numComp]{}; - real64 dCompFlux_dT[numFluxSupportPoints][numComp]{}; - - for( integer i = 0; i < numFluxSupportPoints; ++i ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - real64 const dDens_dT = m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dT]; - dDensMean_dT[i] = 0.5 * dDens_dT; - } - - // Step 2: compute the derivatives of the phase potential difference wrt temperature - //***** calculation of flux ***** - - real64 dPresGrad_dT[numFluxSupportPoints]{}; - real64 dGravHead_dT[numFluxSupportPoints]{}; - - // compute potential difference MPFA-style - for( integer i = 0; i < numFluxSupportPoints; ++i ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - // Step 2.1: compute derivative of capillary pressure wrt temperature - real64 dCapPressure_dT = 0.0; - if( AbstractBase::m_kernelFlags.isSet( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::CapPressure ) ) - { - for( integer jp = 0; jp < m_numPhases; ++jp ) - { - real64 const dCapPressure_dS = m_dPhaseCapPressure_dPhaseVolFrac[er][esr][ei][0][ip][jp]; - dCapPressure_dT += dCapPressure_dS * m_dPhaseVolFrac[er][esr][ei][jp][Deriv::dT]; - } - } - - // Step 2.2: compute derivative of phase pressure difference wrt temperature - dPresGrad_dT[i] -= trans[i] * dCapPressure_dT; - real64 const gravD = trans[i] * m_gravCoef[er][esr][ei]; - - // Step 2.3: compute derivative of gravity potential difference wrt temperature - for( integer j = 0; j < numFluxSupportPoints; ++j ) - { - dGravHead_dT[j] += dDensMean_dT[j] * gravD; - } - } - - // Step 3: compute the derivatives of the (upwinded) compFlux wrt temperature - // *** upwinding *** - - // note: the upwinding is done in the base class, which is in charge of - // computing the following quantities: potGrad, phaseFlux, k_up, er_up, esr_up, ei_up - - real64 dPhaseFlux_dT[numFluxSupportPoints]{}; - - // Step 3.1: compute the derivative of phase flux wrt temperature - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dPhaseFlux_dT[ke] += dPresGrad_dT[ke]; - } - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dPhaseFlux_dT[ke] -= dGravHead_dT[ke]; - } - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dPhaseFlux_dT[ke] *= m_phaseMob[er_up][esr_up][ei_up][ip]; - } - dPhaseFlux_dT[k_up] += m_dPhaseMob[er_up][esr_up][ei_up][ip][Deriv::dT] * potGrad; - - // Step 3.2: compute the derivative of component flux wrt temperature - - // slice some constitutive arrays to avoid too much indexing in component loop - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 3 > phaseCompFracSub = - m_phaseCompFrac[er_up][esr_up][ei_up][0][ip]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 3 > dPhaseCompFracSub = - m_dPhaseCompFrac[er_up][esr_up][ei_up][0][ip]; - - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const ycp = phaseCompFracSub[ic]; - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dCompFlux_dT[ke][ic] += dPhaseFlux_dT[ke] * ycp; - } - dCompFlux_dT[k_up][ic] += phaseFlux * dPhaseCompFracSub[ic][Deriv::dT]; - } - - // Step 4: add dCompFlux_dTemp to localFluxJacobian - for( integer ic = 0; ic < numComp; ++ic ) - { - integer const eqIndex0 = k[0]* numEqn + ic; - integer const eqIndex1 = k[1]* numEqn + ic; - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - integer const localDofIndexTemp = k[ke] * numDof + numDof - 1; - stack.localFluxJacobian[eqIndex0][localDofIndexTemp] += m_dt * dCompFlux_dT[ke][ic]; - stack.localFluxJacobian[eqIndex1][localDofIndexTemp] -= m_dt * dCompFlux_dT[ke][ic]; - } - } - - // Step 5: compute the enthalpy flux - real64 const enthalpy = m_phaseEnthalpy[er_up][esr_up][ei_up][0][ip]; - convectiveEnergyFlux += phaseFlux * enthalpy; - - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dConvectiveEnergyFlux_dP[ke] += dPhaseFlux_dP[ke] * enthalpy; - dConvectiveEnergyFlux_dT[ke] += dPhaseFlux_dT[ke] * enthalpy; - - for( integer jc = 0; jc < numComp; ++jc ) - { - dConvectiveEnergyFlux_dC[ke][jc] += dPhaseFlux_dC[ke][jc] * enthalpy; - } - } - - dConvectiveEnergyFlux_dP[k_up] += phaseFlux * m_dPhaseEnthalpy[er_up][esr_up][ei_up][0][ip][Deriv::dP]; - dConvectiveEnergyFlux_dT[k_up] += phaseFlux * m_dPhaseEnthalpy[er_up][esr_up][ei_up][0][ip][Deriv::dT]; - - real64 dProp_dC[numComp]{}; - applyChainRule( numComp, - m_dCompFrac_dCompDens[er_up][esr_up][ei_up], - m_dPhaseEnthalpy[er_up][esr_up][ei_up][0][ip], - dProp_dC, - Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - dConvectiveEnergyFlux_dC[k_up][jc] += phaseFlux * dProp_dC[jc]; - } - - // Step 6: add convectiveFlux and its derivatives to localFlux and localFluxJacobian - integer const localRowIndexEnergy0 = k[0] * numEqn + numEqn - 1; - integer const localRowIndexEnergy1 = k[1] * numEqn + numEqn - 1; - stack.localFlux[localRowIndexEnergy0] += m_dt * convectiveEnergyFlux; - stack.localFlux[localRowIndexEnergy1] -= m_dt * convectiveEnergyFlux; - - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - integer const localDofIndexPres = k[ke] * numDof; - stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexPres] += m_dt * dConvectiveEnergyFlux_dP[ke]; - stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexPres] -= m_dt * dConvectiveEnergyFlux_dP[ke]; - integer const localDofIndexTemp = localDofIndexPres + numDof - 1; - stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexTemp] += m_dt * dConvectiveEnergyFlux_dT[ke]; - stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexTemp] -= m_dt * dConvectiveEnergyFlux_dT[ke]; - - for( integer jc = 0; jc < numComp; ++jc ) - { - integer const localDofIndexComp = localDofIndexPres + jc + 1; - stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexComp] += m_dt * dConvectiveEnergyFlux_dC[ke][jc]; - stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexComp] -= m_dt * dConvectiveEnergyFlux_dC[ke][jc]; - } - } - } ); - - // ***************************************************** - // Computation of the conduction term in the energy flux - // Note that the phase enthalpy term in the energy was computed above - // Note that this term is computed using an explicit treatment of conductivity for now - - // Step 1: compute the thermal transmissibilities at this face - // Below, the thermal conductivity used to compute (explicitly) the thermal conducivity - // To avoid modifying the signature of the "computeWeights" function for now, we pass m_thermalConductivity twice - // TODO: modify computeWeights to accomodate explicit coefficients - m_stencilWrapper.computeWeights( iconn, - m_thermalConductivity, - m_thermalConductivity, // we have to pass something here, so we just use thermal conductivity - stack.thermalTransmissibility, - stack.dTrans_dPres ); // again, we have to pass something here, but this is unused for now - - - - localIndex k[2]{}; - localIndex connectionIndex = 0; - - for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) - { - for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) - { - real64 const thermalTrans[2] = { stack.thermalTransmissibility[connectionIndex][0], stack.thermalTransmissibility[connectionIndex][1] }; - localIndex const seri[2] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; - localIndex const sesri[2] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; - localIndex const sei[2] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; - - real64 conductiveEnergyFlux = 0.0; - real64 dConductiveEnergyFlux_dT[numFluxSupportPoints]{}; - - // Step 2: compute temperature difference at the interface - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - localIndex const er = seri[ke]; - localIndex const esr = sesri[ke]; - localIndex const ei = sei[ke]; - - conductiveEnergyFlux += thermalTrans[ke] * m_temp[er][esr][ei]; - dConductiveEnergyFlux_dT[ke] += thermalTrans[ke]; - } - - // Step 3: add conductiveFlux and its derivatives to localFlux and localFluxJacobian - integer const localRowIndexEnergy0 = k[0] * numEqn + numEqn - 1; - integer const localRowIndexEnergy1 = k[1] * numEqn + numEqn - 1; - stack.localFlux[localRowIndexEnergy0] += m_dt * conductiveEnergyFlux; - stack.localFlux[localRowIndexEnergy1] -= m_dt * conductiveEnergyFlux; - - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - integer const localDofIndexTemp = k[ke] * numDof + numDof - 1; - stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexTemp] += m_dt * dConductiveEnergyFlux_dT[ke]; - stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexTemp] -= m_dt * dConductiveEnergyFlux_dT[ke]; - } - } - } - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - inline - void complete( localIndex const iconn, - StackVariables & stack ) const - { - // Call Case::complete to assemble the component mass balance equations (i = 0 to i = numDof-2) - // In the lambda, add contribution to residual and jacobian into the energy balance equation - Base::complete( iconn, stack, [&] ( integer const i, - localIndex const localRow ) - { - // beware, there is volume balance eqn in m_localRhs and m_localMatrix! - RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + numEqn], stack.localFlux[i * numEqn + numEqn-1] ); - AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > - ( localRow + numEqn, - stack.dofColIndices.data(), - stack.localFluxJacobian[i * numEqn + numEqn-1].dataIfContiguous(), - stack.stencilSize * numDof ); - - } ); - } - -protected: - - /// Views on temperature - ElementViewConst< arrayView1d< real64 const > > const m_temp; - - /// Views on phase enthalpies - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseEnthalpy; - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseEnthalpy; - - /// View on thermal conductivity - ElementViewConst< arrayView3d< real64 const > > const m_thermalConductivity; - // for now, we treat thermal conductivity explicitly - -}; - -/** - * @class FaceBasedAssemblyKernelFactory - */ -class FaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] hasCapPressure flag specifying whether capillary pressure is used or not - * @param[in] solverName name of the solver (to name accessors) - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY, typename STENCILWRAPPER > - static void - createAndLaunch( integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - string const & dofKey, - integer const hasCapPressure, - integer const useTotalMassEquation, - string const & solverName, - ElementRegionManager const & elemManager, - STENCILWRAPPER const & stencilWrapper, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - isothermalCompositionalMultiphaseBaseKernels:: - internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) - { - integer constexpr NUM_COMP = NC(); - integer constexpr NUM_DOF = NC() + 2; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags; - if( hasCapPressure ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::CapPressure ); - if( useTotalMassEquation ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::TotalMassEquation ); - - using KernelType = FaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; - typename KernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); - typename KernelType::ThermalCompFlowAccessors thermalCompFlowAccessors( elemManager, solverName ); - typename KernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); - typename KernelType::ThermalMultiFluidAccessors thermalMultiFluidAccessors( elemManager, solverName ); - typename KernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); - typename KernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); - typename KernelType::ThermalConductivityAccessors thermalConductivityAccessors( elemManager, solverName ); - - KernelType kernel( numPhases, rankOffset, stencilWrapper, dofNumberAccessor, - compFlowAccessors, thermalCompFlowAccessors, multiFluidAccessors, thermalMultiFluidAccessors, - capPressureAccessors, permeabilityAccessors, thermalConductivityAccessors, - dt, localMatrix, localRhs, kernelFlags ); - KernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); - } ); - } -}; - -/******************************** DiffusionDispersionFaceBasedAssemblyKernel ********************************/ - -/** - * @class DiffusionDispersionFaceBasedAssemblyKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @brief Define the interface for the assembly kernel in charge of diffusion/dispersion flux terms - */ -template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > -class DiffusionDispersionFaceBasedAssemblyKernel : - public isothermalCompositionalMultiphaseFVMKernels::DiffusionDispersionFaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > -{ -public: - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelBase; - using DofNumberAccessor = AbstractBase::DofNumberAccessor; - using CompFlowAccessors = AbstractBase::CompFlowAccessors; - using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; - using AbstractBase::m_dt; - using AbstractBase::m_dPhaseCompFrac; - using AbstractBase::m_dPhaseVolFrac; - - using Base = typename isothermalCompositionalMultiphaseFVMKernels::DiffusionDispersionFaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; - using DiffusionAccessors = typename Base::DiffusionAccessors; - using DispersionAccessors = typename Base::DispersionAccessors; - using PorosityAccessors = typename Base::PorosityAccessors; - using Base::numFluxSupportPoints; - using Base::numEqn; - using Base::numComp; - using Base::numDof; - using Base::m_referencePorosity; - using Base::m_phaseVolFrac; - using Base::m_phaseDens; - using Base::m_dPhaseDens; - using Base::m_phaseDiffusivityMultiplier; - - /** - * @brief Constructor for the kernel interface - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dofNumberAccessor - * @param[in] compFlowAccessors - * @param[in] multiFluidAccessors - * @param[in] diffusionAccessors - * @param[in] dispersionAccessors - * @param[in] porosityAccessors - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - * @param[in] kernelFlags flags packed together - */ - DiffusionDispersionFaceBasedAssemblyKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - DiffusionAccessors const & diffusionAccessors, - DispersionAccessors const & dispersionAccessors, - PorosityAccessors const & porosityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags ) - : Base( numPhases, - rankOffset, - stencilWrapper, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - diffusionAccessors, - dispersionAccessors, - porosityAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ) - {} - - struct StackVariables : public Base::StackVariables - { -public: - - GEOS_HOST_DEVICE - StackVariables( localIndex const size, localIndex numElems ) - : Base::StackVariables( size, numElems ) - {} - - using Base::StackVariables::transmissibility; - using Base::StackVariables::localFlux; - using Base::StackVariables::localFluxJacobian; - - }; - - /** - * @brief Compute the local diffusion flux contributions to the residual and Jacobian - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - inline - void computeDiffusionFlux( localIndex const iconn, - StackVariables & stack ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - // *********************************************** - // First, we call the base computeFlux to compute the diffusionFlux and its derivatives (including derivatives wrt temperature), - // - // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables - Base::computeDiffusionFlux( iconn, stack, [&] ( integer const ip, - integer const ic, - localIndex const (&k)[2], - localIndex const (&seri)[2], - localIndex const (&sesri)[2], - localIndex const (&sei)[2], - localIndex const connectionIndex, - localIndex const k_up, - localIndex const er_up, - localIndex const esr_up, - localIndex const ei_up, - real64 const compFracGrad, - real64 const upwindCoefficient ) - { - // We are in the loop over phases and components, ip provides the current phase index. - - real64 dCompFracGrad_dT[numFluxSupportPoints]{}; - real64 dDiffusionFlux_dT[numFluxSupportPoints]{}; - - /// compute the TPFA component difference - for( integer i = 0; i < numFluxSupportPoints; i++ ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - dCompFracGrad_dT[i] += stack.transmissibility[connectionIndex][i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dT]; - } - - // add contributions of the derivatives of component fractions wrt pressure/component fractions - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dDiffusionFlux_dT[ke] += upwindCoefficient * dCompFracGrad_dT[ke]; - } - - // add contributions of the derivatives of upwind coefficient wrt temperature - real64 const dUpwindCoefficient_dT = - m_referencePorosity[er_up][esr_up][ei_up] * - m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * - ( m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dT] * m_phaseVolFrac[er_up][esr_up][ei_up][ip] - + m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dT] ); - dDiffusionFlux_dT[k_up] += dUpwindCoefficient_dT * compFracGrad; - - // finally, increment local flux and local Jacobian - integer const eqIndex0 = k[0] * numEqn + ic; - integer const eqIndex1 = k[1] * numEqn + ic; - - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - localIndex const localDofIndexTemp = k[ke] * numDof + numComp + 1; - stack.localFluxJacobian[eqIndex0][localDofIndexTemp] += m_dt * dDiffusionFlux_dT[ke]; - stack.localFluxJacobian[eqIndex1][localDofIndexTemp] -= m_dt * dDiffusionFlux_dT[ke]; - } - } ); - } - - /** - * @brief Compute the local dispersion flux contributions to the residual and Jacobian - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - inline - void computeDispersionFlux( localIndex const iconn, - StackVariables & stack ) const - { - using Deriv = constitutive::multifluid::DerivativeOffset; - - // *********************************************** - // First, we call the base computeFlux to compute the dispersionFlux and its derivatives (including derivatives wrt temperature), - // - // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables - Base::computeDispersionFlux( iconn, stack, [&] ( integer const ip, - integer const ic, - localIndex const (&k)[2], - localIndex const (&seri)[2], - localIndex const (&sesri)[2], - localIndex const (&sei)[2], - localIndex const connectionIndex, - localIndex const k_up, - localIndex const er_up, - localIndex const esr_up, - localIndex const ei_up, - real64 const compFracGrad ) - { - // We are in the loop over phases and components, ip provides the current phase index. - - real64 dCompFracGrad_dT[numFluxSupportPoints]{}; - real64 dDispersionFlux_dT[numFluxSupportPoints]{}; - - /// compute the TPFA component difference - for( integer i = 0; i < numFluxSupportPoints; i++ ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - dCompFracGrad_dT[i] += stack.transmissibility[connectionIndex][i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dT]; - } - - // add contributions of the derivatives of component fractions wrt pressure/component fractions - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - dDispersionFlux_dT[ke] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dT[ke]; - } - - // add contributions of the derivatives of upwind coefficient wrt temperature - dDispersionFlux_dT[k_up] += m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dT] * compFracGrad; - - // finally, increment local flux and local Jacobian - integer const eqIndex0 = k[0] * numEqn + ic; - integer const eqIndex1 = k[1] * numEqn + ic; - - for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) - { - localIndex const localDofIndexTemp = k[ke] * numDof + numComp + 1; - stack.localFluxJacobian[eqIndex0][localDofIndexTemp] += m_dt * dDispersionFlux_dT[ke]; - stack.localFluxJacobian[eqIndex1][localDofIndexTemp] -= m_dt * dDispersionFlux_dT[ke]; - } - } ); - } -}; - -/** - * @class DiffusionDispersionFaceBasedAssemblyKernelFactory - */ -class DiffusionDispersionFaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] hasDiffusion flag specifying whether diffusion is used or not - * @param[in] hasDispersion flag specifying whether dispersion is used or not - * @param[in] solverName the name of the solver - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY, typename STENCILWRAPPER > - static void - createAndLaunch( integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - string const & dofKey, - integer const hasDiffusion, - integer const hasDispersion, - integer const useTotalMassEquation, - string const & solverName, - ElementRegionManager const & elemManager, - STENCILWRAPPER const & stencilWrapper, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - isothermalCompositionalMultiphaseBaseKernels:: - internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) - { - integer constexpr NUM_COMP = NC(); - integer constexpr NUM_DOF = NC() + 2; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags; - if( useTotalMassEquation ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::TotalMassEquation ); - - using kernelType = DiffusionDispersionFaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; - typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); - typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); - typename kernelType::DiffusionAccessors diffusionAccessors( elemManager, solverName ); - typename kernelType::DispersionAccessors dispersionAccessors( elemManager, solverName ); - typename kernelType::PorosityAccessors porosityAccessors( elemManager, solverName ); - - kernelType kernel( numPhases, rankOffset, stencilWrapper, - dofNumberAccessor, compFlowAccessors, multiFluidAccessors, - diffusionAccessors, dispersionAccessors, porosityAccessors, - dt, localMatrix, localRhs, kernelFlags ); - kernelType::template launch< POLICY >( stencilWrapper.size(), - hasDiffusion, hasDispersion, - kernel ); - } ); - } -}; - -/******************************** DirichletFaceBasedAssemblyKernel ********************************/ - -/** - * @class DirichletFaceBasedAssemblyKernel - * @tparam NUM_COMP number of fluid components - * @tparam NUM_DOF number of degrees of freedom - * @tparam FLUIDWRAPPER the type of the fluid wrapper - * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms - */ -template< integer NUM_COMP, integer NUM_DOF, typename FLUIDWRAPPER > -class DirichletFaceBasedAssemblyKernel : public isothermalCompositionalMultiphaseFVMKernels::DirichletFaceBasedAssemblyKernel< NUM_COMP, - NUM_DOF, - FLUIDWRAPPER > -{ -public: - - /** - * @brief The type for element-based data. Consists entirely of ArrayView's. - * - * Can be converted from ElementRegionManager::ElementViewConstAccessor - * by calling .toView() or .toViewConst() on an accessor instance - */ - template< typename VIEWTYPE > - using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; - - using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelBase; - using DofNumberAccessor = AbstractBase::DofNumberAccessor; - using CompFlowAccessors = AbstractBase::CompFlowAccessors; - using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; - using CapPressureAccessors = AbstractBase::CapPressureAccessors; - using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; - - using AbstractBase::m_dt; - using AbstractBase::m_numPhases; - using AbstractBase::m_rankOffset; - using AbstractBase::m_dofNumber; - using AbstractBase::m_gravCoef; - using AbstractBase::m_phaseCompFrac; - using AbstractBase::m_dPhaseCompFrac; - using AbstractBase::m_dCompFrac_dCompDens; - - using Base = isothermalCompositionalMultiphaseFVMKernels::DirichletFaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, FLUIDWRAPPER >; - using Base::numComp; - using Base::numDof; - using Base::numEqn; - using Base::m_phaseMob; - using Base::m_dPhaseMob; - using Base::m_dPhaseMassDens; - using Base::m_dPhaseCapPressure_dPhaseVolFrac; - using Base::m_stencilWrapper; - using Base::m_seri; - using Base::m_sesri; - using Base::m_sei; - using Base::m_faceTemp; - using Base::m_faceGravCoef; - - - using ThermalCompFlowAccessors = - StencilAccessors< fields::flow::temperature >; - - using ThermalMultiFluidAccessors = - StencilMaterialAccessors< constitutive::MultiFluidBase, - fields::multifluid::phaseEnthalpy, - fields::multifluid::dPhaseEnthalpy >; - - using ThermalConductivityAccessors = - StencilMaterialAccessors< constitutive::MultiPhaseThermalConductivityBase, - fields::thermalconductivity::effectiveConductivity >; - // for now, we treat thermal conductivity explicitly - - /** - * @brief Constructor for the kernel interface - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] faceManager the face manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] fluidWrapper reference to the fluid wrapper - * @param[in] dofNumberAccessor accessor for the dofs numbers - * @param[in] compFlowAccessor accessor for wrappers registered by the solver - * @param[in] thermalCompFlowAccessors accessor for *thermal* wrappers registered by the solver - * @param[in] multiFluidAccessor accessor for wrappers registered by the multifluid model - * @param[in] thermalMultiFluidAccessors accessor for *thermal* wrappers registered by the multifluid model - * @param[in] capPressureAccessors accessor for wrappers registered by the cap pressure model - * @param[in] permeabilityAccessors accessor for wrappers registered by the permeability model - * @param[in] thermalConductivityAccessors accessor for wrappers registered by the thermal conductivity model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - * @param[in] kernelFlags flags packed together - */ - DirichletFaceBasedAssemblyKernel( integer const numPhases, - globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - ThermalCompFlowAccessors const & thermalCompFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - ThermalConductivityAccessors const & thermalConductivityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags ) - : Base( numPhases, - rankOffset, - faceManager, - stencilWrapper, - fluidWrapper, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - capPressureAccessors, - permeabilityAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ), - m_temp( thermalCompFlowAccessors.get( fields::flow::temperature {} ) ), - m_phaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::phaseEnthalpy {} ) ), - m_dPhaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::dPhaseEnthalpy {} ) ), - m_thermalConductivity( thermalConductivityAccessors.get( fields::thermalconductivity::effectiveConductivity {} ) ) - {} - - struct StackVariables : public Base::StackVariables - { -public: - - /** - * @brief Constructor for the stack variables - * @param[in] size size of the stencil for this connection - * @param[in] numElems number of elements for this connection - */ - GEOS_HOST_DEVICE - StackVariables( localIndex const size, localIndex numElems ) - : Base::StackVariables( size, numElems ) - {} - - using Base::StackVariables::transmissibility; - using Base::StackVariables::dofColIndices; - using Base::StackVariables::localFlux; - using Base::StackVariables::localFluxJacobian; - - // Component fluxes and derivatives - - /// Derivatives of component fluxes wrt temperature - real64 dCompFlux_dT[numComp]{}; - - - // Energy fluxes and derivatives - - /// Energy fluxes - real64 energyFlux = 0.0; - /// Derivative of energy fluxes wrt pressure - real64 dEnergyFlux_dP = 0.0; - /// Derivative of energy fluxes wrt temperature - real64 dEnergyFlux_dT = 0.0; - /// Derivatives of energy fluxes wrt component densities - real64 dEnergyFlux_dC[numComp]{}; - - }; - - /** - * @brief Compute the local flux contributions to the residual and Jacobian - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void computeFlux( localIndex const iconn, - StackVariables & stack ) const - { - using Order = BoundaryStencil::Order; - using Deriv = constitutive::multifluid::DerivativeOffset; - - // *********************************************** - // First, we call the base computeFlux to compute: - // 1) compFlux and its derivatives (including derivatives wrt temperature), - // 2) enthalpy part of energyFlux and its derivatives (including derivatives wrt temperature) - // - // Computing dCompFlux_dT and the enthalpy flux requires quantities already computed in the base computeFlux, - // such as potGrad, phaseFlux, and the indices of the upwind cell - // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables - Base::computeFlux( iconn, stack, [&] ( integer const ip, - localIndex const er, - localIndex const esr, - localIndex const ei, - localIndex const kf, - real64 const f, // potGrad times trans - real64 const facePhaseMob, - arraySlice1d< const real64, constitutive::multifluid::USD_PHASE - 2 > const & facePhaseEnthalpy, - arraySlice2d< const real64, constitutive::multifluid::USD_PHASE_COMP-2 > const & facePhaseCompFrac, - real64 const phaseFlux, - real64 const dPhaseFlux_dP, - real64 const (&dPhaseFlux_dC)[numComp] ) - { - // We are in the loop over phases, ip provides the current phase index. - - // Step 1: compute the derivatives of the mean density at the interface wrt temperature - - real64 const dDensMean_dT = 0.5 * m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dT]; - - // Step 2: compute the derivatives of the phase potential difference wrt temperature - //***** calculation of flux ***** - - real64 const dF_dT = -stack.transmissibility * dDensMean_dT * ( m_gravCoef[er][esr][ei] - m_faceGravCoef[kf] ); - - // Step 3: compute the derivatives of the (upwinded) compFlux wrt temperature - // *** upwinding *** - - // note: the upwinding is done in the base class, which is in charge of - // computing the following quantities: potGrad, phaseFlux - // It is easier to hard-code the if/else because it is difficult to address elem and face variables in a uniform way - - - if( f >= 0 ) // the element is upstream - { - - // Step 3.1.a: compute the derivative of phase flux wrt temperature - real64 const dPhaseFlux_dT = m_phaseMob[er][esr][ei][ip] * dF_dT + m_dPhaseMob[er][esr][ei][ip][Deriv::dT] * f; - - // Step 3.2.a: compute the derivative of component flux wrt temperature - - // slice some constitutive arrays to avoid too much indexing in component loop - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 3 > phaseCompFracSub = - m_phaseCompFrac[er][esr][ei][0][ip]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 3 > dPhaseCompFracSub = - m_dPhaseCompFrac[er][esr][ei][0][ip]; - - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const ycp = phaseCompFracSub[ic]; - stack.dCompFlux_dT[ic] += dPhaseFlux_dT * ycp + phaseFlux * dPhaseCompFracSub[ic][Deriv::dT]; - } - - // Step 3.3.a: compute the enthalpy flux - - real64 const enthalpy = m_phaseEnthalpy[er][esr][ei][0][ip]; - stack.energyFlux += phaseFlux * enthalpy; - stack.dEnergyFlux_dP += dPhaseFlux_dP * enthalpy + phaseFlux * m_dPhaseEnthalpy[er][esr][ei][0][ip][Deriv::dP]; - stack.dEnergyFlux_dT += dPhaseFlux_dT * enthalpy + phaseFlux * m_dPhaseEnthalpy[er][esr][ei][0][ip][Deriv::dT]; - - real64 dProp_dC[numComp]{}; - applyChainRule( numComp, - m_dCompFrac_dCompDens[er][esr][ei], - m_dPhaseEnthalpy[er][esr][ei][0][ip], - dProp_dC, - Deriv::dC ); - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.dEnergyFlux_dC[jc] += dPhaseFlux_dC[jc] * enthalpy + phaseFlux * dProp_dC[jc]; - } - - } - else // the face is upstream - { - - // Step 3.1.b: compute the derivative of phase flux wrt temperature - real64 const dPhaseFlux_dT = facePhaseMob * dF_dT; - - // Step 3.2.b: compute the derivative of component flux wrt temperature - - for( integer ic = 0; ic < numComp; ++ic ) - { - real64 const ycp = facePhaseCompFrac[ip][ic]; - stack.dCompFlux_dT[ic] += dPhaseFlux_dT * ycp; - } - - // Step 3.3.b: compute the enthalpy flux - - real64 const enthalpy = facePhaseEnthalpy[ip]; - stack.energyFlux += phaseFlux * enthalpy; - stack.dEnergyFlux_dP += dPhaseFlux_dP * enthalpy; - stack.dEnergyFlux_dT += dPhaseFlux_dT * enthalpy; - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.dEnergyFlux_dC[jc] += dPhaseFlux_dC[jc] * enthalpy; - } - - } - - } ); - - // ***************************************************** - // Computation of the conduction term in the energy flux - // Note that the phase enthalpy term in the energy was computed above - // Note that this term is computed using an explicit treatment of conductivity for now - - // Step 1: compute the thermal transmissibilities at this face - // Below, the thermal conductivity used to compute (explicitly) the thermal conducivity - // To avoid modifying the signature of the "computeWeights" function for now, we pass m_thermalConductivity twice - // TODO: modify computeWeights to accomodate explicit coefficients - real64 thermalTrans = 0.0; - real64 dThermalTrans_dPerm[3]{}; // not used - m_stencilWrapper.computeWeights( iconn, - m_thermalConductivity, - thermalTrans, - dThermalTrans_dPerm ); - - // Step 2: compute temperature difference at the interface - stack.energyFlux += thermalTrans - * ( m_temp[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )] - m_faceTemp[m_sei( iconn, Order::FACE )] ); - stack.dEnergyFlux_dT += thermalTrans; - - - // ********************************************************************************** - // At this point, we have computed the energyFlux and the compFlux for all components - // We have to do two things here: - // 1) Add dCompFlux_dTemp to the localFluxJacobian of the component mass balance equations - // 2) Add energyFlux and its derivatives to the localFlux(Jacobian) of the energy balance equation - - // Step 1: add dCompFlux_dTemp to localFluxJacobian - for( integer ic = 0; ic < numComp; ++ic ) - { - stack.localFluxJacobian[ic][numDof-1] = m_dt * stack.dCompFlux_dT[ic]; - } - - // Step 2: add energyFlux and its derivatives to localFlux and localFluxJacobian - integer const localRowIndexEnergy = numEqn-1; - stack.localFlux[localRowIndexEnergy] = m_dt * stack.energyFlux; - - stack.localFluxJacobian[localRowIndexEnergy][0] = m_dt * stack.dEnergyFlux_dP; - stack.localFluxJacobian[localRowIndexEnergy][numDof-1] = m_dt * stack.dEnergyFlux_dT; - for( integer jc = 0; jc < numComp; ++jc ) - { - stack.localFluxJacobian[localRowIndexEnergy][jc+1] = m_dt * stack.dEnergyFlux_dC[jc]; - } - } - - /** - * @brief Performs the complete phase for the kernel. - * @param[in] iconn the connection index - * @param[inout] stack the stack variables - */ - GEOS_HOST_DEVICE - void complete( localIndex const iconn, - StackVariables & stack ) const - { - // Call Case::complete to assemble the component mass balance equations (i = 0 to i = numDof-2) - // In the lambda, add contribution to residual and jacobian into the energy balance equation - Base::complete( iconn, stack, [&] ( localIndex const localRow ) - { - // beware, there is volume balance eqn in m_localRhs and m_localMatrix! - RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + numEqn], stack.localFlux[numEqn-1] ); - AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > - ( localRow + numEqn, - stack.dofColIndices, - stack.localFluxJacobian[numEqn-1], - numDof ); - - } ); - } - -protected: - - /// Views on temperature - ElementViewConst< arrayView1d< real64 const > > const m_temp; - - /// Views on phase enthalpies - ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseEnthalpy; - ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseEnthalpy; - - /// View on thermal conductivity - ElementViewConst< arrayView3d< real64 const > > const m_thermalConductivity; - // for now, we treat thermal conductivity explicitly - -}; - -/** - * @class DirichletFaceBasedAssemblyKernelFactory - */ -class DirichletFaceBasedAssemblyKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @tparam STENCILWRAPPER the type of the stencil wrapper - * @param[in] numComps the number of fluid components - * @param[in] numPhases the number of fluid phases - * @param[in] rankOffset the offset of my MPI rank - * @param[in] dofKey string to get the element degrees of freedom numbers - * @param[in] solverName name of the solver (to name accessors) - * @param[in] faceManager reference to the face manager - * @param[in] elemManager reference to the element region manager - * @param[in] stencilWrapper reference to the stencil wrapper - * @param[in] fluidBase the multifluid constitutive model - * @param[in] dt time step size - * @param[inout] localMatrix the local CRS matrix - * @param[inout] localRhs the local right-hand side vector - */ - template< typename POLICY, typename STENCILWRAPPER > - static void - createAndLaunch( integer const numComps, - integer const numPhases, - globalIndex const rankOffset, - integer const useTotalMassEquation, - string const & dofKey, - string const & solverName, - FaceManager const & faceManager, - ElementRegionManager const & elemManager, - STENCILWRAPPER const & stencilWrapper, - constitutive::MultiFluidBase & fluidBase, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) - { - constitutive::constitutiveComponentUpdatePassThru< true >( fluidBase, numComps, [&]( auto & fluid, auto NC ) - { - using FluidType = TYPEOFREF( fluid ); - typename FluidType::KernelWrapper const fluidWrapper = fluid.createKernelWrapper(); - - integer constexpr NUM_COMP = NC(); - integer constexpr NUM_DOF = NC() + 2; - - ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = - elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); - dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); - - // for now, we neglect capillary pressure in the kernel - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags > kernelFlags; - if( useTotalMassEquation ) - kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FaceBasedAssemblyKernelFlags::TotalMassEquation ); - - using KernelType = DirichletFaceBasedAssemblyKernel< NUM_COMP, NUM_DOF, typename FluidType::KernelWrapper >; - typename KernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); - typename KernelType::ThermalCompFlowAccessors thermalCompFlowAccessors( elemManager, solverName ); - typename KernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); - typename KernelType::ThermalMultiFluidAccessors thermalMultiFluidAccessors( elemManager, solverName ); - typename KernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); - typename KernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); - typename KernelType::ThermalConductivityAccessors thermalConductivityAccessors( elemManager, solverName ); - - KernelType kernel( numPhases, rankOffset, faceManager, stencilWrapper, fluidWrapper, - dofNumberAccessor, compFlowAccessors, thermalCompFlowAccessors, multiFluidAccessors, thermalMultiFluidAccessors, - capPressureAccessors, permeabilityAccessors, thermalConductivityAccessors, - dt, localMatrix, localRhs, kernelFlags ); - KernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); - } ); - } -}; - - -} // namespace thermalCompositionalMultiphaseFVMKernels - -} // namespace geos - - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_THERMALCOMPOSITIONALMULTIPHASEFVMKERNELS_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp new file mode 100644 index 00000000000..59a075990d5 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp @@ -0,0 +1,352 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalDiffusionDispersionFluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALDIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALDIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseFVMKernels +{ + +/******************************** DiffusionDispersionFluxComputeKernel ********************************/ + +/** + * @class DiffusionDispersionFluxComputeKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @brief Define the interface for the assembly kernel in charge of diffusion/dispersion flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > +class DiffusionDispersionFluxComputeKernel : + public isothermalCompositionalMultiphaseFVMKernels::DiffusionDispersionFluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > +{ +public: + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; + using DofNumberAccessor = AbstractBase::DofNumberAccessor; + using CompFlowAccessors = AbstractBase::CompFlowAccessors; + using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; + using AbstractBase::m_dt; + using AbstractBase::m_dPhaseCompFrac; + using AbstractBase::m_dPhaseVolFrac; + + using Base = typename isothermalCompositionalMultiphaseFVMKernels::DiffusionDispersionFluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + using DiffusionAccessors = typename Base::DiffusionAccessors; + using DispersionAccessors = typename Base::DispersionAccessors; + using PorosityAccessors = typename Base::PorosityAccessors; + using Base::numFluxSupportPoints; + using Base::numEqn; + using Base::numComp; + using Base::numDof; + using Base::m_referencePorosity; + using Base::m_phaseVolFrac; + using Base::m_phaseDens; + using Base::m_dPhaseDens; + using Base::m_phaseDiffusivityMultiplier; + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dofNumberAccessor + * @param[in] compFlowAccessors + * @param[in] multiFluidAccessors + * @param[in] diffusionAccessors + * @param[in] dispersionAccessors + * @param[in] porosityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed together + */ + DiffusionDispersionFluxComputeKernel( integer const numPhases, + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + DiffusionAccessors const & diffusionAccessors, + DispersionAccessors const & dispersionAccessors, + PorosityAccessors const & porosityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) + : Base( numPhases, + rankOffset, + stencilWrapper, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + diffusionAccessors, + dispersionAccessors, + porosityAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ) + {} + + struct StackVariables : public Base::StackVariables + { +public: + + GEOS_HOST_DEVICE + StackVariables( localIndex const size, localIndex numElems ) + : Base::StackVariables( size, numElems ) + {} + + using Base::StackVariables::transmissibility; + using Base::StackVariables::localFlux; + using Base::StackVariables::localFluxJacobian; + + }; + + /** + * @brief Compute the local diffusion flux contributions to the residual and Jacobian + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + inline + void computeDiffusionFlux( localIndex const iconn, + StackVariables & stack ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + // *********************************************** + // First, we call the base computeFlux to compute the diffusionFlux and its derivatives (including derivatives wrt temperature), + // + // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables + Base::computeDiffusionFlux( iconn, stack, [&] ( integer const ip, + integer const ic, + localIndex const (&k)[2], + localIndex const (&seri)[2], + localIndex const (&sesri)[2], + localIndex const (&sei)[2], + localIndex const connectionIndex, + localIndex const k_up, + localIndex const er_up, + localIndex const esr_up, + localIndex const ei_up, + real64 const compFracGrad, + real64 const upwindCoefficient ) + { + // We are in the loop over phases and components, ip provides the current phase index. + + real64 dCompFracGrad_dT[numFluxSupportPoints]{}; + real64 dDiffusionFlux_dT[numFluxSupportPoints]{}; + + /// compute the TPFA component difference + for( integer i = 0; i < numFluxSupportPoints; i++ ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + dCompFracGrad_dT[i] += stack.transmissibility[connectionIndex][i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dT]; + } + + // add contributions of the derivatives of component fractions wrt pressure/component fractions + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dDiffusionFlux_dT[ke] += upwindCoefficient * dCompFracGrad_dT[ke]; + } + + // add contributions of the derivatives of upwind coefficient wrt temperature + real64 const dUpwindCoefficient_dT = + m_referencePorosity[er_up][esr_up][ei_up] * + m_phaseDiffusivityMultiplier[er_up][esr_up][ei_up][0][ip] * + ( m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dT] * m_phaseVolFrac[er_up][esr_up][ei_up][ip] + + m_phaseDens[er_up][esr_up][ei_up][0][ip] * m_dPhaseVolFrac[er_up][esr_up][ei_up][ip][Deriv::dT] ); + dDiffusionFlux_dT[k_up] += dUpwindCoefficient_dT * compFracGrad; + + // finally, increment local flux and local Jacobian + integer const eqIndex0 = k[0] * numEqn + ic; + integer const eqIndex1 = k[1] * numEqn + ic; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + localIndex const localDofIndexTemp = k[ke] * numDof + numComp + 1; + stack.localFluxJacobian[eqIndex0][localDofIndexTemp] += m_dt * dDiffusionFlux_dT[ke]; + stack.localFluxJacobian[eqIndex1][localDofIndexTemp] -= m_dt * dDiffusionFlux_dT[ke]; + } + } ); + } + + /** + * @brief Compute the local dispersion flux contributions to the residual and Jacobian + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + inline + void computeDispersionFlux( localIndex const iconn, + StackVariables & stack ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + // *********************************************** + // First, we call the base computeFlux to compute the dispersionFlux and its derivatives (including derivatives wrt temperature), + // + // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables + Base::computeDispersionFlux( iconn, stack, [&] ( integer const ip, + integer const ic, + localIndex const (&k)[2], + localIndex const (&seri)[2], + localIndex const (&sesri)[2], + localIndex const (&sei)[2], + localIndex const connectionIndex, + localIndex const k_up, + localIndex const er_up, + localIndex const esr_up, + localIndex const ei_up, + real64 const compFracGrad ) + { + // We are in the loop over phases and components, ip provides the current phase index. + + real64 dCompFracGrad_dT[numFluxSupportPoints]{}; + real64 dDispersionFlux_dT[numFluxSupportPoints]{}; + + /// compute the TPFA component difference + for( integer i = 0; i < numFluxSupportPoints; i++ ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + dCompFracGrad_dT[i] += stack.transmissibility[connectionIndex][i] * m_dPhaseCompFrac[er][esr][ei][0][ip][ic][Deriv::dT]; + } + + // add contributions of the derivatives of component fractions wrt pressure/component fractions + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dDispersionFlux_dT[ke] += m_phaseDens[er_up][esr_up][ei_up][0][ip] * dCompFracGrad_dT[ke]; + } + + // add contributions of the derivatives of upwind coefficient wrt temperature + dDispersionFlux_dT[k_up] += m_dPhaseDens[er_up][esr_up][ei_up][0][ip][Deriv::dT] * compFracGrad; + + // finally, increment local flux and local Jacobian + integer const eqIndex0 = k[0] * numEqn + ic; + integer const eqIndex1 = k[1] * numEqn + ic; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + localIndex const localDofIndexTemp = k[ke] * numDof + numComp + 1; + stack.localFluxJacobian[eqIndex0][localDofIndexTemp] += m_dt * dDispersionFlux_dT[ke]; + stack.localFluxJacobian[eqIndex1][localDofIndexTemp] -= m_dt * dDispersionFlux_dT[ke]; + } + } ); + } +}; + +/** + * @class DiffusionDispersionFluxComputeKernelFactory + */ +class DiffusionDispersionFluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] hasDiffusion flag specifying whether diffusion is used or not + * @param[in] hasDispersion flag specifying whether dispersion is used or not + * @param[in] solverName the name of the solver + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename STENCILWRAPPER > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + string const & dofKey, + integer const hasDiffusion, + integer const hasDispersion, + integer const useTotalMassEquation, + string const & solverName, + ElementRegionManager const & elemManager, + STENCILWRAPPER const & stencilWrapper, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + isothermalCompositionalMultiphaseBaseKernels:: + internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) + { + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 2; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags; + if( useTotalMassEquation ) + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::TotalMassEquation ); + + using kernelType = DiffusionDispersionFluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename kernelType::DiffusionAccessors diffusionAccessors( elemManager, solverName ); + typename kernelType::DispersionAccessors dispersionAccessors( elemManager, solverName ); + typename kernelType::PorosityAccessors porosityAccessors( elemManager, solverName ); + + kernelType kernel( numPhases, rankOffset, stencilWrapper, + dofNumberAccessor, compFlowAccessors, multiFluidAccessors, + diffusionAccessors, dispersionAccessors, porosityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + kernelType::template launch< POLICY >( stencilWrapper.size(), + hasDiffusion, hasDispersion, + kernel ); + } ); + } +}; + +} // namespace thermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALDIFFUSIONDISPERSIONFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp new file mode 100644 index 00000000000..0bfa4ea0380 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp @@ -0,0 +1,486 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalDirichletFluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALDIRICHLETFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALDIRICHLETFLUXCOMPUTEKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" + +#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" +#include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" +#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityFields.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseFVMKernels +{ + +/******************************** DirichletFluxComputeKernel ********************************/ + +/** + * @class DirichletFluxComputeKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam FLUIDWRAPPER the type of the fluid wrapper + * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename FLUIDWRAPPER > +class DirichletFluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::DirichletFluxComputeKernel< NUM_COMP, + NUM_DOF, + FLUIDWRAPPER > +{ +public: + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; + using DofNumberAccessor = AbstractBase::DofNumberAccessor; + using CompFlowAccessors = AbstractBase::CompFlowAccessors; + using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; + using CapPressureAccessors = AbstractBase::CapPressureAccessors; + using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; + + using AbstractBase::m_dt; + using AbstractBase::m_numPhases; + using AbstractBase::m_rankOffset; + using AbstractBase::m_dofNumber; + using AbstractBase::m_gravCoef; + using AbstractBase::m_phaseCompFrac; + using AbstractBase::m_dPhaseCompFrac; + using AbstractBase::m_dCompFrac_dCompDens; + + using Base = isothermalCompositionalMultiphaseFVMKernels::DirichletFluxComputeKernel< NUM_COMP, NUM_DOF, FLUIDWRAPPER >; + using Base::numComp; + using Base::numDof; + using Base::numEqn; + using Base::m_phaseMob; + using Base::m_dPhaseMob; + using Base::m_dPhaseMassDens; + using Base::m_dPhaseCapPressure_dPhaseVolFrac; + using Base::m_stencilWrapper; + using Base::m_seri; + using Base::m_sesri; + using Base::m_sei; + using Base::m_faceTemp; + using Base::m_faceGravCoef; + + + using ThermalCompFlowAccessors = + StencilAccessors< fields::flow::temperature >; + + using ThermalMultiFluidAccessors = + StencilMaterialAccessors< constitutive::MultiFluidBase, + fields::multifluid::phaseEnthalpy, + fields::multifluid::dPhaseEnthalpy >; + + using ThermalConductivityAccessors = + StencilMaterialAccessors< constitutive::MultiPhaseThermalConductivityBase, + fields::thermalconductivity::effectiveConductivity >; + // for now, we treat thermal conductivity explicitly + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] faceManager the face manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] fluidWrapper reference to the fluid wrapper + * @param[in] dofNumberAccessor accessor for the dofs numbers + * @param[in] compFlowAccessor accessor for wrappers registered by the solver + * @param[in] thermalCompFlowAccessors accessor for *thermal* wrappers registered by the solver + * @param[in] multiFluidAccessor accessor for wrappers registered by the multifluid model + * @param[in] thermalMultiFluidAccessors accessor for *thermal* wrappers registered by the multifluid model + * @param[in] capPressureAccessors accessor for wrappers registered by the cap pressure model + * @param[in] permeabilityAccessors accessor for wrappers registered by the permeability model + * @param[in] thermalConductivityAccessors accessor for wrappers registered by the thermal conductivity model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed together + */ + DirichletFluxComputeKernel( integer const numPhases, + globalIndex const rankOffset, + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + ThermalCompFlowAccessors const & thermalCompFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + ThermalConductivityAccessors const & thermalConductivityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) + : Base( numPhases, + rankOffset, + faceManager, + stencilWrapper, + fluidWrapper, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + capPressureAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), + m_temp( thermalCompFlowAccessors.get( fields::flow::temperature {} ) ), + m_phaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::phaseEnthalpy {} ) ), + m_dPhaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::dPhaseEnthalpy {} ) ), + m_thermalConductivity( thermalConductivityAccessors.get( fields::thermalconductivity::effectiveConductivity {} ) ) + {} + + struct StackVariables : public Base::StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const size, localIndex numElems ) + : Base::StackVariables( size, numElems ) + {} + + using Base::StackVariables::transmissibility; + using Base::StackVariables::dofColIndices; + using Base::StackVariables::localFlux; + using Base::StackVariables::localFluxJacobian; + + // Component fluxes and derivatives + + /// Derivatives of component fluxes wrt temperature + real64 dCompFlux_dT[numComp]{}; + + + // Energy fluxes and derivatives + + /// Energy fluxes + real64 energyFlux = 0.0; + /// Derivative of energy fluxes wrt pressure + real64 dEnergyFlux_dP = 0.0; + /// Derivative of energy fluxes wrt temperature + real64 dEnergyFlux_dT = 0.0; + /// Derivatives of energy fluxes wrt component densities + real64 dEnergyFlux_dC[numComp]{}; + + }; + + /** + * @brief Compute the local flux contributions to the residual and Jacobian + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void computeFlux( localIndex const iconn, + StackVariables & stack ) const + { + using Order = BoundaryStencil::Order; + using Deriv = constitutive::multifluid::DerivativeOffset; + + // *********************************************** + // First, we call the base computeFlux to compute: + // 1) compFlux and its derivatives (including derivatives wrt temperature), + // 2) enthalpy part of energyFlux and its derivatives (including derivatives wrt temperature) + // + // Computing dCompFlux_dT and the enthalpy flux requires quantities already computed in the base computeFlux, + // such as potGrad, phaseFlux, and the indices of the upwind cell + // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables + Base::computeFlux( iconn, stack, [&] ( integer const ip, + localIndex const er, + localIndex const esr, + localIndex const ei, + localIndex const kf, + real64 const f, // potGrad times trans + real64 const facePhaseMob, + arraySlice1d< const real64, constitutive::multifluid::USD_PHASE - 2 > const & facePhaseEnthalpy, + arraySlice2d< const real64, constitutive::multifluid::USD_PHASE_COMP-2 > const & facePhaseCompFrac, + real64 const phaseFlux, + real64 const dPhaseFlux_dP, + real64 const (&dPhaseFlux_dC)[numComp] ) + { + // We are in the loop over phases, ip provides the current phase index. + + // Step 1: compute the derivatives of the mean density at the interface wrt temperature + + real64 const dDensMean_dT = 0.5 * m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dT]; + + // Step 2: compute the derivatives of the phase potential difference wrt temperature + //***** calculation of flux ***** + + real64 const dF_dT = -stack.transmissibility * dDensMean_dT * ( m_gravCoef[er][esr][ei] - m_faceGravCoef[kf] ); + + // Step 3: compute the derivatives of the (upwinded) compFlux wrt temperature + // *** upwinding *** + + // note: the upwinding is done in the base class, which is in charge of + // computing the following quantities: potGrad, phaseFlux + // It is easier to hard-code the if/else because it is difficult to address elem and face variables in a uniform way + + + if( f >= 0 ) // the element is upstream + { + + // Step 3.1.a: compute the derivative of phase flux wrt temperature + real64 const dPhaseFlux_dT = m_phaseMob[er][esr][ei][ip] * dF_dT + m_dPhaseMob[er][esr][ei][ip][Deriv::dT] * f; + + // Step 3.2.a: compute the derivative of component flux wrt temperature + + // slice some constitutive arrays to avoid too much indexing in component loop + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 3 > phaseCompFracSub = + m_phaseCompFrac[er][esr][ei][0][ip]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 3 > dPhaseCompFracSub = + m_dPhaseCompFrac[er][esr][ei][0][ip]; + + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = phaseCompFracSub[ic]; + stack.dCompFlux_dT[ic] += dPhaseFlux_dT * ycp + phaseFlux * dPhaseCompFracSub[ic][Deriv::dT]; + } + + // Step 3.3.a: compute the enthalpy flux + + real64 const enthalpy = m_phaseEnthalpy[er][esr][ei][0][ip]; + stack.energyFlux += phaseFlux * enthalpy; + stack.dEnergyFlux_dP += dPhaseFlux_dP * enthalpy + phaseFlux * m_dPhaseEnthalpy[er][esr][ei][0][ip][Deriv::dP]; + stack.dEnergyFlux_dT += dPhaseFlux_dT * enthalpy + phaseFlux * m_dPhaseEnthalpy[er][esr][ei][0][ip][Deriv::dT]; + + real64 dProp_dC[numComp]{}; + applyChainRule( numComp, + m_dCompFrac_dCompDens[er][esr][ei], + m_dPhaseEnthalpy[er][esr][ei][0][ip], + dProp_dC, + Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.dEnergyFlux_dC[jc] += dPhaseFlux_dC[jc] * enthalpy + phaseFlux * dProp_dC[jc]; + } + + } + else // the face is upstream + { + + // Step 3.1.b: compute the derivative of phase flux wrt temperature + real64 const dPhaseFlux_dT = facePhaseMob * dF_dT; + + // Step 3.2.b: compute the derivative of component flux wrt temperature + + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = facePhaseCompFrac[ip][ic]; + stack.dCompFlux_dT[ic] += dPhaseFlux_dT * ycp; + } + + // Step 3.3.b: compute the enthalpy flux + + real64 const enthalpy = facePhaseEnthalpy[ip]; + stack.energyFlux += phaseFlux * enthalpy; + stack.dEnergyFlux_dP += dPhaseFlux_dP * enthalpy; + stack.dEnergyFlux_dT += dPhaseFlux_dT * enthalpy; + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.dEnergyFlux_dC[jc] += dPhaseFlux_dC[jc] * enthalpy; + } + + } + + } ); + + // ***************************************************** + // Computation of the conduction term in the energy flux + // Note that the phase enthalpy term in the energy was computed above + // Note that this term is computed using an explicit treatment of conductivity for now + + // Step 1: compute the thermal transmissibilities at this face + // Below, the thermal conductivity used to compute (explicitly) the thermal conducivity + // To avoid modifying the signature of the "computeWeights" function for now, we pass m_thermalConductivity twice + // TODO: modify computeWeights to accomodate explicit coefficients + real64 thermalTrans = 0.0; + real64 dThermalTrans_dPerm[3]{}; // not used + m_stencilWrapper.computeWeights( iconn, + m_thermalConductivity, + thermalTrans, + dThermalTrans_dPerm ); + + // Step 2: compute temperature difference at the interface + stack.energyFlux += thermalTrans + * ( m_temp[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )] - m_faceTemp[m_sei( iconn, Order::FACE )] ); + stack.dEnergyFlux_dT += thermalTrans; + + + // ********************************************************************************** + // At this point, we have computed the energyFlux and the compFlux for all components + // We have to do two things here: + // 1) Add dCompFlux_dTemp to the localFluxJacobian of the component mass balance equations + // 2) Add energyFlux and its derivatives to the localFlux(Jacobian) of the energy balance equation + + // Step 1: add dCompFlux_dTemp to localFluxJacobian + for( integer ic = 0; ic < numComp; ++ic ) + { + stack.localFluxJacobian[ic][numDof-1] = m_dt * stack.dCompFlux_dT[ic]; + } + + // Step 2: add energyFlux and its derivatives to localFlux and localFluxJacobian + integer const localRowIndexEnergy = numEqn-1; + stack.localFlux[localRowIndexEnergy] = m_dt * stack.energyFlux; + + stack.localFluxJacobian[localRowIndexEnergy][0] = m_dt * stack.dEnergyFlux_dP; + stack.localFluxJacobian[localRowIndexEnergy][numDof-1] = m_dt * stack.dEnergyFlux_dT; + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.localFluxJacobian[localRowIndexEnergy][jc+1] = m_dt * stack.dEnergyFlux_dC[jc]; + } + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void complete( localIndex const iconn, + StackVariables & stack ) const + { + // Call Case::complete to assemble the component mass balance equations (i = 0 to i = numDof-2) + // In the lambda, add contribution to residual and jacobian into the energy balance equation + Base::complete( iconn, stack, [&] ( localIndex const localRow ) + { + // beware, there is volume balance eqn in m_localRhs and m_localMatrix! + RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + numEqn], stack.localFlux[numEqn-1] ); + AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + numEqn, + stack.dofColIndices, + stack.localFluxJacobian[numEqn-1], + numDof ); + + } ); + } + +protected: + + /// Views on temperature + ElementViewConst< arrayView1d< real64 const > > const m_temp; + + /// Views on phase enthalpies + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseEnthalpy; + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseEnthalpy; + + /// View on thermal conductivity + ElementViewConst< arrayView3d< real64 const > > const m_thermalConductivity; + // for now, we treat thermal conductivity explicitly + +}; + +/** + * @class DirichletFluxComputeKernelFactory + */ +class DirichletFluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] solverName name of the solver (to name accessors) + * @param[in] faceManager reference to the face manager + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] fluidBase the multifluid constitutive model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename STENCILWRAPPER > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + integer const useTotalMassEquation, + string const & dofKey, + string const & solverName, + FaceManager const & faceManager, + ElementRegionManager const & elemManager, + STENCILWRAPPER const & stencilWrapper, + constitutive::MultiFluidBase & fluidBase, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + constitutive::constitutiveComponentUpdatePassThru< true >( fluidBase, numComps, [&]( auto & fluid, auto NC ) + { + using FluidType = TYPEOFREF( fluid ); + typename FluidType::KernelWrapper const fluidWrapper = fluid.createKernelWrapper(); + + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 2; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + // for now, we neglect capillary pressure in the kernel + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags; + if( useTotalMassEquation ) + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::TotalMassEquation ); + + using KernelType = DirichletFluxComputeKernel< NUM_COMP, NUM_DOF, typename FluidType::KernelWrapper >; + typename KernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename KernelType::ThermalCompFlowAccessors thermalCompFlowAccessors( elemManager, solverName ); + typename KernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename KernelType::ThermalMultiFluidAccessors thermalMultiFluidAccessors( elemManager, solverName ); + typename KernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); + typename KernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + typename KernelType::ThermalConductivityAccessors thermalConductivityAccessors( elemManager, solverName ); + + KernelType kernel( numPhases, rankOffset, faceManager, stencilWrapper, fluidWrapper, + dofNumberAccessor, compFlowAccessors, thermalCompFlowAccessors, multiFluidAccessors, thermalMultiFluidAccessors, + capPressureAccessors, permeabilityAccessors, thermalConductivityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + KernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } +}; + +} // namespace thermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALDIRICHLETFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp new file mode 100644 index 00000000000..4aefb18e072 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp @@ -0,0 +1,558 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalFluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALFLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALFLUXCOMPUTEKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" + +#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" +#include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" +#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityFields.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseFVMKernels +{ + +/******************************** FluxComputeKernel ********************************/ + +/** + * @class FluxComputeKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @brief Define the interface for the assembly kernel in charge of flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > +class FluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER > +{ +public: + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; + using DofNumberAccessor = AbstractBase::DofNumberAccessor; + using CompFlowAccessors = AbstractBase::CompFlowAccessors; + using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; + using CapPressureAccessors = AbstractBase::CapPressureAccessors; + using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; + + using AbstractBase::m_dt; + using AbstractBase::m_numPhases; + using AbstractBase::m_rankOffset; + using AbstractBase::m_dofNumber; + using AbstractBase::m_gravCoef; + using AbstractBase::m_dPhaseVolFrac; + using AbstractBase::m_phaseCompFrac; + using AbstractBase::m_dPhaseCompFrac; + using AbstractBase::m_dCompFrac_dCompDens; + + using Base = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + using Base::numComp; + using Base::numDof; + using Base::numEqn; + using Base::maxNumElems; + using Base::maxNumConns; + using Base::maxStencilSize; + using Base::numFluxSupportPoints; + using Base::m_phaseMob; + using Base::m_dPhaseMob; + using Base::m_dPhaseMassDens; + using Base::m_dPhaseCapPressure_dPhaseVolFrac; + using Base::m_stencilWrapper; + using Base::m_seri; + using Base::m_sesri; + using Base::m_sei; + + using ThermalCompFlowAccessors = + StencilAccessors< fields::flow::temperature >; + + using ThermalMultiFluidAccessors = + StencilMaterialAccessors< constitutive::MultiFluidBase, + fields::multifluid::phaseEnthalpy, + fields::multifluid::dPhaseEnthalpy >; + + using ThermalConductivityAccessors = + StencilMaterialAccessors< constitutive::MultiPhaseThermalConductivityBase, + fields::thermalconductivity::effectiveConductivity >; + // for now, we treat thermal conductivity explicitly + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dofNumberAccessor accessor for the dofs numbers + * @param[in] compFlowAccessor accessor for wrappers registered by the solver + * @param[in] thermalCompFlowAccessors accessor for *thermal* wrappers registered by the solver + * @param[in] multiFluidAccessor accessor for wrappers registered by the multifluid model + * @param[in] thermalMultiFluidAccessors accessor for *thermal* wrappers registered by the multifluid model + * @param[in] capPressureAccessors accessor for wrappers registered by the cap pressure model + * @param[in] permeabilityAccessors accessor for wrappers registered by the permeability model + * @param[in] thermalConductivityAccessors accessor for wrappers registered by the thermal conductivity model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed all together + */ + FluxComputeKernel( integer const numPhases, + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + ThermalCompFlowAccessors const & thermalCompFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + ThermalConductivityAccessors const & thermalConductivityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) + : Base( numPhases, + rankOffset, + stencilWrapper, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + capPressureAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), + m_temp( thermalCompFlowAccessors.get( fields::flow::temperature {} ) ), + m_phaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::phaseEnthalpy {} ) ), + m_dPhaseEnthalpy( thermalMultiFluidAccessors.get( fields::multifluid::dPhaseEnthalpy {} ) ), + m_thermalConductivity( thermalConductivityAccessors.get( fields::thermalconductivity::effectiveConductivity {} ) ) + {} + + struct StackVariables : public Base::StackVariables + { +public: + + GEOS_HOST_DEVICE + StackVariables( localIndex const size, localIndex numElems ) + : Base::StackVariables( size, numElems ) + {} + + using Base::StackVariables::stencilSize; + using Base::StackVariables::numConnectedElems; + using Base::StackVariables::transmissibility; + using Base::StackVariables::dTrans_dPres; + using Base::StackVariables::dofColIndices; + using Base::StackVariables::localFlux; + using Base::StackVariables::localFluxJacobian; + + // Thermal transmissibility (for now, no derivatives) + + real64 thermalTransmissibility[maxNumConns][2]{}; + }; + + /** + * @brief Compute the local flux contributions to the residual and Jacobian + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + inline + void computeFlux( localIndex const iconn, + StackVariables & stack ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + // *********************************************** + // First, we call the base computeFlux to compute: + // 1) compFlux and its derivatives (including derivatives wrt temperature), + // 2) enthalpy part of convectiveEnergyFlux and its derivatives (including derivatives wrt temperature) + // + // Computing dCompFlux_dT and the enthalpy flux requires quantities already computed in the base computeFlux, + // such as potGrad, phaseFlux, and the indices of the upwind cell + // We use the lambda below (called **inside** the phase loop of the base computeFlux) to access these variables + Base::computeFlux( iconn, stack, [&] ( integer const ip, + localIndex const (&k)[2], + localIndex const (&seri)[2], + localIndex const (&sesri)[2], + localIndex const (&sei)[2], + localIndex const connectionIndex, + localIndex const k_up, + localIndex const er_up, + localIndex const esr_up, + localIndex const ei_up, + real64 const potGrad, + real64 const phaseFlux, + real64 const (&dPhaseFlux_dP)[2], + real64 const (&dPhaseFlux_dC)[2][numComp] ) + { + // We are in the loop over phases, ip provides the current phase index. + + // Step 1: compute the derivatives of the mean density at the interface wrt temperature + + real64 dDensMean_dT[numFluxSupportPoints]{}; + + real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], + stack.transmissibility[connectionIndex][1] }; + + real64 convectiveEnergyFlux = 0.0; + real64 dConvectiveEnergyFlux_dP[numFluxSupportPoints]{}; + real64 dConvectiveEnergyFlux_dT[numFluxSupportPoints]{}; + real64 dConvectiveEnergyFlux_dC[numFluxSupportPoints][numComp]{}; + real64 dCompFlux_dT[numFluxSupportPoints][numComp]{}; + + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + real64 const dDens_dT = m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dT]; + dDensMean_dT[i] = 0.5 * dDens_dT; + } + + // Step 2: compute the derivatives of the phase potential difference wrt temperature + //***** calculation of flux ***** + + real64 dPresGrad_dT[numFluxSupportPoints]{}; + real64 dGravHead_dT[numFluxSupportPoints]{}; + + // compute potential difference MPFA-style + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + // Step 2.1: compute derivative of capillary pressure wrt temperature + real64 dCapPressure_dT = 0.0; + if( AbstractBase::m_kernelFlags.isSet( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::CapPressure ) ) + { + for( integer jp = 0; jp < m_numPhases; ++jp ) + { + real64 const dCapPressure_dS = m_dPhaseCapPressure_dPhaseVolFrac[er][esr][ei][0][ip][jp]; + dCapPressure_dT += dCapPressure_dS * m_dPhaseVolFrac[er][esr][ei][jp][Deriv::dT]; + } + } + + // Step 2.2: compute derivative of phase pressure difference wrt temperature + dPresGrad_dT[i] -= trans[i] * dCapPressure_dT; + real64 const gravD = trans[i] * m_gravCoef[er][esr][ei]; + + // Step 2.3: compute derivative of gravity potential difference wrt temperature + for( integer j = 0; j < numFluxSupportPoints; ++j ) + { + dGravHead_dT[j] += dDensMean_dT[j] * gravD; + } + } + + // Step 3: compute the derivatives of the (upwinded) compFlux wrt temperature + // *** upwinding *** + + // note: the upwinding is done in the base class, which is in charge of + // computing the following quantities: potGrad, phaseFlux, k_up, er_up, esr_up, ei_up + + real64 dPhaseFlux_dT[numFluxSupportPoints]{}; + + // Step 3.1: compute the derivative of phase flux wrt temperature + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dPhaseFlux_dT[ke] += dPresGrad_dT[ke]; + } + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dPhaseFlux_dT[ke] -= dGravHead_dT[ke]; + } + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dPhaseFlux_dT[ke] *= m_phaseMob[er_up][esr_up][ei_up][ip]; + } + dPhaseFlux_dT[k_up] += m_dPhaseMob[er_up][esr_up][ei_up][ip][Deriv::dT] * potGrad; + + // Step 3.2: compute the derivative of component flux wrt temperature + + // slice some constitutive arrays to avoid too much indexing in component loop + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP - 3 > phaseCompFracSub = + m_phaseCompFrac[er_up][esr_up][ei_up][0][ip]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC - 3 > dPhaseCompFracSub = + m_dPhaseCompFrac[er_up][esr_up][ei_up][0][ip]; + + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = phaseCompFracSub[ic]; + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dCompFlux_dT[ke][ic] += dPhaseFlux_dT[ke] * ycp; + } + dCompFlux_dT[k_up][ic] += phaseFlux * dPhaseCompFracSub[ic][Deriv::dT]; + } + + // Step 4: add dCompFlux_dTemp to localFluxJacobian + for( integer ic = 0; ic < numComp; ++ic ) + { + integer const eqIndex0 = k[0]* numEqn + ic; + integer const eqIndex1 = k[1]* numEqn + ic; + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + integer const localDofIndexTemp = k[ke] * numDof + numDof - 1; + stack.localFluxJacobian[eqIndex0][localDofIndexTemp] += m_dt * dCompFlux_dT[ke][ic]; + stack.localFluxJacobian[eqIndex1][localDofIndexTemp] -= m_dt * dCompFlux_dT[ke][ic]; + } + } + + // Step 5: compute the enthalpy flux + real64 const enthalpy = m_phaseEnthalpy[er_up][esr_up][ei_up][0][ip]; + convectiveEnergyFlux += phaseFlux * enthalpy; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dConvectiveEnergyFlux_dP[ke] += dPhaseFlux_dP[ke] * enthalpy; + dConvectiveEnergyFlux_dT[ke] += dPhaseFlux_dT[ke] * enthalpy; + + for( integer jc = 0; jc < numComp; ++jc ) + { + dConvectiveEnergyFlux_dC[ke][jc] += dPhaseFlux_dC[ke][jc] * enthalpy; + } + } + + dConvectiveEnergyFlux_dP[k_up] += phaseFlux * m_dPhaseEnthalpy[er_up][esr_up][ei_up][0][ip][Deriv::dP]; + dConvectiveEnergyFlux_dT[k_up] += phaseFlux * m_dPhaseEnthalpy[er_up][esr_up][ei_up][0][ip][Deriv::dT]; + + real64 dProp_dC[numComp]{}; + applyChainRule( numComp, + m_dCompFrac_dCompDens[er_up][esr_up][ei_up], + m_dPhaseEnthalpy[er_up][esr_up][ei_up][0][ip], + dProp_dC, + Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + { + dConvectiveEnergyFlux_dC[k_up][jc] += phaseFlux * dProp_dC[jc]; + } + + // Step 6: add convectiveFlux and its derivatives to localFlux and localFluxJacobian + integer const localRowIndexEnergy0 = k[0] * numEqn + numEqn - 1; + integer const localRowIndexEnergy1 = k[1] * numEqn + numEqn - 1; + stack.localFlux[localRowIndexEnergy0] += m_dt * convectiveEnergyFlux; + stack.localFlux[localRowIndexEnergy1] -= m_dt * convectiveEnergyFlux; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + integer const localDofIndexPres = k[ke] * numDof; + stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexPres] += m_dt * dConvectiveEnergyFlux_dP[ke]; + stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexPres] -= m_dt * dConvectiveEnergyFlux_dP[ke]; + integer const localDofIndexTemp = localDofIndexPres + numDof - 1; + stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexTemp] += m_dt * dConvectiveEnergyFlux_dT[ke]; + stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexTemp] -= m_dt * dConvectiveEnergyFlux_dT[ke]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + integer const localDofIndexComp = localDofIndexPres + jc + 1; + stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexComp] += m_dt * dConvectiveEnergyFlux_dC[ke][jc]; + stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexComp] -= m_dt * dConvectiveEnergyFlux_dC[ke][jc]; + } + } + } ); + + // ***************************************************** + // Computation of the conduction term in the energy flux + // Note that the phase enthalpy term in the energy was computed above + // Note that this term is computed using an explicit treatment of conductivity for now + + // Step 1: compute the thermal transmissibilities at this face + // Below, the thermal conductivity used to compute (explicitly) the thermal conducivity + // To avoid modifying the signature of the "computeWeights" function for now, we pass m_thermalConductivity twice + // TODO: modify computeWeights to accomodate explicit coefficients + m_stencilWrapper.computeWeights( iconn, + m_thermalConductivity, + m_thermalConductivity, // we have to pass something here, so we just use thermal conductivity + stack.thermalTransmissibility, + stack.dTrans_dPres ); // again, we have to pass something here, but this is unused for now + + + + localIndex k[2]{}; + localIndex connectionIndex = 0; + + for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) + { + for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) + { + real64 const thermalTrans[2] = { stack.thermalTransmissibility[connectionIndex][0], stack.thermalTransmissibility[connectionIndex][1] }; + localIndex const seri[2] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; + localIndex const sesri[2] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; + localIndex const sei[2] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; + + real64 conductiveEnergyFlux = 0.0; + real64 dConductiveEnergyFlux_dT[numFluxSupportPoints]{}; + + // Step 2: compute temperature difference at the interface + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + localIndex const er = seri[ke]; + localIndex const esr = sesri[ke]; + localIndex const ei = sei[ke]; + + conductiveEnergyFlux += thermalTrans[ke] * m_temp[er][esr][ei]; + dConductiveEnergyFlux_dT[ke] += thermalTrans[ke]; + } + + // Step 3: add conductiveFlux and its derivatives to localFlux and localFluxJacobian + integer const localRowIndexEnergy0 = k[0] * numEqn + numEqn - 1; + integer const localRowIndexEnergy1 = k[1] * numEqn + numEqn - 1; + stack.localFlux[localRowIndexEnergy0] += m_dt * conductiveEnergyFlux; + stack.localFlux[localRowIndexEnergy1] -= m_dt * conductiveEnergyFlux; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + integer const localDofIndexTemp = k[ke] * numDof + numDof - 1; + stack.localFluxJacobian[localRowIndexEnergy0][localDofIndexTemp] += m_dt * dConductiveEnergyFlux_dT[ke]; + stack.localFluxJacobian[localRowIndexEnergy1][localDofIndexTemp] -= m_dt * dConductiveEnergyFlux_dT[ke]; + } + } + } + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + inline + void complete( localIndex const iconn, + StackVariables & stack ) const + { + // Call Case::complete to assemble the component mass balance equations (i = 0 to i = numDof-2) + // In the lambda, add contribution to residual and jacobian into the energy balance equation + Base::complete( iconn, stack, [&] ( integer const i, + localIndex const localRow ) + { + // beware, there is volume balance eqn in m_localRhs and m_localMatrix! + RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + numEqn], stack.localFlux[i * numEqn + numEqn-1] ); + AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + numEqn, + stack.dofColIndices.data(), + stack.localFluxJacobian[i * numEqn + numEqn-1].dataIfContiguous(), + stack.stencilSize * numDof ); + + } ); + } + +protected: + + /// Views on temperature + ElementViewConst< arrayView1d< real64 const > > const m_temp; + + /// Views on phase enthalpies + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseEnthalpy; + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseEnthalpy; + + /// View on thermal conductivity + ElementViewConst< arrayView3d< real64 const > > const m_thermalConductivity; + // for now, we treat thermal conductivity explicitly + +}; + +/** + * @class FluxComputeKernelFactory + */ +class FluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] hasCapPressure flag specifying whether capillary pressure is used or not + * @param[in] solverName name of the solver (to name accessors) + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename STENCILWRAPPER > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + string const & dofKey, + integer const hasCapPressure, + integer const useTotalMassEquation, + string const & solverName, + ElementRegionManager const & elemManager, + STENCILWRAPPER const & stencilWrapper, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + isothermalCompositionalMultiphaseBaseKernels:: + internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) + { + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 2; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags; + if( hasCapPressure ) + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::CapPressure ); + if( useTotalMassEquation ) + kernelFlags.set( isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags::TotalMassEquation ); + + using KernelType = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + typename KernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename KernelType::ThermalCompFlowAccessors thermalCompFlowAccessors( elemManager, solverName ); + typename KernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename KernelType::ThermalMultiFluidAccessors thermalMultiFluidAccessors( elemManager, solverName ); + typename KernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); + typename KernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + typename KernelType::ThermalConductivityAccessors thermalConductivityAccessors( elemManager, solverName ); + + KernelType kernel( numPhases, rankOffset, stencilWrapper, dofNumberAccessor, + compFlowAccessors, thermalCompFlowAccessors, multiFluidAccessors, thermalMultiFluidAccessors, + capPressureAccessors, permeabilityAccessors, thermalConductivityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + KernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } +}; + +} // namespace thermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALFLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseMobilityKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseMobilityKernel.hpp new file mode 100644 index 00000000000..f6be6b2cf55 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseMobilityKernel.hpp @@ -0,0 +1,154 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 ThermalPhaseMobilityKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALPHASEMOBILITYKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALPHASEMOBILITYKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" + +namespace geos +{ + +namespace thermalCompositionalMultiphaseFVMKernels +{ + +/******************************** PhaseMobilityKernel ********************************/ + +/** + * @class PhaseMobilityKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_PHASE number of fluid phases + * @brief Define the interface for the property kernel in charge of computing the phase mobilities + */ +template< integer NUM_COMP, integer NUM_PHASE > +class PhaseMobilityKernel : public isothermalCompositionalMultiphaseFVMKernels::PhaseMobilityKernel< NUM_COMP, NUM_PHASE > +{ +public: + + using Base = isothermalCompositionalMultiphaseFVMKernels::PhaseMobilityKernel< NUM_COMP, NUM_PHASE >; + using Base::numPhase; + using Base::m_dPhaseVolFrac; + using Base::m_dPhaseMob; + using Base::m_phaseDens; + using Base::m_dPhaseDens; + using Base::m_phaseVisc; + using Base::m_dPhaseVisc; + using Base::m_dPhaseRelPerm_dPhaseVolFrac; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] relperm the relperm model + */ + PhaseMobilityKernel( ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::RelativePermeabilityBase const & relperm ) + : Base( subRegion, fluid, relperm ) + {} + + /** + * @brief Compute the phase mobilities in an element + * @param[in] ei the element index + */ + GEOS_HOST_DEVICE + inline + void compute( localIndex const ei ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseVisc = m_phaseVisc[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseVisc = m_dPhaseVisc[ei][0]; + arraySlice2d< real64 const, constitutive::relperm::USD_RELPERM_DS - 2 > const dPhaseRelPerm_dPhaseVolFrac = m_dPhaseRelPerm_dPhaseVolFrac[ei][0]; + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; + + Base::compute( ei, [&] ( localIndex const ip, + real64 const & phaseMob, + arraySlice1d< real64, compflow::USD_PHASE_DC - 2 > const & dPhaseMob ) + { + // Step 1: compute the derivative of relPerm[ip] wrt temperature + real64 dRelPerm_dT = 0.0; + for( integer jp = 0; jp < numPhase; ++jp ) + { + dRelPerm_dT += dPhaseRelPerm_dPhaseVolFrac[ip][jp] * dPhaseVolFrac[jp][Deriv::dT]; + } + + // Step 2: compute the derivative of phaseMob[ip] wrt temperature + dPhaseMob[Deriv::dT] = dRelPerm_dT * phaseDens[ip] / phaseVisc[ip] + + phaseMob * (dPhaseDens[ip][Deriv::dT] / phaseDens[ip] - dPhaseVisc[ip][Deriv::dT] / phaseVisc[ip] ); + } ); + } + +}; + +/** + * @class PhaseMobilityKernelFactory + */ +class PhaseMobilityKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] numPhase the number of fluid phases + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] relperm the relperm model + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComp, + integer const numPhase, + ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::RelativePermeabilityBase const & relperm ) + { + if( numPhase == 2 ) + { + isothermalCompositionalMultiphaseBaseKernels:: + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseMobilityKernel< NUM_COMP, 2 > kernel( subRegion, fluid, relperm ); + PhaseMobilityKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + else if( numPhase == 3 ) + { + isothermalCompositionalMultiphaseBaseKernels:: + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseMobilityKernel< NUM_COMP, 3 > kernel( subRegion, fluid, relperm ); + PhaseMobilityKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + } +}; + +} // namespace thermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALPHASEMOBILITYKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp index 5befe3e9aa7..d2a2b413126 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsConformingFractures.hpp @@ -269,7 +269,7 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FluxComputeKe /** - * @class FaceBasedAssemblyKernelFactory + * @class ConnectorBasedAssemblyKernelFactory */ class ConnectorBasedAssemblyKernelFactory { diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp index 654ee0b3594..2cb1dec4ecc 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/SinglePhasePoromechanicsEmbeddedFractures.hpp @@ -239,7 +239,7 @@ class ConnectorBasedAssemblyKernel : public singlePhaseFVMKernels::FluxComputeKe /** - * @class FaceBasedAssemblyKernelFactory + * @class ConnectorBasedAssemblyKernelFactory */ class ConnectorBasedAssemblyKernelFactory { diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp index e82a918fa09..c9eb1dcafaf 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsConformingFractures.hpp @@ -332,7 +332,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsConformingFr /** - * @class FaceBasedAssemblyKernelFactory + * @class ConnectorBasedAssemblyKernelFactory */ class ConnectorBasedAssemblyKernelFactory { diff --git a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp index 1b39b1b44cb..03690cbf27d 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/poromechanicsKernels/ThermalSinglePhasePoromechanicsEmbeddedFractures.hpp @@ -343,7 +343,7 @@ class ConnectorBasedAssemblyKernel : public singlePhasePoromechanicsEmbeddedFrac /** - * @class FaceBasedAssemblyKernelFactory + * @class ConnectorBasedAssemblyKernelFactory */ class ConnectorBasedAssemblyKernelFactory { From c5f490115d4be7efae819951c494bf16f3f82c21 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Sat, 28 Sep 2024 21:34:47 -0500 Subject: [PATCH 25/47] some includes cleanup --- .../fluid/multifluid/MultiFluidSelector.hpp | 2 +- .../fluidFlow/CompositionalMultiphaseBase.cpp | 3 ++- .../compositional/AccumulationKernel.hpp | 4 ---- .../kernels/compositional/AquiferBCKernel.cpp | 7 +------ .../kernels/compositional/AquiferBCKernel.hpp | 20 ------------------ .../kernels/compositional/CFLKernel.cpp | 3 --- .../kernels/compositional/CFLKernel.hpp | 19 ----------------- ...ompositionalMultiphaseHybridFVMKernels.hpp | 1 + .../DiffusionDispersionFluxComputeKernel.hpp | 18 ---------------- .../DirichletFluxComputeKernel.hpp | 21 +------------------ .../DissipationFluxComputeKernel.hpp | 1 + .../compositional/FluxComputeKernel.hpp | 19 ----------------- .../compositional/FluxComputeKernelBase.cpp | 1 - .../compositional/FluxComputeKernelBase.hpp | 20 +----------------- .../StabilizedFluxComputeKernel.hpp | 3 +++ 15 files changed, 11 insertions(+), 131 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/MultiFluidSelector.hpp b/src/coreComponents/constitutive/fluid/multifluid/MultiFluidSelector.hpp index 7d54ed3e3c4..580a965061b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/MultiFluidSelector.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/MultiFluidSelector.hpp @@ -14,7 +14,7 @@ */ /** - * @file multiFluidSelector.hpp + * @file MultiFluidSelector.hpp */ #ifndef GEOS_CONSTITUTIVE_FLUID_MULTIFLUIDSELECTOR_HPP_ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUIDSELECTOR_HPP_ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index db4fe4399fb..5bd0d82fa95 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -36,11 +36,12 @@ #include "fieldSpecification/AquiferBoundaryCondition.hpp" #include "fieldSpecification/EquilibriumInitialCondition.hpp" #include "fieldSpecification/SourceFluxBoundaryCondition.hpp" -#include "physicsSolvers/fluidFlow/SourceFluxStatistics.hpp" +#include "finiteVolume/FluxApproximationBase.hpp" #include "mesh/DomainPartition.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/SourceFluxStatistics.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp index 333ae5dded2..fdb08bb6a9a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp @@ -26,14 +26,10 @@ #include "common/GEOS_RAJA_Interface.hpp" #include "constitutive/solid/CoupledSolidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "functions/TableFunction.hpp" #include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp index b7a9697f819..36ea1aa3226 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.cpp @@ -19,12 +19,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" - -#include "finiteVolume/CellElementStencilTPFA.hpp" -#include "finiteVolume/SurfaceElementStencil.hpp" -#include "finiteVolume/EmbeddedSurfaceToCellStencil.hpp" -#include "finiteVolume/FaceElementToCellStencil.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" +#include "finiteVolume/BoundaryStencil.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp index cd7a839ce9d..b1729589b30 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp @@ -24,34 +24,14 @@ #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" -#include "constitutive/diffusion/DiffusionFields.hpp" -#include "constitutive/diffusion/DiffusionBase.hpp" -#include "constitutive/dispersion/DispersionFields.hpp" -#include "constitutive/dispersion/DispersionBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" -#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" -#include "constitutive/solid/porosity/PorosityBase.hpp" -#include "constitutive/solid/porosity/PorosityFields.hpp" #include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" #include "finiteVolume/BoundaryStencil.hpp" #include "mesh/ElementRegionManager.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.cpp index 851b7d8daa3..38eef8f2c8b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.cpp @@ -18,13 +18,10 @@ */ #include "physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" - #include "finiteVolume/CellElementStencilTPFA.hpp" #include "finiteVolume/SurfaceElementStencil.hpp" #include "finiteVolume/EmbeddedSurfaceToCellStencil.hpp" #include "finiteVolume/FaceElementToCellStencil.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp index e74a54d03fc..8449d57e43e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp @@ -20,38 +20,19 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CFLKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_CFLKERNEL_HPP -#include "codingUtilities/Utilities.hpp" #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" -#include "constitutive/diffusion/DiffusionFields.hpp" -#include "constitutive/diffusion/DiffusionBase.hpp" -#include "constitutive/dispersion/DispersionFields.hpp" -#include "constitutive/dispersion/DispersionBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" -#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" #include "constitutive/permeability/PermeabilityBase.hpp" #include "constitutive/permeability/PermeabilityFields.hpp" #include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" #include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" -#include "constitutive/solid/porosity/PorosityBase.hpp" -#include "constitutive/solid/porosity/PorosityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "finiteVolume/BoundaryStencil.hpp" #include "mesh/ElementRegionManager.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp index ac6fee0e23c..79c9f91fd07 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/CompositionalMultiphaseHybridFVMKernels.hpp @@ -30,6 +30,7 @@ #include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" #include "mesh/ElementRegionManager.hpp" #include "mesh/ObjectManagerBase.hpp" +#include "physicsSolvers/SolverBaseKernels.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp index a6c6dc84a5a..ef967ebf923 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp @@ -24,34 +24,16 @@ #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" #include "constitutive/diffusion/DiffusionFields.hpp" #include "constitutive/diffusion/DiffusionBase.hpp" #include "constitutive/dispersion/DispersionFields.hpp" #include "constitutive/dispersion/DispersionBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" -#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" #include "constitutive/solid/porosity/PorosityBase.hpp" #include "constitutive/solid/porosity/PorosityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "finiteVolume/BoundaryStencil.hpp" #include "mesh/ElementRegionManager.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp index 8b84a977bd7..145c7d8ea6e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp @@ -24,34 +24,15 @@ #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" -#include "constitutive/diffusion/DiffusionFields.hpp" -#include "constitutive/diffusion/DiffusionBase.hpp" -#include "constitutive/dispersion/DispersionFields.hpp" -#include "constitutive/dispersion/DispersionBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" -#include "constitutive/solid/porosity/PorosityBase.hpp" -#include "constitutive/solid/porosity/PorosityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" #include "finiteVolume/BoundaryStencil.hpp" #include "mesh/ElementRegionManager.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp index fc597c9cda0..958e6d400d5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp @@ -21,6 +21,7 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DISSIPATIONFLUXCOMPUTEKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "constitutive/solid/porosity/PorosityBase.hpp" #include "constitutive/solid/porosity/PorosityFields.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp index 6d550ddd22a..95dea15f481 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp @@ -26,26 +26,7 @@ #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" -#include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" -#include "constitutive/diffusion/DiffusionFields.hpp" -#include "constitutive/diffusion/DiffusionBase.hpp" -#include "constitutive/dispersion/DispersionFields.hpp" -#include "constitutive/dispersion/DispersionBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" -#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" -#include "constitutive/permeability/PermeabilityBase.hpp" -#include "constitutive/permeability/PermeabilityFields.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" -#include "constitutive/solid/porosity/PorosityBase.hpp" -#include "constitutive/solid/porosity/PorosityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "finiteVolume/BoundaryStencil.hpp" -#include "mesh/ElementRegionManager.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp index a28e0f93864..5c513f569ad 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp @@ -18,7 +18,6 @@ */ #include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "finiteVolume/CellElementStencilTPFA.hpp" #include "finiteVolume/SurfaceElementStencil.hpp" diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp index 2c6f7083162..a991d651642 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp @@ -20,38 +20,20 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNELBASE_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNELBASE_HPP -#include "codingUtilities/Utilities.hpp" #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" #include "constitutive/capillaryPressure/CapillaryPressureFields.hpp" #include "constitutive/capillaryPressure/CapillaryPressureBase.hpp" -#include "constitutive/diffusion/DiffusionFields.hpp" -#include "constitutive/diffusion/DiffusionBase.hpp" -#include "constitutive/dispersion/DispersionFields.hpp" -#include "constitutive/dispersion/DispersionBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" -#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" #include "constitutive/permeability/PermeabilityBase.hpp" #include "constitutive/permeability/PermeabilityFields.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" -#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" -#include "constitutive/solid/porosity/PorosityBase.hpp" -#include "constitutive/solid/porosity/PorosityFields.hpp" -#include "fieldSpecification/AquiferBoundaryCondition.hpp" -#include "finiteVolume/FluxApproximationBase.hpp" -#include "finiteVolume/BoundaryStencil.hpp" #include "mesh/ElementRegionManager.hpp" -#include "mesh/utilities/MeshMapUtilities.hpp" #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" #include "physicsSolvers/fluidFlow/StencilAccessors.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelector.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" + namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp index 9986bd6cb24..50a0f6cad69 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp @@ -21,6 +21,9 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_STABILIZEDFLUXCOMPUTEKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityBase.hpp" +#include "constitutive/relativePermeability/RelativePermeabilityFields.hpp" + namespace geos { From 890af39d0dfcf5f9c7e5cc8f0011dd4e390c3bbd Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Mon, 30 Sep 2024 08:53:46 -0500 Subject: [PATCH 26/47] includes cleanup and code style --- .../compositional/AccumulationKernel.hpp | 16 +++---- .../kernels/compositional/C1PPUPhaseFlux.hpp | 2 + .../DiffusionDispersionFluxComputeKernel.hpp | 40 ++++++++--------- .../DirichletFluxComputeKernel.hpp | 30 ++++++------- .../DissipationFluxComputeKernel.hpp | 38 ++++++++-------- .../compositional/FluxComputeKernel.hpp | 38 ++++++++-------- .../compositional/FluxComputeKernelBase.cpp | 16 +++---- .../compositional/FluxComputeKernelBase.hpp | 16 +++---- .../HydrostaticPressureKernel.hpp | 9 ---- .../compositional/PropertyKernelBase.hpp | 12 ----- ...ctiveCompositionalMultiphaseOBLKernels.hpp | 44 +++++++++---------- .../RelativePermeabilityUpdateKernel.hpp | 12 ----- .../compositional/SolutionCheckKernel.hpp | 15 +------ .../SolutionScalingAndCheckingKernelBase.hpp | 26 ++++------- .../compositional/SolutionScalingKernel.hpp | 27 ++++++------ .../StabilizedFluxComputeKernel.hpp | 28 ++++++------ .../ThermalAccumulationKernel.hpp | 16 +++---- ...alDiffusionDispersionFluxComputeKernel.hpp | 24 +++++----- .../ThermalDirichletFluxComputeKernel.hpp | 41 +++++++++-------- .../ThermalFluxComputeKernel.hpp | 33 +++++++------- .../ThermalSolutionScalingKernel.hpp | 38 ++++++++-------- .../CompositionalMultiphaseWellKernels.hpp | 2 +- 22 files changed, 234 insertions(+), 289 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp index fdb08bb6a9a..99355258d83 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp @@ -87,14 +87,14 @@ class AccumulationKernel * @param[inout] localRhs the local right-hand side vector */ AccumulationKernel( localIndex const numPhases, - globalIndex const rankOffset, - string const dofKey, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< AccumulationKernelFlags > const kernelFlags ) + globalIndex const rankOffset, + string const dofKey, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< AccumulationKernelFlags > const kernelFlags ) : m_numPhases( numPhases ), m_rankOffset( rankOffset ), m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp index 2ff1a7b6a37..f1b13581db5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp @@ -25,6 +25,8 @@ #include "constitutive/fluid/multifluid/Layouts.hpp" #include "constitutive/capillaryPressure/layouts.hpp" #include "mesh/ElementRegionManager.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PotGrad.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseComponentFlux.hpp" namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp index ef967ebf923..17bc8db184a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DiffusionDispersionFluxComputeKernel.hpp @@ -111,27 +111,27 @@ class DiffusionDispersionFluxComputeKernel : public FluxComputeKernelBase * @param[in] kernelFlags flags packed together */ DiffusionDispersionFluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - DiffusionAccessors const & diffusionAccessors, - DispersionAccessors const & dispersionAccessors, - PorosityAccessors const & porosityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + DiffusionAccessors const & diffusionAccessors, + DispersionAccessors const & dispersionAccessors, + PorosityAccessors const & porosityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) : FluxComputeKernelBase( numPhases, - rankOffset, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ), + rankOffset, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), m_phaseVolFrac( compFlowAccessors.get( fields::flow::phaseVolumeFraction {} ) ), m_phaseDens( multiFluidAccessors.get( fields::multifluid::phaseDensity {} ) ), m_dPhaseDens( multiFluidAccessors.get( fields::multifluid::dPhaseDensity {} ) ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp index 145c7d8ea6e..6c9607cc46b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp @@ -51,8 +51,8 @@ namespace isothermalCompositionalMultiphaseFVMKernels */ template< integer NUM_COMP, integer NUM_DOF, typename FLUIDWRAPPER > class DirichletFluxComputeKernel : public FluxComputeKernel< NUM_COMP, - NUM_DOF, - BoundaryStencilWrapper > + NUM_DOF, + BoundaryStencilWrapper > { public: @@ -119,19 +119,19 @@ class DirichletFluxComputeKernel : public FluxComputeKernel< NUM_COMP, * @param[in] kernelFlags flags packed together */ DirichletFluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) : Base( numPhases, rankOffset, stencilWrapper, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp index 958e6d400d5..0ba8fc50cd2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/DissipationFluxComputeKernel.hpp @@ -112,25 +112,25 @@ class FluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::Fl * @param[in] contMultiplier continuation multiplier factor (should be < 1) */ FluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - DissCompFlowAccessors const & dissCompFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - PorosityAccessors const & porosityAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags, - real64 const omega, - integer const curNewton, - integer const continuation, - integer const miscible, - real64 const kappamin, - real64 const contMultiplier ) + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + DissCompFlowAccessors const & dissCompFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + PorosityAccessors const & porosityAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags, + real64 const omega, + integer const curNewton, + integer const continuation, + integer const miscible, + real64 const kappamin, + real64 const contMultiplier ) : Base( numPhases, rankOffset, stencilWrapper, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp index 95dea15f481..d19db48bdf3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp @@ -91,26 +91,26 @@ class FluxComputeKernel : public FluxComputeKernelBase * @param[in] kernelFlags flags packed together */ FluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) : FluxComputeKernelBase( numPhases, - rankOffset, - dofNumberAccessor, - compFlowAccessors, - multiFluidAccessors, - dt, - localMatrix, - localRhs, - kernelFlags ), + rankOffset, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), m_permeability( permeabilityAccessors.get( fields::permeability::permeability {} ) ), m_dPerm_dPres( permeabilityAccessors.get( fields::permeability::dPerm_dPressure {} ) ), m_phaseMob( compFlowAccessors.get( fields::flow::phaseMobility {} ) ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp index 5c513f569ad..ee6c24965e5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.cpp @@ -35,14 +35,14 @@ namespace isothermalCompositionalMultiphaseFVMKernels /******************************** FluxComputeKernelBase ********************************/ FluxComputeKernelBase::FluxComputeKernelBase( integer const numPhases, - globalIndex const rankOffset, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) : m_numPhases( numPhases ), m_rankOffset( rankOffset ), m_dt( dt ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp index a991d651642..e794c992954 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp @@ -120,14 +120,14 @@ class FluxComputeKernelBase * @param[in] kernelFlags flags packed all together */ FluxComputeKernelBase( integer const numPhases, - globalIndex const rankOffset, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< FluxComputeKernelFlags > kernelFlags ); + globalIndex const rankOffset, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ); protected: diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp index e835d88b734..65b6bde6360 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp @@ -20,20 +20,11 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_HYDROSTATICPRESSUREKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_HYDROSTATICPRESSUREKERNEL_HPP -#include "codingUtilities/Utilities.hpp" #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" #include "constitutive/fluid/multifluid/MultiFluidBase.hpp" #include "functions/TableFunction.hpp" -#include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp index a7e693f2e81..4390ad8a34b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp @@ -20,20 +20,8 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PROPERTYKERNELBASE_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PROPERTYKERNELBASE_HPP -//#include "codingUtilities/Utilities.hpp" -//#include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -//#include "constitutive/solid/CoupledSolidBase.hpp" -//#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -//#include "functions/TableFunction.hpp" -//#include "mesh/ElementSubRegionBase.hpp" -//#include "mesh/ObjectManagerBase.hpp" -//#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -//#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -//#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -//#include "physicsSolvers/SolverBaseKernels.hpp" -//#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp index 3093131fb13..bc76898511d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ReactiveCompositionalMultiphaseOBLKernels.hpp @@ -657,13 +657,13 @@ class FluxComputeKernelBase * @param[inout] localRhs the local right-hand side vector */ FluxComputeKernelBase( globalIndex const rankOffset, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - real64 const & transMultExp, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + real64 const & transMultExp, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : m_rankOffset( rankOffset ), m_dt( dt * secondsToDaysMult ), m_transMultExp ( transMultExp ), @@ -791,22 +791,22 @@ class FluxComputeKernel : public FluxComputeKernelBase * @param[inout] localRhs the local right-hand side vector */ FluxComputeKernel( globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - PermeabilityAccessors const & permeabilityAccessors, - real64 const & dt, - real64 const & transMultExp, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const & dt, + real64 const & transMultExp, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) : FluxComputeKernelBase( rankOffset, - dofNumberAccessor, - compFlowAccessors, - permeabilityAccessors, - dt, - transMultExp, - localMatrix, - localRhs ), + dofNumberAccessor, + compFlowAccessors, + permeabilityAccessors, + dt, + transMultExp, + localMatrix, + localRhs ), m_stencilWrapper( stencilWrapper ), m_seri( stencilWrapper.getElementRegionIndices() ), m_sesri( stencilWrapper.getElementSubRegionIndices() ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp index b964ff56a2e..7706d28b679 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp @@ -20,20 +20,8 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RELATIVEPERMEABILITYUPDATEKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_RELATIVEPERMEABILITYUPDATEKERNEL_HPP -#include "codingUtilities/Utilities.hpp" -#include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "functions/TableFunction.hpp" -#include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp index 42c0325a8f2..fc5d20b6ca5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionCheckKernel.hpp @@ -20,20 +20,7 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP -#include "codingUtilities/Utilities.hpp" -#include "common/DataLayouts.hpp" -#include "common/DataTypes.hpp" -#include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "functions/TableFunction.hpp" -#include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp index 8bcbb477f84..ff03cf15f71 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp @@ -20,20 +20,10 @@ #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGKERNELBASE_HPP #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGKERNELBASE_HPP -#include "codingUtilities/Utilities.hpp" #include "common/DataLayouts.hpp" #include "common/DataTypes.hpp" #include "common/GEOS_RAJA_Interface.hpp" -#include "constitutive/solid/CoupledSolidBase.hpp" -#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" -#include "functions/TableFunction.hpp" #include "mesh/ElementSubRegionBase.hpp" -#include "mesh/ObjectManagerBase.hpp" -#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" -#include "physicsSolvers/SolverBaseKernels.hpp" -#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" namespace geos { @@ -63,14 +53,14 @@ class SolutionScalingAndCheckingKernelBase * @param[in] compDensScalingFactor the component local scaling factor */ SolutionScalingAndCheckingKernelBase( globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor ) + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor ) : m_rankOffset( rankOffset ), m_numComp( numComp ), m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp index b3ae5bac125..73344b95aef 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingKernel.hpp @@ -21,6 +21,7 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/SolutionScalingAndCheckingKernelBase.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" namespace geos { @@ -66,18 +67,18 @@ class SolutionScalingKernel : public SolutionScalingAndCheckingKernelBase< real6 * @param[in] compDensScalingFactor the component density local scaling factor */ SolutionScalingKernel( real64 const maxRelativePresChange, - real64 const maxAbsolutePresChange, - real64 const maxCompFracChange, - real64 const maxRelativeCompDensChange, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor ) + real64 const maxAbsolutePresChange, + real64 const maxCompFracChange, + real64 const maxRelativeCompDensChange, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor ) : Base( rankOffset, numComp, dofKey, @@ -373,7 +374,7 @@ class SolutionScalingKernelFactory arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset, - numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); + numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); return SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel ); } }; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp index 50a0f6cad69..f71923d804e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/StabilizedFluxComputeKernel.hpp @@ -119,20 +119,20 @@ class FluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::Fl * @param[in] kernelFlags flags packed together */ FluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - StabCompFlowAccessors const & stabCompFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - StabMultiFluidAccessors const & stabMultiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - RelPermAccessors const & relPermAccessors, - real64 const & dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + StabCompFlowAccessors const & stabCompFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + StabMultiFluidAccessors const & stabMultiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + RelPermAccessors const & relPermAccessors, + real64 const & dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) : Base( numPhases, rankOffset, stencilWrapper, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp index fd5b059f6ea..04841f5bb19 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp @@ -74,14 +74,14 @@ class AccumulationKernel : public isothermalCompositionalMultiphaseBaseKernels:: * @param[inout] localRhs the local right-hand side vector */ AccumulationKernel( localIndex const numPhases, - globalIndex const rankOffset, - string const dofKey, - ElementSubRegionBase const & subRegion, - constitutive::MultiFluidBase const & fluid, - constitutive::CoupledSolidBase const & solid, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > const kernelFlags ) + globalIndex const rankOffset, + string const dofKey, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseBaseKernels::AccumulationKernelFlags > const kernelFlags ) : Base( numPhases, rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs, kernelFlags ), m_dPoro_dTemp( solid.getDporosity_dTemperature() ), m_phaseInternalEnergy( fluid.phaseInternalEnergy() ), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp index 59a075990d5..9c59e0015f7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDiffusionDispersionFluxComputeKernel.hpp @@ -91,18 +91,18 @@ class DiffusionDispersionFluxComputeKernel : * @param[in] kernelFlags flags packed together */ DiffusionDispersionFluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - DiffusionAccessors const & diffusionAccessors, - DispersionAccessors const & dispersionAccessors, - PorosityAccessors const & porosityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + DiffusionAccessors const & diffusionAccessors, + DispersionAccessors const & dispersionAccessors, + PorosityAccessors const & porosityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) : Base( numPhases, rankOffset, stencilWrapper, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp index 0bfa4ea0380..96d55a186ed 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp @@ -21,11 +21,10 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALDIRICHLETFLUXCOMPUTEKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" - +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" -#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityFields.hpp" namespace geos { @@ -44,8 +43,8 @@ namespace thermalCompositionalMultiphaseFVMKernels */ template< integer NUM_COMP, integer NUM_DOF, typename FLUIDWRAPPER > class DirichletFluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::DirichletFluxComputeKernel< NUM_COMP, - NUM_DOF, - FLUIDWRAPPER > + NUM_DOF, + FLUIDWRAPPER > { public: @@ -124,22 +123,22 @@ class DirichletFluxComputeKernel : public isothermalCompositionalMultiphaseFVMKe * @param[in] kernelFlags flags packed together */ DirichletFluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - FaceManager const & faceManager, - BoundaryStencilWrapper const & stencilWrapper, - FLUIDWRAPPER const & fluidWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - ThermalCompFlowAccessors const & thermalCompFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - ThermalConductivityAccessors const & thermalConductivityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + ThermalCompFlowAccessors const & thermalCompFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + ThermalConductivityAccessors const & thermalConductivityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) : Base( numPhases, rankOffset, faceManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp index 4aefb18e072..963eb2ba513 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalFluxComputeKernel.hpp @@ -21,11 +21,10 @@ #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALFLUXCOMPUTEKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseMobilityKernel.hpp" - +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/thermalConductivity/MultiPhaseThermalConductivityBase.hpp" #include "constitutive/thermalConductivity/ThermalConductivityFields.hpp" -#include "constitutive/thermalConductivity/MultiPhaseThermalConductivityFields.hpp" namespace geos { @@ -122,20 +121,20 @@ class FluxComputeKernel : public isothermalCompositionalMultiphaseFVMKernels::Fl * @param[in] kernelFlags flags packed all together */ FluxComputeKernel( integer const numPhases, - globalIndex const rankOffset, - STENCILWRAPPER const & stencilWrapper, - DofNumberAccessor const & dofNumberAccessor, - CompFlowAccessors const & compFlowAccessors, - ThermalCompFlowAccessors const & thermalCompFlowAccessors, - MultiFluidAccessors const & multiFluidAccessors, - ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, - CapPressureAccessors const & capPressureAccessors, - PermeabilityAccessors const & permeabilityAccessors, - ThermalConductivityAccessors const & thermalConductivityAccessors, - real64 const dt, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs, - BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + ThermalCompFlowAccessors const & thermalCompFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + ThermalMultiFluidAccessors const & thermalMultiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + ThermalConductivityAccessors const & thermalConductivityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelFlags > kernelFlags ) : Base( numPhases, rankOffset, stencilWrapper, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp index 67e45cfc792..01688df3745 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/ThermalSolutionScalingKernel.hpp @@ -62,21 +62,21 @@ class SolutionScalingKernel : public isothermalCompositionalMultiphaseBaseKernel * @param[in] temperatureFactor the temperature local scaling factor */ SolutionScalingKernel( real64 const maxRelativePresChange, - real64 const maxAbsolutePresChange, - real64 const maxRelativeTempChange, - real64 const maxCompFracChange, - real64 const maxRelativeCompDensChange, - globalIndex const rankOffset, - integer const numComp, - string const dofKey, - ElementSubRegionBase const & subRegion, - arrayView1d< real64 const > const localSolution, - arrayView1d< real64 const > const pressure, - arrayView1d< real64 const > const temperature, - arrayView2d< real64 const, compflow::USD_COMP > const compDens, - arrayView1d< real64 > pressureScalingFactor, - arrayView1d< real64 > compDensScalingFactor, - arrayView1d< real64 > temperatureScalingFactor ) + real64 const maxAbsolutePresChange, + real64 const maxRelativeTempChange, + real64 const maxCompFracChange, + real64 const maxRelativeCompDensChange, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView1d< real64 const > const temperature, + arrayView2d< real64 const, compflow::USD_COMP > const compDens, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compDensScalingFactor, + arrayView1d< real64 > temperatureScalingFactor ) : Base( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, @@ -203,10 +203,10 @@ class SolutionScalingKernelFactory arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxRelativeTempChange, - maxCompFracChange, maxRelativeCompDensChange, - rankOffset, numComp, dofKey, subRegion, localSolution, - pressure, temperature, compDens, pressureScalingFactor, - temperatureScalingFactor, compDensScalingFactor ); + maxCompFracChange, maxRelativeCompDensChange, + rankOffset, numComp, dofKey, subRegion, localSolution, + pressure, temperature, compDens, pressureScalingFactor, + temperatureScalingFactor, compDensScalingFactor ); return thermalCompositionalMultiphaseBaseKernels:: SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp index 280cdf8dcf1..f9ba0fb8bd9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/kernels/CompositionalMultiphaseWellKernels.hpp @@ -950,7 +950,7 @@ class SolutionScalingKernelFactory subRegion.getField< fields::well::globalCompDensityScalingFactor >(); isothermalCompositionalMultiphaseBaseKernels:: SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset, - numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); + numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor ); return isothermalCompositionalMultiphaseBaseKernels:: SolutionScalingKernel:: launch< POLICY >( subRegion.size(), kernel ); From 695b4e2346cd3a2ae08c0ca3eab9a19d876efaa9 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Mon, 30 Sep 2024 09:12:33 -0500 Subject: [PATCH 27/47] crash fix --- .../fluidFlow/kernels/singlePhase/AccumulationKernels.hpp | 4 ++-- .../kernels/singlePhase/ThermalAccumulationKernels.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp index 6db441298fe..d7bcb6068f1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/AccumulationKernels.hpp @@ -334,13 +334,13 @@ class AccumulationKernelFactory CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) { - if constexpr ( std::is_same_v< SUBREGION_TYPE, CellElementSubRegion > ) + if constexpr ( std::is_base_of_v< CellElementSubRegion, SUBREGION_TYPE > ) { integer constexpr NUM_DOF = 1; AccumulationKernel< CellElementSubRegion, NUM_DOF > kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); AccumulationKernel< CellElementSubRegion, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); } - else if constexpr ( std::is_same_v< SUBREGION_TYPE, SurfaceElementSubRegion > ) + else if constexpr ( std::is_base_of_v< SurfaceElementSubRegion, SUBREGION_TYPE > ) { SurfaceElementAccumulationKernel kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); SurfaceElementAccumulationKernel::launch< POLICY >( subRegion.size(), kernel ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp index c912c8a1e63..792558b5b2e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ThermalAccumulationKernels.hpp @@ -311,13 +311,13 @@ class AccumulationKernelFactory CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) { - if constexpr ( std::is_same_v< SUBREGION_TYPE, CellElementSubRegion > ) + if constexpr ( std::is_base_of_v< CellElementSubRegion, SUBREGION_TYPE > ) { integer constexpr NUM_DOF = 2; AccumulationKernel< CellElementSubRegion, NUM_DOF > kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); AccumulationKernel< CellElementSubRegion, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel ); } - else if constexpr ( std::is_same_v< SUBREGION_TYPE, SurfaceElementSubRegion > ) + else if constexpr ( std::is_base_of_v< SurfaceElementSubRegion, SUBREGION_TYPE > ) { SurfaceElementAccumulationKernel kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs ); SurfaceElementAccumulationKernel::launch< POLICY >( subRegion.size(), kernel ); From 683733eca76ac49cd01795b3a332cf09194db372 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Tue, 15 Oct 2024 13:24:42 -0500 Subject: [PATCH 28/47] build fix --- .../physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp index 24c4f4eee38..33220f315c6 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/SinglePhaseWell.cpp @@ -37,6 +37,7 @@ #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" #include "physicsSolvers/fluidFlow/wells/kernels/SinglePhaseWellKernels.hpp" #include "physicsSolvers/fluidFlow/kernels/singlePhase/FluidUpdateKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/singlePhase/SolutionCheckKernel.hpp" #include "physicsSolvers/fluidFlow/wells/LogLevelsInfo.hpp" namespace geos From 86805765b9fa60e73656ae981886bc4fdc304993 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 1 Nov 2024 11:23:24 -0500 Subject: [PATCH 29/47] bug fix --- .../fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp index e5f07d5d20a..7fc163d40e0 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/singlePhase/ResidualNormKernel.hpp @@ -120,7 +120,7 @@ class ThermalResidualNormKernel : public solverBaseKernels::ResidualNormKernelBa real64 & energyNormalizer ) const { massNormalizer = LvArray::math::max( m_minNormalizer, m_mass_n[ei] ); - energyNormalizer = LvArray::math::max( m_minNormalizer, m_energy_n[ei] ); + energyNormalizer = LvArray::math::max( m_minNormalizer, LvArray::math::abs( m_energy_n[ei] ) ); // energy can be negative } GEOS_HOST_DEVICE From bc23865fdae2b3948ff376679973ce19c358218e Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Thu, 7 Nov 2024 16:13:00 -0600 Subject: [PATCH 30/47] Added flag for z formulation --- .vscode-codespaces/launch.json | 2 +- .vscode-codespaces/settings.json | 6 +- .../fluidFlow/CompositionalMultiphaseBase.cpp | 114 ++++++++++++--- .../fluidFlow/CompositionalMultiphaseBase.hpp | 35 +++++ .../fluidFlow/CompositionalMultiphaseFVM.cpp | 131 ++++++++++++++++++ .../fluidFlow/CompositionalMultiphaseFVM.hpp | 7 + .../CompositionalMultiphaseHybridFVM.cpp | 11 ++ .../CompositionalMultiphaseHybridFVM.hpp | 7 + 8 files changed, 293 insertions(+), 20 deletions(-) diff --git a/.vscode-codespaces/launch.json b/.vscode-codespaces/launch.json index deed20d9573..0d6e0ebb4c6 100644 --- a/.vscode-codespaces/launch.json +++ b/.vscode-codespaces/launch.json @@ -9,7 +9,7 @@ "name": "Debug geos", "type": "cppdbg", "request": "launch", - "program": "${userHome}/geos-build/bin/geosx", + "program": "${workspaceFolder}/build-self_build-relwithdebinfo/bin/geosx", "args": ["-i", "${workspaceFolder}/inputFiles/simplePDE/10x10x10Hex_LaplaceFEM_smoke.xml", "-o", "${userHome}/geos-output"], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/.vscode-codespaces/settings.json b/.vscode-codespaces/settings.json index 03d8b0fc930..0a3374c5270 100644 --- a/.vscode-codespaces/settings.json +++ b/.vscode-codespaces/settings.json @@ -1,9 +1,9 @@ { "cmake": { "sourceDirectory": "${workspaceFolder}/src", - "buildDirectory": "${userHome}/geos-build", - "installPrefix": "${userHome}/geos-install", - "cacheInit": "/workspaces/GEOS/host-configs/environment.cmake", + "buildDirectory": "${workspaceFolder}/build-self_build-relwithdebinfo", + "installPrefix": "${workspaceFolder}/install-self_build-relwithdebinfo", + "cacheInit": "${workspaceFolder}/host-configs/CVX/self_build.cmake", "configureSettings": { "BLT_MPI_COMMAND_APPEND": "--use-hwthread-cpus;--oversubscribe", "ENABLE_OPENMP": "OFF", diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 08e7176fdbe..aed4364d8a2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -92,6 +92,10 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, setInputFlag( InputFlags::OPTIONAL ). setDescription( GEOS_FMT( "Use mass formulation instead of molar. Warning : Affects {} rates units.", SourceFluxBoundaryCondition::catalogName() ) ); + this->registerWrapper( viewKeyStruct::useZFormulationFlagString(), &m_useZFormulation ). + setApplyDefaultValue( 0 ). + setInputFlag( InputFlags::OPTIONAL ). + setDescription( "Use overall composition (Z) formulation instead of component density." ); this->registerWrapper( viewKeyStruct::solutionChangeScalingFactorString(), &m_solutionChangeScalingFactor ). setSizedFromParent( 0 ). @@ -1372,27 +1376,44 @@ void CompositionalMultiphaseBase::assembleSystem( real64 const GEOS_UNUSED_PARAM { GEOS_MARK_FUNCTION; - assembleAccumulationAndVolumeBalanceTerms( domain, - dofManager, - localMatrix, - localRhs ); - - if( m_isJumpStabilized ) + if (m_useZFormulation) { - assembleStabilizedFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); + assembleZFormulationAccumulation( domain, + dofManager, + localMatrix, + localRhs ); + + assembleZFormulationFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); } else { - assembleFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); + assembleAccumulationAndVolumeBalanceTerms( domain, + dofManager, + localMatrix, + localRhs ); + + if( m_isJumpStabilized ) + { + assembleStabilizedFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); + } + else + { + assembleFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); + } } + } void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( DomainPartition & domain, @@ -1452,6 +1473,67 @@ void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( Dom } ); } +void CompositionalMultiphaseBase::assembleZFormulationAccumulation( DomainPartition & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const +{ + GEOS_MARK_FUNCTION; + + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, + MeshLevel const & mesh, + arrayView1d< string const > const & regionNames ) + { + mesh.getElemManager().forElementSubRegions( regionNames, + [&]( localIndex const, + ElementSubRegionBase const & subRegion ) + { + string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); + string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); + string const & solidName = subRegion.getReference< string >( viewKeyStruct::solidNamesString() ); + + MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); + CoupledSolidBase const & solid = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); + + // TODO: add the thermal case + /* + if( m_isThermal ) + { + thermalCompositionalMultiphaseBaseKernels:: + AccumulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + dofKey, + subRegion, + fluid, + solid, + localMatrix, + localRhs ); + } + else + { + } + */ + // isothermal for now + isothermalCompositionalMultiphaseBaseKernels:: + AccumulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + m_useSimpleAccumulation, + dofKey, + subRegion, + fluid, + solid, + localMatrix, + localRhs ); + } ); + } ); +} + void CompositionalMultiphaseBase::applyBoundaryConditions( real64 const time_n, real64 const dt, DomainPartition & domain, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index cfd06428707..d7c93d5ec78 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -234,7 +234,38 @@ class CompositionalMultiphaseBase : public FlowSolverBase DofManager const & dofManager, CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) const = 0; + + /** + * @brief assembles the accumulation term (Z formulation) for all cells + * @param time_n previous time value + * @param dt time step + * @param domain the physical domain object + * @param dofManager degree-of-freedom manager associated with the linear system + * @param localMatrix the system matrix + * @param localRhs the system right-hand side vector + */ + void assembleZFormulationAccumulation( DomainPartition & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const; + + /** + * @brief assembles the flux terms (Z formulation) for all cells + * @param time_n previous time value + * @param dt time step + * @param domain the physical domain object + * @param dofManager degree-of-freedom manager associated with the linear system + * @param matrix the system matrix + * @param rhs the system right-hand side vector + */ + virtual void + assembleZFormulationFluxTerms( real64 const dt, + DomainPartition const & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const = 0; /**@}*/ + struct viewKeyStruct : FlowSolverBase::viewKeyStruct { @@ -243,6 +274,7 @@ class CompositionalMultiphaseBase : public FlowSolverBase // inputs static constexpr char const * useMassFlagString() { return "useMass"; } + static constexpr char const * useZFormulationFlagString() { return "useZFormulation"; } static constexpr char const * relPermNamesString() { return "relPermNames"; } static constexpr char const * capPressureNamesString() { return "capPressureNames"; } static constexpr char const * diffusionNamesString() { return "diffusionNames"; } @@ -434,6 +466,9 @@ class CompositionalMultiphaseBase : public FlowSolverBase /// flag indicating whether mass or molar formulation should be used integer m_useMass; + /// flag indicating whether overall composition (Z) formulation should be used + integer m_useZFormulation; + /// flag to determine whether or not to apply capillary pressure integer m_hasCapPressure; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 784c7810169..511b5893252 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -289,6 +289,137 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, } ); } +void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, + DomainPartition const & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const +{ + GEOS_MARK_FUNCTION; + + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, + MeshLevel const & mesh, + arrayView1d< string const > const & ) + { + NumericalMethodsManager const & numericalMethodManager = domain.getNumericalMethodManager(); + FiniteVolumeManager const & fvManager = numericalMethodManager.getFiniteVolumeManager(); + FluxApproximationBase const & fluxApprox = fvManager.getFluxApproximation( m_discretizationName ); + + string const & elemDofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); + + fluxApprox.forAllStencils( mesh, [&] ( auto & stencil ) + { + typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); + + // Convective flux + if( m_isThermal ) + { + thermalCompositionalMultiphaseFVMKernels:: + FluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasCapPressure, + m_useTotalMassEquation, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + } + else + { + if( m_dbcParams.useDBC ) + { + dissipationCompositionalMultiphaseFVMKernels:: + FluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasCapPressure, + m_useTotalMassEquation, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView(), + m_dbcParams.omega, + getNonlinearSolverParameters().m_numNewtonIterations, + m_dbcParams.continuation, + m_dbcParams.miscible, + m_dbcParams.kappamin, + m_dbcParams.contMultiplier ); + } + else + { + isothermalCompositionalMultiphaseFVMKernels:: + FluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasCapPressure, + m_useTotalMassEquation, + fluxApprox.upwindingParams(), + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + } + } + + // Diffusive and dispersive flux + if( m_hasDiffusion || m_hasDispersion ) + { + + if( m_isThermal ) + { + thermalCompositionalMultiphaseFVMKernels:: + DiffusionDispersionFluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasDiffusion, + m_hasDispersion, + m_useTotalMassEquation, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + } + else + { + isothermalCompositionalMultiphaseFVMKernels:: + DiffusionDispersionFluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasDiffusion, + m_hasDispersion, + m_useTotalMassEquation, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + } + } + + } ); + } ); +} + void CompositionalMultiphaseFVM::assembleStabilizedFluxTerms( real64 const dt, DomainPartition const & domain, DofManager const & dofManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp index 88249873115..df0d1571977 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp @@ -138,6 +138,13 @@ class CompositionalMultiphaseFVM : public CompositionalMultiphaseBase CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) const override; + virtual void + assembleZFormulationFluxTerms( real64 const dt, + DomainPartition const & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const override; + virtual void updatePhaseMobility( ObjectManagerBase & dataGroup ) const override; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index bedfa0c3261..48613fd4f10 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -420,6 +420,17 @@ void CompositionalMultiphaseHybridFVM::assembleFluxTerms( real64 const dt, } ); } +void CompositionalMultiphaseHybridFVM::assembleZFormulationFluxTerms( real64 const dt, + DomainPartition const & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const +{ + // z formulation not implemented + GEOS_UNUSED_VAR( dt, domain, dofManager, localMatrix, localRhs ); + GEOS_ERROR( "Z formulation not yet available for this flow solver" ); +} + void CompositionalMultiphaseHybridFVM::assembleStabilizedFluxTerms( real64 const dt, DomainPartition const & domain, DofManager const & dofManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp index 45bea1e810e..7be5313ec0e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp @@ -134,6 +134,13 @@ class CompositionalMultiphaseHybridFVM : public CompositionalMultiphaseBase CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) const override; + virtual void + assembleZFormulationFluxTerms( real64 const dt, + DomainPartition const & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const override; + virtual void assembleStabilizedFluxTerms( real64 const dt, DomainPartition const & domain, From 483d91f838b8787cfaec8d497f2b3b06fdbae4bc Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Tue, 12 Nov 2024 13:38:39 -0600 Subject: [PATCH 31/47] Implemented Accumulation Kernel for Z formulation --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 42 +- .../CompositionalMultiphaseBaseFields.hpp | 8 + .../AccumulationZFormulationKernel.hpp | 500 ++++++++++++++++++ 3 files changed, 535 insertions(+), 15 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index aed4364d8a2..b9852549b03 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -43,6 +43,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SourceFluxStatistics.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" @@ -297,8 +298,19 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) m_isThermal = referenceFluid.isThermal(); } - // n_c components + one pressure ( + one temperature if needed ) - m_numDofPerCell = m_isThermal ? m_numComponents + 2 : m_numComponents + 1; + + if (m_useZFormulation) + // Z formulation - component densities and pressure are primary unknowns + // (n_c-1) overall compositions + one pressure + // Testing: let's have sum_c zc = 1 as explicit equation for now + m_numDofPerCell = m_numComponents + 1; + else + { + // default formulation - component densities and pressure are primary unknowns + // n_c components + one pressure ( + one temperature if needed ) + m_numDofPerCell = m_isThermal ? m_numComponents + 2 : m_numComponents + 1; + } + // 2. Register and resize all fields as necessary forDiscretizationOnMeshTargets( meshBodies, [&]( string const &, @@ -1517,19 +1529,19 @@ void CompositionalMultiphaseBase::assembleZFormulationAccumulation( DomainPartit } */ // isothermal for now - isothermalCompositionalMultiphaseBaseKernels:: - AccumulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - m_useSimpleAccumulation, - dofKey, - subRegion, - fluid, - solid, - localMatrix, - localRhs ); + isothermalCompositionalMultiphaseBaseKernels:: + AccumulationZFormulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + m_useSimpleAccumulation, + dofKey, + subRegion, + fluid, + solid, + localMatrix, + localRhs ); } ); } ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp index eb00898d8df..8fddb175273 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp @@ -72,6 +72,14 @@ DECLARE_FIELD( globalCompFraction, WRITE_AND_READ, "Global component fraction" ); +DECLARE_FIELD( globalCompFraction_k, + "globalCompFraction_k", + array2dLayoutComp, + 0, + NOPLOT, + NO_WRITE, + "Global component fraction updates at the previous sequential iteration" ); + DECLARE_FIELD( faceGlobalCompFraction, "faceGlobalCompFraction", array2dLayoutComp, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp new file mode 100644 index 00000000000..146335626c4 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp @@ -0,0 +1,500 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 AccumulationZFormulationKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_ACCUMULATIONZFORMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_ACCUMULATIONZFORMULATIONKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/solid/CoupledSolidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "mesh/ElementSubRegionBase.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelectors.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** AccumulationKernel ********************************/ + +/** + * @class AccumulationZFormulationKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @brief Define the interface for the assembly kernel in charge of accumulation and volume balance + */ +template< integer NUM_COMP, integer NUM_DOF> +class AccumulationZFormulationKernel +{ +public: + + /// Compile time value for the number of components + static constexpr integer numComp = NUM_COMP; + + /// Compute time value for the number of degrees of freedom + static constexpr integer numDof = NUM_DOF; + + /// Compute time value for the number of equations + static constexpr integer numEqn = NUM_DOF; + + /** + * @brief Constructor + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + AccumulationZFormulationKernel( localIndex const numPhases, + globalIndex const rankOffset, + string const dofKey, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< KernelFlags > const KernelFlags ) + : m_numPhases( numPhases ), + m_rankOffset( rankOffset ), + m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), + m_elemGhostRank( subRegion.ghostRank() ), + m_volume( subRegion.getElementVolume() ), + m_porosity( solid.getPorosity() ), + m_dPoro_dPres( solid.getDporosity_dPressure() ), + m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), + m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), + m_phaseDens( fluid.phaseDensity() ), + m_dPhaseDens( fluid.dPhaseDensity() ), + m_phaseCompFrac( fluid.phaseCompFraction() ), + m_dPhaseCompFrac( fluid.dPhaseCompFraction() ), + m_phaseFrac( fluid.phaseFraction() ), + m_dPhaseFrac( fluid.dPhaseFraction() ), + m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), + m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ), + m_compAmount_n( subRegion.getField< fields::flow::compAmount_n >() ), + m_localMatrix( localMatrix ), + m_localRhs( localRhs ), + m_KernelFlags( KernelFlags ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + // Pore volume information (used by both accumulation and volume balance) + + /// Pore volume at time n+1 + real64 poreVolume = 0.0; + + /// Derivative of pore volume with respect to pressure + real64 dPoreVolume_dPres = 0.0; + + // Residual information + + /// Index of the local row corresponding to this element + localIndex localRow = -1; + + /// Indices of the matrix rows/columns corresponding to the dofs in this element + globalIndex dofIndices[numDof]{}; + + /// C-array storage for the element local residual vector (all equations except volume balance) + real64 localResidual[numEqn]{}; + + /// C-array storage for the element local Jacobian matrix (all equations except volume balance, all dofs) + real64 localJacobian[numEqn][numDof]{}; + + }; + + /** + * @brief Getter for the ghost rank of an element + * @param[in] ei the element index + * @return the ghost rank of the element + */ + GEOS_HOST_DEVICE + integer elemGhostRank( localIndex const ei ) const + { return m_elemGhostRank( ei ); } + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] ei the element index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + // initialize the pore volume + stack.poreVolume = m_volume[ei] * m_porosity[ei][0]; + stack.dPoreVolume_dPres = m_volume[ei] * m_dPoro_dPres[ei][0]; + + // set row index and degrees of freedom indices for this element + stack.localRow = m_dofNumber[ei] - m_rankOffset; + for( integer idof = 0; idof < numDof; ++idof ) + { + stack.dofIndices[idof] = m_dofNumber[ei] + idof; + } + } + + /** + * @brief Compute the local accumulation contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + * @param[in] phaseAmountKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeAccumulation( localIndex const ei, + StackVariables & stack, + FUNC && phaseAmountKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; + arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compFrac = m_compFrac[ei]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; + + // calculate total component density from volume balance + // TO DO: create separate kernel + real64 totalDensity = 0.0; + real64 dtotalDensity_dP = 0.0; + real64 dtotalDensity_dC[numComp]{}; + + for( integer ic = 0; ic < numComp; ++ic ) + { + totalDensity += compDens[ic]; + dtotalDensity_dC[ic] = 0.0; + } + + //real64 const sum_phaseFrac_phaseDens = 0.0; + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + real64 const phaseDensInv = 1.0 / phaseDens[ip]; + //sum_phaseFrac_phaseDens += phaseFrac[ip] * phaseDensInv; + + dtotalDensity_dP += phaseDensInv * totalDensity * totalDensity * + (phaseFrac[ip] * phaseDensInv * dPhaseDens[ip][Deriv::dP] - dPhaseFrac[ip][Deriv::dP]); + + for( integer jc = 0; jc < numComp; ++jc ) + { + dtotalDensity_dC[jc] += phaseDensInv * totalDensity * totalDensity * + (phaseFrac[ip] * phaseDensInv * dPhaseDens[ip][Deriv::dC+jc] - dPhaseFrac[ip][Deriv::dC+jc]); + } + } + + std::cout << "Cell [" << ei << "]" << std::endl; + for( integer ic = 0; ic < numComp; ++ic ) + std::cout << "rho[" << ic << "] = " << compDens[ic] << std::endl; + for( integer ic = 0; ic < numComp; ++ic ) + std::cout << "z[" << ic << "] = " << compFrac[ic] << std::endl; + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + std::cout << "nu[" << ip << "] = " << phaseFrac[ip] << std::endl; + std::cout << "dnu[" << ip << "]_dP = " << dPhaseFrac[ip][Deriv::dP] << std::endl; + for( integer ic = 0; ic < numComp; ++ic ) + std::cout << "dnu[" << ip << "]_dz[" << ic << "] = " << dPhaseFrac[ip][Deriv::dC+ic] << std::endl; + } + + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + std::cout << "phaseDens[" << ip << "] = " << phaseDens[ip] << std::endl; + std::cout << "dphaseDens[" << ip << "]_dP = " << dPhaseDens[ip][Deriv::dP] << std::endl; + for( integer ic = 0; ic < numComp; ++ic ) + std::cout << "dphaseDens[" << ip << "]_dz[" << ic << "] = " << dPhaseDens[ip][Deriv::dC+ic] << std::endl; + } + + + + std::cout << "rhoT = " << totalDensity << std::endl; + std::cout << "drhoT_dP = " << dtotalDensity_dP << std::endl; + for( integer ic = 0; ic < numComp; ++ic ) + std::cout << "drhoT_dC[" << ic << "] = " << dtotalDensity_dC[ic] << std::endl; + + // ic - index of component whose conservation equation is assembled + // (i.e. row number in local matrix) + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const compAmount = stack.poreVolume * totalDensity * compFrac[ic]; + real64 const compAmount_n = m_compAmount_n[ei][ic]; + + stack.localResidual[ic] += compAmount - compAmount_n; + + // derivatives with respect to pressure (p) + real64 const dCompAmount_dP = compFrac[ic] * (stack.dPoreVolume_dPres * totalDensity + stack.poreVolume * dtotalDensity_dP); + stack.localJacobian[ic][0] += dCompAmount_dP; + + // derivatives with respect to global component fraction (zc) + for( integer jc = 0; jc < numComp; ++jc ) + { + real64 dCompAmount_dC; + if (ic == jc) + dCompAmount_dC = stack.poreVolume * (totalDensity + dtotalDensity_dC[jc] * compFrac[ic]); + else + dCompAmount_dC = stack.poreVolume * (dtotalDensity_dC[jc] * compFrac[ic]); + + stack.localJacobian[ic][jc + 1] += dCompAmount_dC; + } + } + + for( integer ic = 0; ic < numComp; ++ic ) + { + std::cout << "Raccum[" << ic << "] = " << stack.localResidual[ic] << std::endl; + std::cout << "dRaccum[" << ic << "]_dP = " << stack.localJacobian[ic][0] << std::endl; + for( integer jc = 0; jc < numComp; ++jc ) + { + std::cout << "dRaccum[" << ic << "]_dz[" << jc << "] = " << stack.localJacobian[ic][jc+1] << std::endl; + } + + } + } + + /** + * @brief Compute the local volume balance contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + * @param[in] phaseVolFractionSumKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeVolumeBalance( localIndex const ei, + StackVariables & stack, + FUNC && phaseVolFractionSumKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > compFrac = m_compFrac[ei]; + + real64 oneMinusCompFracSum = 1.0; + + // sum contributions to component accumulation from each component + for( integer ic = 0; ic < numComp; ++ic ) + { + oneMinusCompFracSum -= compFrac[ic]; + // no derivatives w.r.t pressure + + // derivative w.r.t component fractions are unity: dzc_dzc = 1 + stack.localJacobian[numComp][ic+1] -= 1; + } + + // scale componentFraction-based volume balance by pore volume (for better scaling w.r.t. other equations) + stack.localResidual[numComp] = stack.poreVolume * oneMinusCompFracSum; + for( integer idof = 0; idof < numDof; ++idof ) + { + stack.localJacobian[numComp][idof] *= stack.poreVolume; + } + stack.localJacobian[numComp][0] += stack.dPoreVolume_dPres * oneMinusCompFracSum; + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void complete( localIndex const GEOS_UNUSED_PARAM( ei ), + StackVariables & stack ) const + { + using namespace compositionalMultiphaseUtilities; + + if( m_KernelFlags.isSet( KernelFlags::TotalMassEquation ) ) + { + // apply equation/variable change transformation to the component mass balance equations + real64 work[numDof]{}; + shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numDof, stack.localJacobian, work ); + shiftElementsAheadByOneAndReplaceFirstElementWithSum( numComp, stack.localResidual ); + } + + // add contribution to residual and jacobian into: + // - the component mass balance equations (i = 0 to i = numComp-1) + // - the volume balance equations (i = numComp) + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + integer const numRows = numComp+1; + for( integer i = 0; i < numRows; ++i ) + { + m_localRhs[stack.localRow + i] += stack.localResidual[i]; + m_localMatrix.addToRow< serialAtomic >( stack.localRow + i, + stack.dofIndices, + stack.localJacobian[i], + numDof ); + } + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + GEOS_MARK_FUNCTION; + + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( kernelComponent.elemGhostRank( ei ) >= 0 ) + { + return; + } + + typename KERNEL_TYPE::StackVariables stack; + + kernelComponent.setup( ei, stack ); + kernelComponent.computeAccumulation( ei, stack ); + kernelComponent.computeVolumeBalance( ei, stack ); + kernelComponent.complete( ei, stack ); + } ); + } + +protected: + + /// Number of fluid phases + integer const m_numPhases; + + /// Offset for my MPI rank + globalIndex const m_rankOffset; + + /// View on the dof numbers + arrayView1d< globalIndex const > const m_dofNumber; + + /// View on the ghost ranks + arrayView1d< integer const > const m_elemGhostRank; + + /// View on the element volumes + arrayView1d< real64 const > const m_volume; + + /// Views on the porosity + arrayView2d< real64 const > const m_porosity; + arrayView2d< real64 const > const m_dPoro_dPres; + + /// Views on the derivatives of comp fractions wrt component density + arrayView3d< real64 const, compflow::USD_COMP_DC > const m_dCompFrac_dCompDens; + + /// Views on the phase volume fractions + arrayView2d< real64 const, compflow::USD_PHASE > const m_phaseVolFrac; + arrayView3d< real64 const, compflow::USD_PHASE_DC > const m_dPhaseVolFrac; + + /// Views on phase fractions + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseFrac; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseFrac; + + /// Views on the phase densities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseDens; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseDens; + + /// Views on the phase component fraction + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > const m_phaseCompFrac; + arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > const m_dPhaseCompFrac; + + // View on component densities and component fractions + arrayView2d< real64 const, compflow::USD_COMP > m_compDens; + arrayView2d< real64 const, compflow::USD_COMP > m_compFrac; + + // View on component amount (mass/moles) from previous time step + arrayView2d< real64 const, compflow::USD_COMP > m_compAmount_n; + + /// View on the local CRS matrix + CRSMatrixView< real64, globalIndex const > const m_localMatrix; + /// View on the local RHS + arrayView1d< real64 > const m_localRhs; + + BitFlags< KernelFlags > const m_KernelFlags; +}; + +/** + * @class AccumulationZFormulationKernelFactory + */ +class AccumulationZFormulationKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey the string key to retrieve the degress of freedom numbers + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] solid the solid model + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + integer const useTotalMassEquation, + integer const useSimpleAccumulation, + string const dofKey, + ElementSubRegionBase const & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::CoupledSolidBase const & solid, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + internal::kernelLaunchSelectorCompSwitch( numComps, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC()+1; + + BitFlags< KernelFlags > KernelFlags; + if( useTotalMassEquation ) + KernelFlags.set( KernelFlags::TotalMassEquation ); + if( useSimpleAccumulation ) + KernelFlags.set( KernelFlags::SimpleAccumulation ); + + AccumulationZFormulationKernel< NUM_COMP, NUM_DOF> kernel( numPhases, rankOffset, dofKey, subRegion, + fluid, solid, localMatrix, localRhs, KernelFlags ); + AccumulationZFormulationKernel< NUM_COMP, NUM_DOF>::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_ACCUMULATIONZFORMULATIONKERNEL_HPP From 23c0cd4dccb052a90d995b29856fb818f4523ee2 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Tue, 12 Nov 2024 17:05:03 -0600 Subject: [PATCH 32/47] Reorganized flag, started the Z-based flux implementation --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 53 ++-- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 41 +-- .../compositional/FluxComputeKernel.hpp | 36 ++- .../compositional/FluxComputeKernelBase.hpp | 4 +- .../AccumulationZFormulationKernel.hpp | 0 ...balComponentFractionZFormulationKernel.hpp | 144 ++++++++++ .../zFormulation/PPUPhaseFluxZFormulation.hpp | 159 +++++++++++ .../PhaseComponentFluxZFormulation.hpp | 120 +++++++++ .../PhaseMobilityZFormulationKernel.hpp | 241 +++++++++++++++++ .../PhaseVolumeFractionZFormulationKernel.hpp | 253 ++++++++++++++++++ .../zFormulation/PotGradZFormulation.hpp | 180 +++++++++++++ 11 files changed, 1188 insertions(+), 43 deletions(-) rename src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/{ => zFormulation}/AccumulationZFormulationKernel.hpp (100%) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index b9852549b03..364c0bdbd88 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -43,7 +43,7 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SourceFluxStatistics.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" @@ -1388,18 +1388,22 @@ void CompositionalMultiphaseBase::assembleSystem( real64 const GEOS_UNUSED_PARAM { GEOS_MARK_FUNCTION; + /* + assembleZFormulationFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); + */ + + + // Accumulation term if (m_useZFormulation) { assembleZFormulationAccumulation( domain, dofManager, localMatrix, localRhs ); - - assembleZFormulationFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); } else { @@ -1407,25 +1411,26 @@ void CompositionalMultiphaseBase::assembleSystem( real64 const GEOS_UNUSED_PARAM dofManager, localMatrix, localRhs ); - - if( m_isJumpStabilized ) - { - assembleStabilizedFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); - } - else - { - assembleFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); - } } + + // Flux term + if( m_isJumpStabilized ) + { + assembleStabilizedFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); + } + else + { + assembleFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); + } } void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( DomainPartition & domain, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 511b5893252..6f0c0ff913f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -233,6 +233,7 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, elemDofKey, m_hasCapPressure, m_useTotalMassEquation, + m_useZFormulation, fluxApprox.upwindingParams(), getName(), mesh.getElemManager(), @@ -311,6 +312,7 @@ void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, { typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); + /* // Convective flux if( m_isThermal ) { @@ -356,24 +358,30 @@ void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, } else { - isothermalCompositionalMultiphaseFVMKernels:: - FluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasCapPressure, - m_useTotalMassEquation, - fluxApprox.upwindingParams(), - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); } } + */ + // isothermal only for now + isothermalCompositionalMultiphaseFVMKernels:: + FluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasCapPressure, + m_useTotalMassEquation, + m_useZFormulation, + fluxApprox.upwindingParams(), + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + + // TO DO: implement diffusion and dispersion flux for Z formulation + /* // Diffusive and dispersive flux if( m_hasDiffusion || m_hasDispersion ) { @@ -413,8 +421,9 @@ void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, dt, localMatrix.toViewConstSizes(), localRhs.toView() ); - } + } } + */ } ); } ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp index 4a46588f638..c6b3576eff8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp @@ -35,6 +35,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp" namespace geos { @@ -325,7 +326,34 @@ class FluxComputeKernel : public FluxComputeKernelBase } else { - isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFlux::compute< numComp, numFluxSupportPoints > + if( m_kernelFlags.isSet( FluxComputeKernelFlags::useZFormulation ) ) + { + isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFluxZFormulation::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + else + { + isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFlux::compute< numComp, numFluxSupportPoints > ( m_numPhases, ip, m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), @@ -348,6 +376,8 @@ class FluxComputeKernel : public FluxComputeKernelBase compFlux, dCompFlux_dP, dCompFlux_dC ); + } + } // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives @@ -525,6 +555,7 @@ class FluxComputeKernelFactory string const & dofKey, integer const hasCapPressure, integer const useTotalMassEquation, + integer const useZFormulation, UpwindingParameters upwindingParams, string const & solverName, ElementRegionManager const & elemManager, @@ -552,7 +583,8 @@ class FluxComputeKernelFactory kernelFlags.set( FluxComputeKernelFlags::C1PPU ); else if( upwindingParams.upwindingScheme == UpwindingScheme::IHU ) kernelFlags.set( FluxComputeKernelFlags::IHU ); - + if( useZFormulation ) + kernelFlags.set( FluxComputeKernelFlags::useZFormulation ); using kernelType = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp index e794c992954..ce7b308efcf 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp @@ -50,7 +50,9 @@ enum class FluxComputeKernelFlags /// Flag indicating whether C1-PPU is used or not C1PPU = 1 << 2, // 4 /// Flag indicating whether IHU is used or not - IHU = 1 << 3 // 8 + IHU = 1 << 3, // 8 + /// Flag indicating whether overall composition (Z) formulation is used or not + useZFormulation = 1 << 4 // 16 /// Add more flags like that if needed: // Flag5 = 1 << 4, // 16 // Flag6 = 1 << 5, // 32 diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp similarity index 100% rename from src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/AccumulationZFormulationKernel.hpp rename to src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp new file mode 100644 index 00000000000..e8d53a625ba --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp @@ -0,0 +1,144 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 GlobalComponentFractionKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** GlobalComponentFractionKernel ********************************/ + +/** + * @class GlobalComponentFractionKernel + * @tparam NUM_COMP number of fluid components + * @brief Define the interface for the update kernel in charge of computing the phase volume fractions + */ +template< integer NUM_COMP > +class GlobalComponentFractionKernel : public PropertyKernelBase< NUM_COMP > +{ +public: + + using Base = PropertyKernelBase< NUM_COMP >; + using Base::numComp; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + GlobalComponentFractionKernel( ObjectManagerBase & subRegion ) + : Base(), + m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), + m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ), + m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ) + {} + + /** + * @brief Compute the phase volume fractions in an element + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[in] phaseVolFractionKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void compute( localIndex const ei, + FUNC && compFractionKernelOp = NoOpFunc{} ) const + { + arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; + arraySlice1d< real64, compflow::USD_COMP - 1 > const compFrac = m_compFrac[ei]; + arraySlice2d< real64, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; + + real64 totalDensity = 0.0; + + for( integer ic = 0; ic < numComp; ++ic ) + { + totalDensity += compDens[ic]; + } + + real64 const totalDensityInv = 1.0 / totalDensity; + + for( integer ic = 0; ic < numComp; ++ic ) + { + compFrac[ic] = compDens[ic] * totalDensityInv; + for( integer jc = 0; jc < numComp; ++jc ) + { + dCompFrac_dCompDens[ic][jc] = -compFrac[ic] * totalDensityInv; + } + dCompFrac_dCompDens[ic][ic] += totalDensityInv; + } + + compFractionKernelOp( compFrac, dCompFrac_dCompDens ); + } + +protected: + + // inputs + + // Views on component densities + arrayView2d< real64 const, compflow::USD_COMP > m_compDens; + + // outputs + + // Views on component fraction + arrayView2d< real64, compflow::USD_COMP > m_compFrac; + arrayView3d< real64, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; + +}; + +/** + * @class GlobalComponentFractionKernelFactory + */ +class GlobalComponentFractionKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComp, + ObjectManagerBase & subRegion ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + GlobalComponentFractionKernel< NUM_COMP > kernel( subRegion ); + GlobalComponentFractionKernel< NUM_COMP >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp new file mode 100644 index 00000000000..c718b4fefa2 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp @@ -0,0 +1,159 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PPUPhaseFluxZFormulation.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PPUPHASEFLUXZFORMULATION_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PPUPHASEFLUXZFORMULATION_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "constitutive/fluid/multifluid/Layouts.hpp" +#include "constitutive/capillaryPressure/layouts.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernelUtilities +{ + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +using Deriv = constitutive::multifluid::DerivativeOffset; + +struct PPUPhaseFluxZFormulation +{ + /** + * @brief Form the PhasePotentialUpwind from pressure gradient and gravitational head + * @tparam numComp number of components + * @tparam numFluxSupportPoints number of flux support points + * @param numPhase number of phases + * @param ip phase index + * @param hasCapPressure flag indicating if there is capillary pressure + * @param seri arraySlice of the stencil-implied element region index + * @param sesri arraySlice of the stencil-implied element subregion index + * @param sei arraySlice of the stencil-implied element index + * @param trans transmissibility at the connection + * @param dTrans_dPres derivative of transmissibility wrt pressure + * @param pres pressure + * @param gravCoef gravitational coefficient + * @param phaseMob phase mobility + * @param dPhaseMob derivative of phase mobility wrt pressure, temperature, comp density + * @param dPhaseVolFrac derivative of phase volume fraction wrt pressure, temperature, comp density + * @param phaseMassDens phase mass density + * @param dPhaseMassDens derivative of phase mass density wrt pressure, temperature, comp fraction + * @param phaseCapPressure phase capillary pressure + * @param dPhaseCapPressure_dPhaseVolFrac derivative of phase capillary pressure wrt phase volume fraction + * @param k_up uptream index for this phase + * @param potGrad potential gradient for this phase + * @param phaseFlux phase flux + * @param dPhaseFlux_dP derivative of phase flux wrt pressure + * @param dPhaseFlux_dC derivative of phase flux wrt comp density + */ + template< integer numComp, integer numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + compute( integer const numPhase, + integer const ip, + integer const hasCapPressure, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + real64 const ( &trans )[2], + real64 const ( &dTrans_dPres )[2], + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseMob, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseMob, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, + ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, + ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, + localIndex & k_up, + real64 & potGrad, + real64 ( &phaseFlux ), + real64 ( & dPhaseFlux_dP )[numFluxSupportPoints], + real64 ( & dPhaseFlux_dC )[numFluxSupportPoints][numComp], + real64 ( & compFlux )[numComp], + real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], + real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) + { + real64 dPresGrad_dP[numFluxSupportPoints]{}; + real64 dPresGrad_dC[numFluxSupportPoints][numComp]{}; + real64 dGravHead_dP[numFluxSupportPoints]{}; + real64 dGravHead_dC[numFluxSupportPoints][numComp]{}; + PotGradZFormulation::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, seri, sesri, sei, trans, dTrans_dPres, pres, + gravCoef, dPhaseVolFrac, phaseMassDens, dPhaseMassDens, + phaseCapPressure, dPhaseCapPressure_dPhaseVolFrac, potGrad, dPresGrad_dP, + dPresGrad_dC, dGravHead_dP, dGravHead_dC ); + + // *** upwinding *** + + // choose upstream cell + k_up = (potGrad >= 0) ? 0 : 1; + + localIndex const er_up = seri[k_up]; + localIndex const esr_up = sesri[k_up]; + localIndex const ei_up = sei[k_up]; + + real64 const mobility = phaseMob[er_up][esr_up][ei_up][ip]; + + // pressure gradient depends on all points in the stencil + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dPhaseFlux_dP[ke] += dPresGrad_dP[ke] - dGravHead_dP[ke]; + dPhaseFlux_dP[ke] *= mobility; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[ke][jc] += dPresGrad_dC[ke][jc] - dGravHead_dC[ke][jc]; + dPhaseFlux_dC[ke][jc] *= mobility; + } + } + // compute phase flux using upwind mobility. + phaseFlux = mobility * potGrad; + + real64 const dMob_dP = dPhaseMob[er_up][esr_up][ei_up][ip][Deriv::dP]; + arraySlice1d< real64 const, compflow::USD_PHASE_DC - 2 > dPhaseMobSub = + dPhaseMob[er_up][esr_up][ei_up][ip]; + + // add contribution from upstream cell mobility derivatives + dPhaseFlux_dP[k_up] += dMob_dP * potGrad; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[k_up][jc] += dPhaseMobSub[Deriv::dC+jc] * potGrad; + } + + //distribute on phaseComponentFlux here + PhaseComponentFluxZFormulation::compute( ip, k_up, seri, sesri, sei, phaseCompFrac, dPhaseCompFrac, phaseFlux + , dPhaseFlux_dP, dPhaseFlux_dC, compFlux, dCompFlux_dP, dCompFlux_dC ); + + } +}; + +} // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities + +} // namespace geos + + +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PPUPHASEFLUXZFORMULATION_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp new file mode 100644 index 00000000000..ed6c4b0adef --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp @@ -0,0 +1,120 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PhaseComponentFluxZFormulation.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUXZFORMULATION_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUXZFORMULATION_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "constitutive/fluid/multifluid/Layouts.hpp" +#include "mesh/ElementRegionManager.hpp" + + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernelUtilities +{ + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +using Deriv = constitutive::multifluid::DerivativeOffset; + +struct PhaseComponentFluxZFormulation +{ + /** + * @brief Compute the component flux for a given phase + * @tparam numComp number of components + * @tparam numFluxSupportPoints number of flux support points + * @param ip phase index + * @param k_up uptream index for this phase + * @param seri arraySlice of the stencil-implied element region index + * @param sesri arraySlice of the stencil-implied element subregion index + * @param sei arraySlice of the stencil-implied element index + * @param phaseCompFrac phase component fraction + * @param dPhaseCompFrac derivative of phase component fraction wrt pressure, temperature, component fraction + * @param dCompFrac_dCompDens derivative of component fraction wrt component density + * @param phaseFlux phase flux + * @param dPhaseFlux_dP derivative of phase flux wrt pressure + * @param dPhaseFlux_dC derivative of phase flux wrt comp density + * @param compFlux component flux + * @param dCompFlux_dP derivative of phase flux wrt pressure + * @param dCompFlux_dC derivative of phase flux wrt comp density + */ + template< localIndex numComp, localIndex numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + compute( localIndex const ip, + localIndex const k_up, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, + ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, + real64 const & phaseFlux, + real64 const ( &dPhaseFlux_dP )[numFluxSupportPoints], + real64 const ( &dPhaseFlux_dC )[numFluxSupportPoints][numComp], + real64 ( & compFlux )[numComp], + real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp], + real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] ) + { + localIndex const er_up = seri[k_up]; + localIndex const esr_up = sesri[k_up]; + localIndex const ei_up = sei[k_up]; + + // slice some constitutive arrays to avoid too much indexing in component loop + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub = + phaseCompFrac[er_up][esr_up][ei_up][0][ip]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub = + dPhaseCompFrac[er_up][esr_up][ei_up][0][ip]; + + // compute component fluxes and derivatives using upstream cell composition + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = phaseCompFracSub[ic]; + compFlux[ic] += phaseFlux * ycp; + + // derivatives stemming from phase flux + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + dCompFlux_dP[ke][ic] += dPhaseFlux_dP[ke] * ycp; + for( integer jc = 0; jc < numComp; ++jc ) + { + dCompFlux_dC[ke][ic][jc] += dPhaseFlux_dC[ke][jc] * ycp; + } + } + + // additional derivatives stemming from upstream cell phase composition + dCompFlux_dP[k_up][ic] += phaseFlux * dPhaseCompFracSub[ic][Deriv::dP]; + + // convert derivatives of comp fraction w.r.t. comp fractions to derivatives w.r.t. comp densities + for( integer jc = 0; jc < numComp; ++jc ) + { + dCompFlux_dC[k_up][ic][jc] += phaseFlux * dPhaseCompFracSub[ic][Deriv::dC+jc]; + } + } + } +}; + +} // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities + +} // namespace geos + +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUXZFORMULATION_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp new file mode 100644 index 00000000000..3bf95052767 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp @@ -0,0 +1,241 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PhaseMobilityZFormulationKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEMOBILITYZFORMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEMOBILITYZFORMULATIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** PhaseMobilityZFormulationKernel ********************************/ + +/** + * @class PhaseMobilityZFormulationKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_PHASE number of fluid phases + * @brief Defines the interface for the property kernel in charge of computing the phase mobilities + */ +template< integer NUM_COMP, integer NUM_PHASE > +class PhaseMobilityZFormulationKernel : public isothermalCompositionalMultiphaseBaseKernels::PropertyKernelBase< NUM_COMP > +{ +public: + + using Base = isothermalCompositionalMultiphaseBaseKernels::PropertyKernelBase< NUM_COMP >; + using Base::numComp; + + /// Compile time value for the number of phases + static constexpr integer numPhase = NUM_PHASE; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] relperm the relperm model + */ + PhaseMobilityZFormulationKernel( ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::RelativePermeabilityBase const & relperm ) + : Base(), + m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), + m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), + m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), + m_phaseDens( fluid.phaseDensity() ), + m_dPhaseDens( fluid.dPhaseDensity() ), + m_phaseVisc( fluid.phaseViscosity() ), + m_dPhaseVisc( fluid.dPhaseViscosity() ), + m_phaseRelPerm( relperm.phaseRelPerm() ), + m_dPhaseRelPerm_dPhaseVolFrac( relperm.dPhaseRelPerm_dPhaseVolFraction() ), + m_phaseMob( subRegion.getField< fields::flow::phaseMobility >() ), + m_dPhaseMob( subRegion.getField< fields::flow::dPhaseMobility >() ) + {} + + /** + * @brief Compute the phase mobilities in an element + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[in] phaseMobilityKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void compute( localIndex const ei, + FUNC && phaseMobilityKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseVisc = m_phaseVisc[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseVisc = m_dPhaseVisc[ei][0]; + arraySlice1d< real64 const, constitutive::relperm::USD_RELPERM - 2 > const phaseRelPerm = m_phaseRelPerm[ei][0]; + arraySlice2d< real64 const, constitutive::relperm::USD_RELPERM_DS - 2 > const dPhaseRelPerm_dPhaseVolFrac = m_dPhaseRelPerm_dPhaseVolFrac[ei][0]; + arraySlice1d< real64 const, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; + arraySlice2d< real64 const, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; + arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseMob = m_phaseMob[ei]; + arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseMob = m_dPhaseMob[ei]; + + real64 dRelPerm_dC[numComp]{}; + real64 dDens_dC[numComp]{}; + real64 dVisc_dC[numComp]{}; + + for( integer ip = 0; ip < numPhase; ++ip ) + { + + // compute the phase mobility only if the phase is present + bool const phaseExists = (phaseVolFrac[ip] > 0); + if( !phaseExists ) + { + phaseMob[ip] = 0.0; + for( integer jc = 0; jc < numComp + 2; ++jc ) + { + dPhaseMob[ip][jc] = 0.0; + } + continue; + } + + real64 const density = phaseDens[ip]; + real64 const dDens_dP = dPhaseDens[ip][Deriv::dP]; + applyChainRule( numComp, dCompFrac_dCompDens, dPhaseDens[ip], dDens_dC, Deriv::dC ); + + real64 const viscosity = phaseVisc[ip]; + real64 const dVisc_dP = dPhaseVisc[ip][Deriv::dP]; + applyChainRule( numComp, dCompFrac_dCompDens, dPhaseVisc[ip], dVisc_dC, Deriv::dC ); + + real64 const relPerm = phaseRelPerm[ip]; + real64 dRelPerm_dP = 0.0; + for( integer ic = 0; ic < numComp; ++ic ) + { + dRelPerm_dC[ic] = 0.0; + } + + for( integer jp = 0; jp < numPhase; ++jp ) + { + real64 const dRelPerm_dS = dPhaseRelPerm_dPhaseVolFrac[ip][jp]; + dRelPerm_dP += dRelPerm_dS * dPhaseVolFrac[jp][Deriv::dP]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + dRelPerm_dC[jc] += dRelPerm_dS * dPhaseVolFrac[jp][Deriv::dC+jc]; + } + } + + real64 const mobility = relPerm * density / viscosity; + + phaseMob[ip] = mobility; + dPhaseMob[ip][Deriv::dP] = dRelPerm_dP * density / viscosity + + mobility * (dDens_dP / density - dVisc_dP / viscosity); + + // compositional derivatives + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseMob[ip][Deriv::dC+jc] = dRelPerm_dC[jc] * density / viscosity + + mobility * (dDens_dC[jc] / density - dVisc_dC[jc] / viscosity); + } + + // call the lambda in the phase loop to allow the reuse of the relperm, density, viscosity, and mobility + // possible use: assemble the derivatives wrt temperature + phaseMobilityKernelOp( ip, phaseMob[ip], dPhaseMob[ip] ); + } + } + +protected: + + // inputs + + /// Views on the phase volume fractions + arrayView2d< real64 const, compflow::USD_PHASE > m_phaseVolFrac; + arrayView3d< real64 const, compflow::USD_PHASE_DC > m_dPhaseVolFrac; + arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; + + /// Views on the phase densities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseDens; + + /// Views on the phase viscosities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseVisc; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseVisc; + + /// Views on the phase relative permeabilities + arrayView3d< real64 const, constitutive::relperm::USD_RELPERM > m_phaseRelPerm; + arrayView4d< real64 const, constitutive::relperm::USD_RELPERM_DS > m_dPhaseRelPerm_dPhaseVolFrac; + + // outputs + + /// Views on the phase mobilities + arrayView2d< real64, compflow::USD_PHASE > m_phaseMob; + arrayView3d< real64, compflow::USD_PHASE_DC > m_dPhaseMob; + +}; + +/** + * @class PhaseMobilityZFormulationKernelFactory + */ +class PhaseMobilityZFormulationKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] numPhase the number of fluid phases + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + * @param[in] relperm the relperm model + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComp, + integer const numPhase, + ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid, + constitutive::RelativePermeabilityBase const & relperm ) + { + if( numPhase == 2 ) + { + isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseMobilityZFormulationKernel< NUM_COMP, 2 > kernel( subRegion, fluid, relperm ); + PhaseMobilityZFormulationKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + else if( numPhase == 3 ) + { + isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseMobilityZFormulationKernel< NUM_COMP, 3 > kernel( subRegion, fluid, relperm ); + PhaseMobilityZFormulationKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + } +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEMOBILITYZFORMULATIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp new file mode 100644 index 00000000000..92457153cbb --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp @@ -0,0 +1,253 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PhaseVolumeFractionZFormulationKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEVOLUMEFRACTIONZFORMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEVOLUMEFRACTIONZFORMULATIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** PhaseVolumeFractionZFormulationKernel ********************************/ + +/** + * @class PhaseVolumeFractionZFormulationKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_PHASE number of fluid phases + * @brief Define the interface for the property kernel in charge of computing the phase volume fractions + */ +template< integer NUM_COMP, integer NUM_PHASE > +class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COMP > +{ +public: + + using Base = PropertyKernelBase< NUM_COMP >; + using Base::numComp; + + /// Compile time value for the number of phases + static constexpr integer numPhase = NUM_PHASE; + + /** + * @brief Constructor + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + PhaseVolumeFractionZFormulationKernel( ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid ) + : Base(), + m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), + m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), + m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), + m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), + m_phaseFrac( fluid.phaseFraction() ), + m_dPhaseFrac( fluid.dPhaseFraction() ), + m_phaseDens( fluid.phaseDensity() ), + m_dPhaseDens( fluid.dPhaseDensity() ) + {} + + /** + * @brief Compute the phase volume fractions in an element + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[in] phaseVolFractionKernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + real64 compute( localIndex const ei, + FUNC && phaseVolFractionKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + + arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; + arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; + arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; + arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; + + real64 work[numComp]{}; + + // compute total density from component partial densities + real64 totalDensity = 0.0; + real64 const dTotalDens_dCompDens = 1.0; + for( integer ic = 0; ic < numComp; ++ic ) + { + totalDensity += compDens[ic]; + } + + real64 maxDeltaPhaseVolFrac = 0.0; + + for( integer ip = 0; ip < numPhase; ++ip ) + { + + // set the saturation to zero if the phase is absent + bool const phaseExists = (phaseFrac[ip] > 0); + if( !phaseExists ) + { + phaseVolFrac[ip] = 0.; + for( integer jc = 0; jc < numComp+2; ++jc ) + { + dPhaseVolFrac[ip][jc] = 0.; + } + continue; + } + + // Expression for volume fractions: S_p = (nu_p / rho_p) * rho_t + real64 const phaseDensInv = 1.0 / phaseDens[ip]; + + // store old saturation to compute change later + real64 const satOld = phaseVolFrac[ip]; + + // compute saturation and derivatives except multiplying by the total density + phaseVolFrac[ip] = phaseFrac[ip] * phaseDensInv; + + dPhaseVolFrac[ip][Deriv::dP] = + (dPhaseFrac[ip][Deriv::dP] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dP]) * phaseDensInv; + + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseVolFrac[ip][Deriv::dC+jc] = + (dPhaseFrac[ip][Deriv::dC+jc] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dC+jc]) * phaseDensInv; + } + + // call the lambda in the phase loop to allow the reuse of the phaseVolFrac and totalDensity + // possible use: assemble the derivatives wrt temperature + phaseVolFractionKernelOp( ip, phaseVolFrac[ip], phaseDensInv, totalDensity ); + + // now finalize the computation by multiplying by total density + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseVolFrac[ip][Deriv::dC+jc] *= totalDensity; + dPhaseVolFrac[ip][Deriv::dC+jc] += phaseVolFrac[ip] * dTotalDens_dCompDens; + } + + phaseVolFrac[ip] *= totalDensity; + dPhaseVolFrac[ip][Deriv::dP] *= totalDensity; + + real64 const deltaPhaseVolFrac = LvArray::math::abs( phaseVolFrac[ip] - satOld ); + if( maxDeltaPhaseVolFrac < deltaPhaseVolFrac ) + { + maxDeltaPhaseVolFrac = deltaPhaseVolFrac; + } + } + return maxDeltaPhaseVolFrac; + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static real64 + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPhaseVolFrac( 0.0 ); + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + real64 const deltaPhaseVolFrac = kernelComponent.compute( ei ); + maxDeltaPhaseVolFrac.max( deltaPhaseVolFrac ); + } ); + return maxDeltaPhaseVolFrac.get(); + } + +protected: + + // outputs + + /// Views on phase volume fractions + arrayView2d< real64, compflow::USD_PHASE > m_phaseVolFrac; + arrayView3d< real64, compflow::USD_PHASE_DC > m_dPhaseVolFrac; + + // inputs + + /// Views on component densities + arrayView2d< real64 const, compflow::USD_COMP > m_compDens; + arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; + + /// Views on phase fractions + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseFrac; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseFrac; + + /// Views on phase densities + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseDens; + +}; + +/** + * @class PhaseVolumeFractionZFormulationKernelFactory + */ +class PhaseVolumeFractionZFormulationKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComp the number of fluid components + * @param[in] numPhase the number of fluid phases + * @param[in] subRegion the element subregion + * @param[in] fluid the fluid model + */ + template< typename POLICY > + static real64 + createAndLaunch( integer const numComp, + integer const numPhase, + ObjectManagerBase & subRegion, + constitutive::MultiFluidBase const & fluid ) + { + real64 maxDeltaPhaseVolFrac = 0.0; + if( numPhase == 2 ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseVolumeFractionZFormulationKernel< NUM_COMP, 2 > kernel( subRegion, fluid ); + maxDeltaPhaseVolFrac = PhaseVolumeFractionZFormulationKernel< NUM_COMP, 2 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + else if( numPhase == 3 ) + { + internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) + { + integer constexpr NUM_COMP = NC(); + PhaseVolumeFractionZFormulationKernel< NUM_COMP, 3 > kernel( subRegion, fluid ); + maxDeltaPhaseVolFrac = PhaseVolumeFractionZFormulationKernel< NUM_COMP, 3 >::template launch< POLICY >( subRegion.size(), kernel ); + } ); + } + return maxDeltaPhaseVolFrac; + } +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASEVOLUMEFRACTIONZFORMULATIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp new file mode 100644 index 00000000000..8f1442f586e --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp @@ -0,0 +1,180 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 PotGradZFormulation.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRADZFORMULATION_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRADZFORMULATION_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "constitutive/fluid/multifluid/Layouts.hpp" +#include "constitutive/capillaryPressure/layouts.hpp" +#include "mesh/ElementRegionManager.hpp" + + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernelUtilities +{ + +template< typename VIEWTYPE > +using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + +using Deriv = constitutive::multifluid::DerivativeOffset; + +struct PotGradZFormulation +{ + template< integer numComp, integer numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + compute ( integer const numPhase, + integer const ip, + integer const hasCapPressure, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + real64 const ( &trans )[numFluxSupportPoints], + real64 const ( &dTrans_dPres )[numFluxSupportPoints], + ElementViewConst< arrayView1d< real64 const > > const & pres, + ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, + ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const & phaseCapPressure, + ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const & dPhaseCapPressure_dPhaseVolFrac, + real64 & potGrad, + real64 ( & dPresGrad_dP )[numFluxSupportPoints], + real64 ( & dPresGrad_dC )[numFluxSupportPoints][numComp], + real64 ( & dGravHead_dP )[numFluxSupportPoints], + real64 ( & dGravHead_dC )[numFluxSupportPoints][numComp] ) + { + // assign derivatives arrays to zero + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + dPresGrad_dP[i] = 0.0; + dGravHead_dP[i] = 0.0; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPresGrad_dC[i][jc] = 0.0; + dGravHead_dC[i][jc] = 0.0; + } + } + + // create local work arrays + real64 densMean = 0.0; + real64 dDensMean_dP[numFluxSupportPoints]{}; + real64 dDensMean_dC[numFluxSupportPoints][numComp]{}; + + real64 presGrad = 0.0; + real64 gravHead = 0.0; + real64 dCapPressure_dC[numComp]{}; + + real64 dProp_dC[numComp]{}; + + // calculate quantities on primary connected cells + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + // density + real64 const density = phaseMassDens[er][esr][ei][0][ip]; + real64 const dDens_dP = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; + + // average density and derivatives + densMean += 0.5 * density; + dDensMean_dP[i] = 0.5 * dDens_dP; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDensMean_dC[i][jc] = 0.5 * dPhaseMassDens[er][esr][ei][0][ip][Deriv::dC+jc]; + } + } + + /// compute the TPFA potential difference + for( integer i = 0; i < numFluxSupportPoints; i++ ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + // capillary pressure + real64 capPressure = 0.0; + real64 dCapPressure_dP = 0.0; + + for( integer ic = 0; ic < numComp; ++ic ) + { + dCapPressure_dC[ic] = 0.0; + } + + if( hasCapPressure ) + { + capPressure = phaseCapPressure[er][esr][ei][0][ip]; + + for( integer jp = 0; jp < numPhase; ++jp ) + { + real64 const dCapPressure_dS = dPhaseCapPressure_dPhaseVolFrac[er][esr][ei][0][ip][jp]; + dCapPressure_dP += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dP]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + dCapPressure_dC[jc] += dCapPressure_dS * dPhaseVolFrac[er][esr][ei][jp][Deriv::dC+jc]; + } + } + } + + presGrad += trans[i] * (pres[er][esr][ei] - capPressure); + dPresGrad_dP[i] += trans[i] * (1 - dCapPressure_dP) + + dTrans_dPres[i] * (pres[er][esr][ei] - capPressure); + for( integer jc = 0; jc < numComp; ++jc ) + { + dPresGrad_dC[i][jc] += -trans[i] * dCapPressure_dC[jc]; + } + + real64 const gravD = trans[i] * gravCoef[er][esr][ei]; + real64 const dGravD_dP = dTrans_dPres[i] * gravCoef[er][esr][ei]; + + // the density used in the potential difference is always a mass density + // unlike the density used in the phase mobility, which is a mass density + // if useMass == 1 and a molar density otherwise + gravHead += densMean * gravD; + + // need to add contributions from both cells the mean density depends on + for( integer j = 0; j < numFluxSupportPoints; ++j ) + { + dGravHead_dP[j] += dDensMean_dP[j] * gravD + dGravD_dP * densMean; + for( integer jc = 0; jc < numComp; ++jc ) + { + dGravHead_dC[j][jc] += dDensMean_dC[j][jc] * gravD; + } + } + } + + // compute phase potential gradient + potGrad = presGrad - gravHead; + + } + +}; + +} // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities + +} // namespace geos + +#endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_POTGRADZFORMULATION_HPP From 98a9300230ea0dc6f78d6e8579a28e34553b13df Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Wed, 13 Nov 2024 11:37:55 -0600 Subject: [PATCH 33/47] rhoT taken from fluid, reorganization of Z formulation and fixes --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 89 ++- .../fluidFlow/CompositionalMultiphaseBase.hpp | 12 + .../fluidFlow/CompositionalMultiphaseFVM.cpp | 53 +- .../AccumulationZFormulationKernel.hpp | 32 +- .../FluxComputeZFormulationKernel.hpp | 607 ++++++++++++++++++ ...balComponentFractionZFormulationKernel.hpp | 144 ----- .../PhaseVolumeFractionZFormulationKernel.hpp | 4 - .../zFormulation/PotGradZFormulation.hpp | 2 - 8 files changed, 754 insertions(+), 189 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp delete mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 364c0bdbd88..2dbc52586ef 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -43,7 +43,6 @@ #include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" #include "physicsSolvers/fluidFlow/SourceFluxStatistics.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalAccumulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp" @@ -55,6 +54,8 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" +//#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" @@ -685,6 +686,28 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFraction( ObjectManagerBase return maxDeltaPhaseVolFrac; } +real64 CompositionalMultiphaseBase::updatePhaseVolumeFractionZFormulation( ObjectManagerBase & dataGroup ) const +{ + GEOS_MARK_FUNCTION; + + string const & fluidName = dataGroup.getReference< string >( viewKeyStruct::fluidNamesString() ); + MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( dataGroup, fluidName ); + + // For now: isothermal only + GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + + real64 maxDeltaPhaseVolFrac = + isothermalCompositionalMultiphaseBaseKernels:: + PhaseVolumeFractionKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid ); + + // ZFormulation + return maxDeltaPhaseVolFrac; +} + void CompositionalMultiphaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const { GEOS_MARK_FUNCTION; @@ -782,6 +805,33 @@ void CompositionalMultiphaseBase::updateCompAmount( ElementSubRegionBase & subRe } ); } +void CompositionalMultiphaseBase::updateCompAmountZFormulation( ElementSubRegionBase & subRegion ) const +{ + GEOS_MARK_FUNCTION; + + string const & solidName = subRegion.template getReference< string >( viewKeyStruct::solidNamesString() ); + CoupledSolidBase const & porousMaterial = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); + arrayView2d< real64 const > const porosity = porousMaterial.getPorosity(); + arrayView1d< real64 const > const volume = subRegion.getElementVolume(); + arrayView2d< real64 const, compflow::USD_COMP > const compFrac = subRegion.getField< fields::flow::globalCompFraction >(); + arrayView2d< real64, compflow::USD_COMP > const compAmount = subRegion.getField< fields::flow::compAmount >(); + // access total density stored in the fluid + string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); + MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); + arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); + + integer const numComp = m_numComponents; + + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + for( integer ic = 0; ic < numComp; ++ic ) + { + // m = phi*V*z_c*rho_T + compAmount[ei][ic] = porosity[ei][0] * volume[ei] * compFrac[ei][ic] * totalDens[ei][0]; + } + } ); +} + void CompositionalMultiphaseBase::updateEnergy( ElementSubRegionBase & subRegion ) const { GEOS_MARK_FUNCTION; @@ -833,16 +883,35 @@ real64 CompositionalMultiphaseBase::updateFluidState( ElementSubRegionBase & sub { GEOS_MARK_FUNCTION; - updateGlobalComponentFraction( subRegion ); - updateFluidModel( subRegion ); - updateCompAmount( subRegion ); - real64 const maxDeltaPhaseVolFrac = updatePhaseVolumeFraction( subRegion ); - updateRelPermModel( subRegion ); - updatePhaseMobility( subRegion ); - updateCapPressureModel( subRegion ); + real64 maxdS; - // note1: for now, thermal conductivity is treated explicitly, so no update here - // note2: for now, diffusion and dispersion are also treated explicitly + if (m_useZFormulation) + { + // For p, z_c as the primary unknowns + updateFluidModel( subRegion ); // rho_T is now a function of p, z_c from volume balance + updateCompAmountZFormulation( subRegion ); + maxdS = updatePhaseVolumeFractionZFormulation( subRegion ); + updateRelPermModel( subRegion ); + updatePhaseMobility( subRegion ); + updateCapPressureModel( subRegion ); + } + else + { + // For p, rho_c as the primary unknowns + updateGlobalComponentFraction( subRegion ); + updateFluidModel( subRegion ); + updateCompAmount( subRegion ); + maxdS = updatePhaseVolumeFraction( subRegion ); + updateRelPermModel( subRegion ); + updatePhaseMobility( subRegion ); + updateCapPressureModel( subRegion ); + // note1: for now, thermal conductivity is treated explicitly, so no update here + // note2: for now, diffusion and dispersion are also treated explicitly + } + + + real64 const maxDeltaPhaseVolFrac = maxdS; + return maxDeltaPhaseVolFrac; } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index d7c93d5ec78..24ea1860ac9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -116,6 +116,12 @@ class CompositionalMultiphaseBase : public FlowSolverBase */ real64 updatePhaseVolumeFraction( ObjectManagerBase & dataGroup ) const; + /** + * @brief Recompute phase volume fractions (saturations) from constitutive and primary variables (pressure and global component fractions) + * @param dataGroup the group storing the required fields + */ + real64 updatePhaseVolumeFractionZFormulation( ObjectManagerBase & dataGroup ) const; + /** * @brief Update all relevant fluid models using current values of pressure and composition * @param dataGroup the group storing the required fields @@ -140,6 +146,12 @@ class CompositionalMultiphaseBase : public FlowSolverBase */ void updateCompAmount( ElementSubRegionBase & subRegion ) const; + /** + * @brief Update components mass/moles if Z formulation is used + * @param subRegion the subregion storing the required fields + */ + void updateCompAmountZFormulation( ElementSubRegionBase & subRegion ) const; + /** * @brief Update energy * @param subRegion the subregion storing the required fields diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 6f0c0ff913f..bb7cb74f262 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -55,6 +55,8 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp" namespace geos { @@ -934,25 +936,46 @@ void CompositionalMultiphaseFVM::updatePhaseMobility( ObjectManagerBase & dataGr string const & relpermName = dataGroup.getReference< string >( viewKeyStruct::relPermNamesString() ); RelativePermeabilityBase const & relperm = getConstitutiveModel< RelativePermeabilityBase >( dataGroup, relpermName ); - if( m_isThermal ) + if (m_useZFormulation) { - thermalCompositionalMultiphaseFVMKernels:: - PhaseMobilityKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dataGroup, - fluid, - relperm ); + if( m_isThermal ) + { + // For now: isothermal only + GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + } + else + { + isothermalCompositionalMultiphaseFVMKernels:: + PhaseMobilityZFormulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid, + relperm ); + } } else { - isothermalCompositionalMultiphaseFVMKernels:: - PhaseMobilityKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dataGroup, - fluid, - relperm ); + if( m_isThermal ) + { + thermalCompositionalMultiphaseFVMKernels:: + PhaseMobilityKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid, + relperm ); + } + else + { + isothermalCompositionalMultiphaseFVMKernels:: + PhaseMobilityKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid, + relperm ); + } } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp index 146335626c4..7fd2672dda9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp @@ -91,10 +91,10 @@ class AccumulationZFormulationKernel m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), m_phaseDens( fluid.phaseDensity() ), m_dPhaseDens( fluid.dPhaseDensity() ), - m_phaseCompFrac( fluid.phaseCompFraction() ), - m_dPhaseCompFrac( fluid.dPhaseCompFraction() ), m_phaseFrac( fluid.phaseFraction() ), m_dPhaseFrac( fluid.dPhaseFraction() ), + m_totalDens( fluid.totalDensity() ), + m_dTotalDens( fluid.dTotalDensity() ), m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ), m_compAmount_n( subRegion.getField< fields::flow::compAmount_n >() ), @@ -176,8 +176,7 @@ class AccumulationZFormulationKernel template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void computeAccumulation( localIndex const ei, - StackVariables & stack, - FUNC && phaseAmountKernelOp = NoOpFunc{} ) const + StackVariables & stack) const { using Deriv = constitutive::multifluid::DerivativeOffset; @@ -187,6 +186,11 @@ class AccumulationZFormulationKernel arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; + //arraySlice1d< real64 const, constitutive::multifluid::USD_FLUID - 1 > const totalDens = m_totalDens[ei]; + //arraySlice2d< real64 const, constitutive::multifluid::USD_FLUID_DC - 1 > const dTotalDens = m_dTotalDens[ei]; + + // debugging + // calculate total component density from volume balance // TO DO: create separate kernel @@ -292,10 +296,8 @@ class AccumulationZFormulationKernel template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE void computeVolumeBalance( localIndex const ei, - StackVariables & stack, - FUNC && phaseVolFractionSumKernelOp = NoOpFunc{} ) const + StackVariables & stack) const { - using Deriv = constitutive::multifluid::DerivativeOffset; arraySlice1d< real64 const, compflow::USD_PHASE - 1 > compFrac = m_compFrac[ei]; @@ -311,6 +313,8 @@ class AccumulationZFormulationKernel stack.localJacobian[numComp][ic+1] -= 1; } + //phaseVolFractionSumKernelOp( oneMinusCompFracSum ); + // scale componentFraction-based volume balance by pore volume (for better scaling w.r.t. other equations) stack.localResidual[numComp] = stack.poreVolume * oneMinusCompFracSum; for( integer idof = 0; idof < numDof; ++idof ) @@ -412,17 +416,17 @@ class AccumulationZFormulationKernel arrayView2d< real64 const, compflow::USD_PHASE > const m_phaseVolFrac; arrayView3d< real64 const, compflow::USD_PHASE_DC > const m_dPhaseVolFrac; - /// Views on phase fractions - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseFrac; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseFrac; - /// Views on the phase densities arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseDens; arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseDens; - /// Views on the phase component fraction - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > const m_phaseCompFrac; - arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > const m_dPhaseCompFrac; + /// Views on phase fractions + arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseFrac; + arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseFrac; + + /// Views on the total density + arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const m_totalDens; + arrayView3d< real64 const, constitutive::multifluid::USD_FLUID_DC > const m_dTotalDens; // View on component densities and component fractions arrayView2d< real64 const, compflow::USD_COMP > m_compDens; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp new file mode 100644 index 00000000000..c6b3576eff8 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp @@ -0,0 +1,607 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 FluxComputeKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp" + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/fluid/multifluid/MultiFluidFields.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/KernelLaunchSelectors.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/** + * @class FluxComputeKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @brief Define the interface for the assembly kernel in charge of flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > +class FluxComputeKernel : public FluxComputeKernelBase +{ +public: + + /// Compile time value for the number of components + static constexpr integer numComp = NUM_COMP; + + /// Compute time value for the number of degrees of freedom + static constexpr integer numDof = NUM_DOF; + + /// Compute time value for the number of equations (all of them, except the volume balance equation) + static constexpr integer numEqn = NUM_DOF-1; + + /// Maximum number of elements at the face + static constexpr localIndex maxNumElems = STENCILWRAPPER::maxNumPointsInFlux; + + /// Maximum number of connections at the face + static constexpr localIndex maxNumConns = STENCILWRAPPER::maxNumConnections; + + /// Maximum number of points in the stencil + static constexpr localIndex maxStencilSize = STENCILWRAPPER::maxStencilSize; + + /// Number of flux support points (hard-coded for TFPA) + static constexpr integer numFluxSupportPoints = 2; + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dofNumberAccessor + * @param[in] compFlowAccessors + * @param[in] multiFluidAccessors + * @param[in] capPressureAccessors + * @param[in] permeabilityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed together + */ + FluxComputeKernel( integer const numPhases, + globalIndex const rankOffset, + STENCILWRAPPER const & stencilWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< FluxComputeKernelFlags > kernelFlags ) + : FluxComputeKernelBase( numPhases, + rankOffset, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), + m_permeability( permeabilityAccessors.get( fields::permeability::permeability {} ) ), + m_dPerm_dPres( permeabilityAccessors.get( fields::permeability::dPerm_dPressure {} ) ), + m_phaseMob( compFlowAccessors.get( fields::flow::phaseMobility {} ) ), + m_dPhaseMob( compFlowAccessors.get( fields::flow::dPhaseMobility {} ) ), + m_phaseMassDens( multiFluidAccessors.get( fields::multifluid::phaseMassDensity {} ) ), + m_dPhaseMassDens( multiFluidAccessors.get( fields::multifluid::dPhaseMassDensity {} ) ), + m_phaseCapPressure( capPressureAccessors.get( fields::cappres::phaseCapPressure {} ) ), + m_dPhaseCapPressure_dPhaseVolFrac( capPressureAccessors.get( fields::cappres::dPhaseCapPressure_dPhaseVolFraction {} ) ), + m_stencilWrapper( stencilWrapper ), + m_seri( stencilWrapper.getElementRegionIndices() ), + m_sesri( stencilWrapper.getElementSubRegionIndices() ), + m_sei( stencilWrapper.getElementIndices() ) + { } + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const size, localIndex numElems ) + : stencilSize( size ), + numConnectedElems( numElems ), + dofColIndices( size * numDof ), + localFlux( numElems * numEqn ), + localFluxJacobian( numElems * numEqn, size * numDof ) + {} + + // Stencil information + + /// Stencil size for a given connection + localIndex const stencilSize; + /// Number of elements connected at a given connection + localIndex const numConnectedElems; + + // Transmissibility and derivatives + + /// Transmissibility + real64 transmissibility[maxNumConns][numFluxSupportPoints]{}; + /// Derivatives of transmissibility with respect to pressure + real64 dTrans_dPres[maxNumConns][numFluxSupportPoints]{}; + + // Local degrees of freedom and local residual/jacobian + + /// Indices of the matrix rows/columns corresponding to the dofs in this face + stackArray1d< globalIndex, maxNumElems * numDof > dofColIndices; + + /// Storage for the face local residual vector (all equations except volume balance) + stackArray1d< real64, maxNumElems * numEqn > localFlux; + /// Storage for the face local Jacobian matrix + stackArray2d< real64, maxNumElems * numEqn * maxStencilSize * numDof > localFluxJacobian; + }; + + + /** + * @brief Getter for the stencil size at this connection + * @param[in] iconn the connection index + * @return the size of the stencil at this connection + */ + GEOS_HOST_DEVICE + inline + localIndex stencilSize( localIndex const iconn ) const { return m_sei[iconn].size(); } + + /** + * @brief Getter for the number of elements at this connection + * @param[in] iconn the connection index + * @return the number of elements at this connection + */ + GEOS_HOST_DEVICE + inline + localIndex numPointsInFlux( localIndex const iconn ) const { return m_stencilWrapper.numPointsInFlux( iconn ); } + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] iconn the connection index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + inline + void setup( localIndex const iconn, + StackVariables & stack ) const + { + // set degrees of freedom indices for this face + for( integer i = 0; i < stack.stencilSize; ++i ) + { + globalIndex const offset = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + + for( integer jdof = 0; jdof < numDof; ++jdof ) + { + stack.dofColIndices[i * numDof + jdof] = offset + jdof; + } + } + } + + /** + * @brief Compute the local flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + inline + void computeFlux( localIndex const iconn, + StackVariables & stack, + FUNC && compFluxKernelOp = NoOpFunc{} ) const + { + + // first, compute the transmissibilities at this face + m_stencilWrapper.computeWeights( iconn, + m_permeability, + m_dPerm_dPres, + stack.transmissibility, + stack.dTrans_dPres ); + + + localIndex k[numFluxSupportPoints]; + localIndex connectionIndex = 0; + for( k[0] = 0; k[0] < stack.numConnectedElems; ++k[0] ) + { + for( k[1] = k[0] + 1; k[1] < stack.numConnectedElems; ++k[1] ) + { + /// cell indices + localIndex const seri[numFluxSupportPoints] = {m_seri( iconn, k[0] ), m_seri( iconn, k[1] )}; + localIndex const sesri[numFluxSupportPoints] = {m_sesri( iconn, k[0] ), m_sesri( iconn, k[1] )}; + localIndex const sei[numFluxSupportPoints] = {m_sei( iconn, k[0] ), m_sei( iconn, k[1] )}; + + // clear working arrays + real64 compFlux[numComp]{}; + real64 dCompFlux_dP[numFluxSupportPoints][numComp]{}; + real64 dCompFlux_dC[numFluxSupportPoints][numComp][numComp]{}; + + real64 const trans[numFluxSupportPoints] = { stack.transmissibility[connectionIndex][0], + stack.transmissibility[connectionIndex][1] }; + + real64 const dTrans_dPres[numFluxSupportPoints] = { stack.dTrans_dPres[connectionIndex][0], + stack.dTrans_dPres[connectionIndex][1] }; + + //***** calculation of flux ***** + // loop over phases, compute and upwind phase flux and sum contributions to each component's flux + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + // create local work arrays + real64 potGrad = 0.0; + real64 phaseFlux = 0.0; + real64 dPhaseFlux_dP[numFluxSupportPoints]{}; + real64 dPhaseFlux_dC[numFluxSupportPoints][numComp]{}; + + localIndex k_up = -1; + + if( m_kernelFlags.isSet( FluxComputeKernelFlags::C1PPU ) ) + { + isothermalCompositionalMultiphaseFVMKernelUtilities::C1PPUPhaseFlux::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_dCompFrac_dCompDens, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + else if( m_kernelFlags.isSet( FluxComputeKernelFlags::IHU ) ) + { + isothermalCompositionalMultiphaseFVMKernelUtilities::IHUPhaseFlux::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_dCompFrac_dCompDens, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + else + { + if( m_kernelFlags.isSet( FluxComputeKernelFlags::useZFormulation ) ) + { + isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFluxZFormulation::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + else + { + isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFlux::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_dCompFrac_dCompDens, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); + } + + } + + // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives + // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase + compFluxKernelOp( ip, k, seri, sesri, sei, connectionIndex, + k_up, seri[k_up], sesri[k_up], sei[k_up], potGrad, + phaseFlux, dPhaseFlux_dP, dPhaseFlux_dC ); + + } // loop over phases + + /// populate local flux vector and derivatives + for( integer ic = 0; ic < numComp; ++ic ) + { + integer const eqIndex0 = k[0] * numEqn + ic; + integer const eqIndex1 = k[1] * numEqn + ic; + + stack.localFlux[eqIndex0] += m_dt * compFlux[ic]; + stack.localFlux[eqIndex1] -= m_dt * compFlux[ic]; + + for( integer ke = 0; ke < numFluxSupportPoints; ++ke ) + { + localIndex const localDofIndexPres = k[ke] * numDof; + stack.localFluxJacobian[eqIndex0][localDofIndexPres] += m_dt * dCompFlux_dP[ke][ic]; + stack.localFluxJacobian[eqIndex1][localDofIndexPres] -= m_dt * dCompFlux_dP[ke][ic]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + localIndex const localDofIndexComp = localDofIndexPres + jc + 1; + stack.localFluxJacobian[eqIndex0][localDofIndexComp] += m_dt * dCompFlux_dC[ke][ic][jc]; + stack.localFluxJacobian[eqIndex1][localDofIndexComp] -= m_dt * dCompFlux_dC[ke][ic][jc]; + } + } + } + connectionIndex++; + } // loop over k[1] + } // loop over k[0] + + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + inline + void complete( localIndex const iconn, + StackVariables & stack, + FUNC && assemblyKernelOp = NoOpFunc{} ) const + { + using namespace compositionalMultiphaseUtilities; + + if( m_kernelFlags.isSet( FluxComputeKernelFlags::TotalMassEquation ) ) + { + // Apply equation/variable change transformation(s) + stackArray1d< real64, maxStencilSize * numDof > work( stack.stencilSize * numDof ); + shiftBlockRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numEqn, numDof * stack.stencilSize, stack.numConnectedElems, + stack.localFluxJacobian, work ); + shiftBlockElementsAheadByOneAndReplaceFirstElementWithSum( numComp, numEqn, stack.numConnectedElems, + stack.localFlux ); + } + + // add contribution to residual and jacobian into: + // - the component mass balance equations (i = 0 to i = numComp-1) + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + for( integer i = 0; i < stack.numConnectedElems; ++i ) + { + if( m_ghostRank[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )] < 0 ) + { + globalIndex const globalRow = m_dofNumber[m_seri( iconn, i )][m_sesri( iconn, i )][m_sei( iconn, i )]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( m_localMatrix.numRows(), localRow + numComp ); + + for( integer ic = 0; ic < numComp; ++ic ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &m_localRhs[localRow + ic], + stack.localFlux[i * numEqn + ic] ); + m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + ic, + stack.dofColIndices.data(), + stack.localFluxJacobian[i * numEqn + ic].dataIfContiguous(), + stack.stencilSize * numDof ); + } + + // call the lambda to assemble additional terms, such as thermal terms + assemblyKernelOp( i, localRow ); + } + } + } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numConnections the number of connections + * @param[inout] kernelComponent the kernel component providing access to setup/compute/complete functions and stack variables + */ + template< typename POLICY, typename KERNEL_TYPE > + static void + launch( localIndex const numConnections, + KERNEL_TYPE const & kernelComponent ) + { + GEOS_MARK_FUNCTION; + forAll< POLICY >( numConnections, [=] GEOS_HOST_DEVICE ( localIndex const iconn ) + { + typename KERNEL_TYPE::StackVariables stack( kernelComponent.stencilSize( iconn ), + kernelComponent.numPointsInFlux( iconn ) ); + + kernelComponent.setup( iconn, stack ); + kernelComponent.computeFlux( iconn, stack ); + kernelComponent.complete( iconn, stack ); + } ); + } + +protected: + + /// Views on permeability + ElementViewConst< arrayView3d< real64 const > > const m_permeability; + ElementViewConst< arrayView3d< real64 const > > const m_dPerm_dPres; + + /// Views on phase mobilities + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const m_phaseMob; + ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const m_dPhaseMob; + + /// Views on phase mass densities + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const m_phaseMassDens; + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const m_dPhaseMassDens; + + /// Views on phase capillary pressure + ElementViewConst< arrayView3d< real64 const, constitutive::cappres::USD_CAPPRES > > const m_phaseCapPressure; + ElementViewConst< arrayView4d< real64 const, constitutive::cappres::USD_CAPPRES_DS > > const m_dPhaseCapPressure_dPhaseVolFrac; + + // Stencil information + + /// Reference to the stencil wrapper + STENCILWRAPPER const m_stencilWrapper; + + /// Connection to element maps + typename STENCILWRAPPER::IndexContainerViewConstType const m_seri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sesri; + typename STENCILWRAPPER::IndexContainerViewConstType const m_sei; + +}; + +/** + * @class FluxComputeKernelFactory + */ +class FluxComputeKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @tparam STENCILWRAPPER the type of the stencil wrapper + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] hasCapPressure flag specifying whether capillary pressure is used or not + * @param[in] solverName name of the solver (to name accessors) + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY, typename STENCILWRAPPER > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + string const & dofKey, + integer const hasCapPressure, + integer const useTotalMassEquation, + integer const useZFormulation, + UpwindingParameters upwindingParams, + string const & solverName, + ElementRegionManager const & elemManager, + STENCILWRAPPER const & stencilWrapper, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + isothermalCompositionalMultiphaseBaseKernels::internal::kernelLaunchSelectorCompSwitch( numComps, [&]( auto NC ) + { + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 1; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + BitFlags< FluxComputeKernelFlags > kernelFlags; + if( hasCapPressure ) + kernelFlags.set( FluxComputeKernelFlags::CapPressure ); + if( useTotalMassEquation ) + kernelFlags.set( FluxComputeKernelFlags::TotalMassEquation ); + if( upwindingParams.upwindingScheme == UpwindingScheme::C1PPU && + isothermalCompositionalMultiphaseFVMKernelUtilities::epsC1PPU > 0 ) + kernelFlags.set( FluxComputeKernelFlags::C1PPU ); + else if( upwindingParams.upwindingScheme == UpwindingScheme::IHU ) + kernelFlags.set( FluxComputeKernelFlags::IHU ); + if( useZFormulation ) + kernelFlags.set( FluxComputeKernelFlags::useZFormulation ); + + using kernelType = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename kernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); + typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + + kernelType kernel( numPhases, rankOffset, stencilWrapper, dofNumberAccessor, + compFlowAccessors, multiFluidAccessors, capPressureAccessors, permeabilityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp deleted file mode 100644 index e8d53a625ba..00000000000 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/GlobalComponentFractionZFormulationKernel.hpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2024 Total, S.A - * 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 GlobalComponentFractionKernel.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP - -#include "physicsSolvers/fluidFlow/kernels/compositional/PropertyKernelBase.hpp" - -namespace geos -{ - -namespace isothermalCompositionalMultiphaseBaseKernels -{ - -/******************************** GlobalComponentFractionKernel ********************************/ - -/** - * @class GlobalComponentFractionKernel - * @tparam NUM_COMP number of fluid components - * @brief Define the interface for the update kernel in charge of computing the phase volume fractions - */ -template< integer NUM_COMP > -class GlobalComponentFractionKernel : public PropertyKernelBase< NUM_COMP > -{ -public: - - using Base = PropertyKernelBase< NUM_COMP >; - using Base::numComp; - - /** - * @brief Constructor - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - */ - GlobalComponentFractionKernel( ObjectManagerBase & subRegion ) - : Base(), - m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), - m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ), - m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ) - {} - - /** - * @brief Compute the phase volume fractions in an element - * @tparam FUNC the type of the function that can be used to customize the kernel - * @param[in] ei the element index - * @param[in] phaseVolFractionKernelOp the function used to customize the kernel - */ - template< typename FUNC = NoOpFunc > - GEOS_HOST_DEVICE - void compute( localIndex const ei, - FUNC && compFractionKernelOp = NoOpFunc{} ) const - { - arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; - arraySlice1d< real64, compflow::USD_COMP - 1 > const compFrac = m_compFrac[ei]; - arraySlice2d< real64, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; - - real64 totalDensity = 0.0; - - for( integer ic = 0; ic < numComp; ++ic ) - { - totalDensity += compDens[ic]; - } - - real64 const totalDensityInv = 1.0 / totalDensity; - - for( integer ic = 0; ic < numComp; ++ic ) - { - compFrac[ic] = compDens[ic] * totalDensityInv; - for( integer jc = 0; jc < numComp; ++jc ) - { - dCompFrac_dCompDens[ic][jc] = -compFrac[ic] * totalDensityInv; - } - dCompFrac_dCompDens[ic][ic] += totalDensityInv; - } - - compFractionKernelOp( compFrac, dCompFrac_dCompDens ); - } - -protected: - - // inputs - - // Views on component densities - arrayView2d< real64 const, compflow::USD_COMP > m_compDens; - - // outputs - - // Views on component fraction - arrayView2d< real64, compflow::USD_COMP > m_compFrac; - arrayView3d< real64, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; - -}; - -/** - * @class GlobalComponentFractionKernelFactory - */ -class GlobalComponentFractionKernelFactory -{ -public: - - /** - * @brief Create a new kernel and launch - * @tparam POLICY the policy used in the RAJA kernel - * @param[in] numComp the number of fluid components - * @param[in] subRegion the element subregion - * @param[in] fluid the fluid model - */ - template< typename POLICY > - static void - createAndLaunch( integer const numComp, - ObjectManagerBase & subRegion ) - { - internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC ) - { - integer constexpr NUM_COMP = NC(); - GlobalComponentFractionKernel< NUM_COMP > kernel( subRegion ); - GlobalComponentFractionKernel< NUM_COMP >::template launch< POLICY >( subRegion.size(), kernel ); - } ); - } - -}; - -} // namespace isothermalCompositionalMultiphaseBaseKernels - -} // namespace geos - - -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp index 92457153cbb..fcd9f4d04bc 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp @@ -58,7 +58,6 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), - m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), m_phaseFrac( fluid.phaseFraction() ), m_dPhaseFrac( fluid.dPhaseFraction() ), m_phaseDens( fluid.phaseDensity() ), @@ -79,7 +78,6 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM using Deriv = constitutive::multifluid::DerivativeOffset; arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; @@ -87,8 +85,6 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; - real64 work[numComp]{}; - // compute total density from component partial densities real64 totalDensity = 0.0; real64 const dTotalDens_dCompDens = 1.0; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp index 8f1442f586e..a4a55513156 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp @@ -85,8 +85,6 @@ struct PotGradZFormulation real64 gravHead = 0.0; real64 dCapPressure_dC[numComp]{}; - real64 dProp_dC[numComp]{}; - // calculate quantities on primary connected cells for( integer i = 0; i < numFluxSupportPoints; ++i ) { From f8a1f167f959667d7ddcc591aa85990309119648 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Wed, 13 Nov 2024 15:47:02 -0600 Subject: [PATCH 34/47] Correct accumulation and saturation calculations for z formulation --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 5 +- .../AccumulationZFormulationKernel.hpp | 99 +------------------ .../PhaseVolumeFractionZFormulationKernel.hpp | 61 ++++-------- 3 files changed, 28 insertions(+), 137 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 2dbc52586ef..01f1d269b90 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -55,7 +55,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/CFLKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" -//#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp" #if defined( __INTEL_COMPILER ) #pragma GCC optimize "O0" @@ -698,13 +698,12 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFractionZFormulation( Objec real64 maxDeltaPhaseVolFrac = isothermalCompositionalMultiphaseBaseKernels:: - PhaseVolumeFractionKernelFactory:: + PhaseVolumeFractionZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dataGroup, fluid ); - // ZFormulation return maxDeltaPhaseVolFrac; } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp index 7fd2672dda9..590a301b2f3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp @@ -89,13 +89,8 @@ class AccumulationZFormulationKernel m_dPoro_dPres( solid.getDporosity_dPressure() ), m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), - m_phaseDens( fluid.phaseDensity() ), - m_dPhaseDens( fluid.dPhaseDensity() ), - m_phaseFrac( fluid.phaseFraction() ), - m_dPhaseFrac( fluid.dPhaseFraction() ), m_totalDens( fluid.totalDensity() ), m_dTotalDens( fluid.dTotalDensity() ), - m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ), m_compAmount_n( subRegion.getField< fields::flow::compAmount_n >() ), m_localMatrix( localMatrix ), @@ -180,74 +175,10 @@ class AccumulationZFormulationKernel { using Deriv = constitutive::multifluid::DerivativeOffset; - arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compFrac = m_compFrac[ei]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; - //arraySlice1d< real64 const, constitutive::multifluid::USD_FLUID - 1 > const totalDens = m_totalDens[ei]; - //arraySlice2d< real64 const, constitutive::multifluid::USD_FLUID_DC - 1 > const dTotalDens = m_dTotalDens[ei]; + real64 const totalDensity = m_totalDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_FLUID_DC - 2 > const dTotalDens = m_dTotalDens[ei][0]; - // debugging - - - // calculate total component density from volume balance - // TO DO: create separate kernel - real64 totalDensity = 0.0; - real64 dtotalDensity_dP = 0.0; - real64 dtotalDensity_dC[numComp]{}; - - for( integer ic = 0; ic < numComp; ++ic ) - { - totalDensity += compDens[ic]; - dtotalDensity_dC[ic] = 0.0; - } - - //real64 const sum_phaseFrac_phaseDens = 0.0; - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - real64 const phaseDensInv = 1.0 / phaseDens[ip]; - //sum_phaseFrac_phaseDens += phaseFrac[ip] * phaseDensInv; - - dtotalDensity_dP += phaseDensInv * totalDensity * totalDensity * - (phaseFrac[ip] * phaseDensInv * dPhaseDens[ip][Deriv::dP] - dPhaseFrac[ip][Deriv::dP]); - - for( integer jc = 0; jc < numComp; ++jc ) - { - dtotalDensity_dC[jc] += phaseDensInv * totalDensity * totalDensity * - (phaseFrac[ip] * phaseDensInv * dPhaseDens[ip][Deriv::dC+jc] - dPhaseFrac[ip][Deriv::dC+jc]); - } - } - - std::cout << "Cell [" << ei << "]" << std::endl; - for( integer ic = 0; ic < numComp; ++ic ) - std::cout << "rho[" << ic << "] = " << compDens[ic] << std::endl; - for( integer ic = 0; ic < numComp; ++ic ) - std::cout << "z[" << ic << "] = " << compFrac[ic] << std::endl; - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - std::cout << "nu[" << ip << "] = " << phaseFrac[ip] << std::endl; - std::cout << "dnu[" << ip << "]_dP = " << dPhaseFrac[ip][Deriv::dP] << std::endl; - for( integer ic = 0; ic < numComp; ++ic ) - std::cout << "dnu[" << ip << "]_dz[" << ic << "] = " << dPhaseFrac[ip][Deriv::dC+ic] << std::endl; - } - - for( integer ip = 0; ip < m_numPhases; ++ip ) - { - std::cout << "phaseDens[" << ip << "] = " << phaseDens[ip] << std::endl; - std::cout << "dphaseDens[" << ip << "]_dP = " << dPhaseDens[ip][Deriv::dP] << std::endl; - for( integer ic = 0; ic < numComp; ++ic ) - std::cout << "dphaseDens[" << ip << "]_dz[" << ic << "] = " << dPhaseDens[ip][Deriv::dC+ic] << std::endl; - } - - - - std::cout << "rhoT = " << totalDensity << std::endl; - std::cout << "drhoT_dP = " << dtotalDensity_dP << std::endl; - for( integer ic = 0; ic < numComp; ++ic ) - std::cout << "drhoT_dC[" << ic << "] = " << dtotalDensity_dC[ic] << std::endl; - // ic - index of component whose conservation equation is assembled // (i.e. row number in local matrix) for( integer ic = 0; ic < numComp; ++ic ) @@ -258,7 +189,7 @@ class AccumulationZFormulationKernel stack.localResidual[ic] += compAmount - compAmount_n; // derivatives with respect to pressure (p) - real64 const dCompAmount_dP = compFrac[ic] * (stack.dPoreVolume_dPres * totalDensity + stack.poreVolume * dtotalDensity_dP); + real64 const dCompAmount_dP = compFrac[ic] * (stack.dPoreVolume_dPres * totalDensity + stack.poreVolume * dTotalDens[Deriv::dP]); stack.localJacobian[ic][0] += dCompAmount_dP; // derivatives with respect to global component fraction (zc) @@ -266,24 +197,13 @@ class AccumulationZFormulationKernel { real64 dCompAmount_dC; if (ic == jc) - dCompAmount_dC = stack.poreVolume * (totalDensity + dtotalDensity_dC[jc] * compFrac[ic]); + dCompAmount_dC = stack.poreVolume * (totalDensity + dTotalDens[Deriv::dC+jc] * compFrac[ic]); else - dCompAmount_dC = stack.poreVolume * (dtotalDensity_dC[jc] * compFrac[ic]); + dCompAmount_dC = stack.poreVolume * (dTotalDens[Deriv::dC+jc] * compFrac[ic]); stack.localJacobian[ic][jc + 1] += dCompAmount_dC; } } - - for( integer ic = 0; ic < numComp; ++ic ) - { - std::cout << "Raccum[" << ic << "] = " << stack.localResidual[ic] << std::endl; - std::cout << "dRaccum[" << ic << "]_dP = " << stack.localJacobian[ic][0] << std::endl; - for( integer jc = 0; jc < numComp; ++jc ) - { - std::cout << "dRaccum[" << ic << "]_dz[" << jc << "] = " << stack.localJacobian[ic][jc+1] << std::endl; - } - - } } /** @@ -416,20 +336,11 @@ class AccumulationZFormulationKernel arrayView2d< real64 const, compflow::USD_PHASE > const m_phaseVolFrac; arrayView3d< real64 const, compflow::USD_PHASE_DC > const m_dPhaseVolFrac; - /// Views on the phase densities - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseDens; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseDens; - - /// Views on phase fractions - arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const m_phaseFrac; - arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > const m_dPhaseFrac; - /// Views on the total density arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const m_totalDens; arrayView3d< real64 const, constitutive::multifluid::USD_FLUID_DC > const m_dTotalDens; // View on component densities and component fractions - arrayView2d< real64 const, compflow::USD_COMP > m_compDens; arrayView2d< real64 const, compflow::USD_COMP > m_compFrac; // View on component amount (mass/moles) from previous time step diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp index fcd9f4d04bc..c68d4766e40 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp @@ -57,11 +57,12 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM : Base(), m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), - m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ), m_phaseFrac( fluid.phaseFraction() ), m_dPhaseFrac( fluid.dPhaseFraction() ), m_phaseDens( fluid.phaseDensity() ), - m_dPhaseDens( fluid.dPhaseDensity() ) + m_dPhaseDens( fluid.dPhaseDensity() ), + m_totalDens( fluid.totalDensity() ), + m_dTotalDens( fluid.dTotalDensity() ) {} /** @@ -72,27 +73,19 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM */ template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE - real64 compute( localIndex const ei, - FUNC && phaseVolFractionKernelOp = NoOpFunc{} ) const + real64 compute( localIndex const ei) const { using Deriv = constitutive::multifluid::DerivativeOffset; - arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei]; - arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; - arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseFrac = m_phaseFrac[ei][0]; arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseFrac = m_dPhaseFrac[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; + real64 const totalDensity = m_totalDens[ei][0]; + arraySlice1d< real64 const, constitutive::multifluid::USD_FLUID_DC - 2 > const dTotalDens = m_dTotalDens[ei][0]; arraySlice1d< real64, compflow::USD_PHASE - 1 > const phaseVolFrac = m_phaseVolFrac[ei]; arraySlice2d< real64, compflow::USD_PHASE_DC - 1 > const dPhaseVolFrac = m_dPhaseVolFrac[ei]; - // compute total density from component partial densities - real64 totalDensity = 0.0; - real64 const dTotalDens_dCompDens = 1.0; - for( integer ic = 0; ic < numComp; ++ic ) - { - totalDensity += compDens[ic]; - } - real64 maxDeltaPhaseVolFrac = 0.0; for( integer ip = 0; ip < numPhase; ++ip ) @@ -110,39 +103,27 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM continue; } - // Expression for volume fractions: S_p = (nu_p / rho_p) * rho_t - real64 const phaseDensInv = 1.0 / phaseDens[ip]; - // store old saturation to compute change later real64 const satOld = phaseVolFrac[ip]; - // compute saturation and derivatives except multiplying by the total density - phaseVolFrac[ip] = phaseFrac[ip] * phaseDensInv; - - dPhaseVolFrac[ip][Deriv::dP] = - (dPhaseFrac[ip][Deriv::dP] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dP]) * phaseDensInv; + // compute saturation and derivatives S_p = rho_t * (nu_p / rho_p) + phaseVolFrac[ip] = totalDensity * phaseFrac[ip] / phaseDens[ip]; + dPhaseVolFrac[ip][Deriv::dP] = phaseVolFrac[ip] * + (dTotalDens[Deriv::dP] / totalDensity + dPhaseFrac[ip][Deriv::dP] / phaseFrac[ip] - dPhaseDens[ip][Deriv::dP] / phaseDens[ip]); + for( integer jc = 0; jc < numComp; ++jc ) { - dPhaseVolFrac[ip][Deriv::dC+jc] = - (dPhaseFrac[ip][Deriv::dC+jc] - phaseVolFrac[ip] * dPhaseDens[ip][Deriv::dC+jc]) * phaseDensInv; + dPhaseVolFrac[ip][Deriv::dC+jc] = phaseVolFrac[ip] * + (dTotalDens[Deriv::dC+jc] / totalDensity + dPhaseFrac[ip][Deriv::dC+jc] / phaseFrac[ip] - dPhaseDens[ip][Deriv::dC+jc] / phaseDens[ip]); } // call the lambda in the phase loop to allow the reuse of the phaseVolFrac and totalDensity // possible use: assemble the derivatives wrt temperature - phaseVolFractionKernelOp( ip, phaseVolFrac[ip], phaseDensInv, totalDensity ); - - // now finalize the computation by multiplying by total density - for( integer jc = 0; jc < numComp; ++jc ) - { - dPhaseVolFrac[ip][Deriv::dC+jc] *= totalDensity; - dPhaseVolFrac[ip][Deriv::dC+jc] += phaseVolFrac[ip] * dTotalDens_dCompDens; - } - - phaseVolFrac[ip] *= totalDensity; - dPhaseVolFrac[ip][Deriv::dP] *= totalDensity; + //phaseVolFractionKernelOp( ip, phaseVolFrac[ip], phaseDensInv, totalDensity ); real64 const deltaPhaseVolFrac = LvArray::math::abs( phaseVolFrac[ip] - satOld ); + if( maxDeltaPhaseVolFrac < deltaPhaseVolFrac ) { maxDeltaPhaseVolFrac = deltaPhaseVolFrac; @@ -182,10 +163,6 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM // inputs - /// Views on component densities - arrayView2d< real64 const, compflow::USD_COMP > m_compDens; - arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; - /// Views on phase fractions arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseFrac; arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseFrac; @@ -194,6 +171,10 @@ class PhaseVolumeFractionZFormulationKernel : public PropertyKernelBase< NUM_COM arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > m_dPhaseDens; + /// Views on the total density + arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const m_totalDens; + arrayView3d< real64 const, constitutive::multifluid::USD_FLUID_DC > const m_dTotalDens; + }; /** From 0dd987b4e35f218bbe77a17dfb13d33ad7e45f39 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Wed, 13 Nov 2024 16:37:13 -0600 Subject: [PATCH 35/47] Reorganized flux compute kernel for z formulation --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 49 +++--- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 109 +----------- .../compositional/FluxComputeKernel.hpp | 37 +--- .../FluxComputeZFormulationKernel.hpp | 161 +++++------------- 4 files changed, 74 insertions(+), 282 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 01f1d269b90..6b395f097f5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -1456,15 +1456,6 @@ void CompositionalMultiphaseBase::assembleSystem( real64 const GEOS_UNUSED_PARAM { GEOS_MARK_FUNCTION; - /* - assembleZFormulationFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); - */ - - // Accumulation term if (m_useZFormulation) { @@ -1472,6 +1463,12 @@ void CompositionalMultiphaseBase::assembleSystem( real64 const GEOS_UNUSED_PARAM dofManager, localMatrix, localRhs ); + + assembleZFormulationFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); } else { @@ -1479,25 +1476,23 @@ void CompositionalMultiphaseBase::assembleSystem( real64 const GEOS_UNUSED_PARAM dofManager, localMatrix, localRhs ); - } - - // Flux term - if( m_isJumpStabilized ) - { - assembleStabilizedFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); - } - else - { - assembleFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); + if( m_isJumpStabilized ) + { + assembleStabilizedFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); + } + else + { + assembleFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); + } } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index bb7cb74f262..5295f1e9fa2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -55,6 +55,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/DirichletFluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/ThermalDirichletFluxComputeKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/AquiferBCKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp" @@ -235,7 +236,6 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, elemDofKey, m_hasCapPressure, m_useTotalMassEquation, - m_useZFormulation, fluxApprox.upwindingParams(), getName(), mesh.getElemManager(), @@ -314,66 +314,20 @@ void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, { typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); - /* - // Convective flux - if( m_isThermal ) - { - thermalCompositionalMultiphaseFVMKernels:: - FluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasCapPressure, - m_useTotalMassEquation, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); - } - else - { - if( m_dbcParams.useDBC ) - { - dissipationCompositionalMultiphaseFVMKernels:: - FluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasCapPressure, - m_useTotalMassEquation, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView(), - m_dbcParams.omega, - getNonlinearSolverParameters().m_numNewtonIterations, - m_dbcParams.continuation, - m_dbcParams.miscible, - m_dbcParams.kappamin, - m_dbcParams.contMultiplier ); - } - else - { - } - } - */ + GEOS_ERROR_IF( m_isThermal, GEOS_FMT( + "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + GEOS_ERROR_IF( m_hasDiffusion || m_hasDispersion, GEOS_FMT( + "CompositionalMultiphaseBase {}: Z Formulation is currently not available for Diffusion or Dispersion", getDataContext() ) ); - // isothermal only for now + // isothermal only for now isothermalCompositionalMultiphaseFVMKernels:: - FluxComputeKernelFactory:: + FluxComputeZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), elemDofKey, m_hasCapPressure, m_useTotalMassEquation, - m_useZFormulation, fluxApprox.upwindingParams(), getName(), mesh.getElemManager(), @@ -381,52 +335,6 @@ void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, dt, localMatrix.toViewConstSizes(), localRhs.toView() ); - - // TO DO: implement diffusion and dispersion flux for Z formulation - /* - // Diffusive and dispersive flux - if( m_hasDiffusion || m_hasDispersion ) - { - - if( m_isThermal ) - { - thermalCompositionalMultiphaseFVMKernels:: - DiffusionDispersionFluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasDiffusion, - m_hasDispersion, - m_useTotalMassEquation, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); - } - else - { - isothermalCompositionalMultiphaseFVMKernels:: - DiffusionDispersionFluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasDiffusion, - m_hasDispersion, - m_useTotalMassEquation, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); - } - } - */ - } ); } ); } @@ -941,7 +849,8 @@ void CompositionalMultiphaseFVM::updatePhaseMobility( ObjectManagerBase & dataGr if( m_isThermal ) { // For now: isothermal only - GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + GEOS_ERROR_IF( m_isThermal, GEOS_FMT( + "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); } else { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp index c6b3576eff8..56bc3b43d3c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernel.hpp @@ -35,7 +35,6 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/PPUPhaseFlux.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/C1PPUPhaseFlux.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/IHUPhaseFlux.hpp" -#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp" namespace geos { @@ -325,34 +324,7 @@ class FluxComputeKernel : public FluxComputeKernelBase dCompFlux_dC ); } else - { - if( m_kernelFlags.isSet( FluxComputeKernelFlags::useZFormulation ) ) - { - isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFluxZFormulation::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - else - { + { isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFlux::compute< numComp, numFluxSupportPoints > ( m_numPhases, ip, @@ -375,9 +347,7 @@ class FluxComputeKernel : public FluxComputeKernelBase dPhaseFlux_dC, compFlux, dCompFlux_dP, - dCompFlux_dC ); - } - + dCompFlux_dC ); } // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives @@ -555,7 +525,6 @@ class FluxComputeKernelFactory string const & dofKey, integer const hasCapPressure, integer const useTotalMassEquation, - integer const useZFormulation, UpwindingParameters upwindingParams, string const & solverName, ElementRegionManager const & elemManager, @@ -583,8 +552,6 @@ class FluxComputeKernelFactory kernelFlags.set( FluxComputeKernelFlags::C1PPU ); else if( upwindingParams.upwindingScheme == UpwindingScheme::IHU ) kernelFlags.set( FluxComputeKernelFlags::IHU ); - if( useZFormulation ) - kernelFlags.set( FluxComputeKernelFlags::useZFormulation ); using kernelType = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp index c6b3576eff8..851831bb46f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp @@ -14,11 +14,11 @@ */ /** - * @file FluxComputeKernel.hpp + * @file FluxComputeZFormulationKernel.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP -#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEZFORMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEZFORMULATIONKERNEL_HPP #include "physicsSolvers/fluidFlow/kernels/compositional/FluxComputeKernelBase.hpp" @@ -44,14 +44,14 @@ namespace isothermalCompositionalMultiphaseFVMKernels { /** - * @class FluxComputeKernel + * @class FluxComputeZFormulationKernel * @tparam NUM_COMP number of fluid components * @tparam NUM_DOF number of degrees of freedom * @tparam STENCILWRAPPER the type of the stencil wrapper * @brief Define the interface for the assembly kernel in charge of flux terms */ template< integer NUM_COMP, integer NUM_DOF, typename STENCILWRAPPER > -class FluxComputeKernel : public FluxComputeKernelBase +class FluxComputeZFormulationKernel : public FluxComputeKernelBase { public: @@ -91,7 +91,7 @@ class FluxComputeKernel : public FluxComputeKernelBase * @param[inout] localRhs the local right-hand side vector * @param[in] kernelFlags flags packed together */ - FluxComputeKernel( integer const numPhases, + FluxComputeZFormulationKernel( integer const numPhases, globalIndex const rankOffset, STENCILWRAPPER const & stencilWrapper, DofNumberAccessor const & dofNumberAccessor, @@ -272,113 +272,30 @@ class FluxComputeKernel : public FluxComputeKernelBase localIndex k_up = -1; - if( m_kernelFlags.isSet( FluxComputeKernelFlags::C1PPU ) ) - { - isothermalCompositionalMultiphaseFVMKernelUtilities::C1PPUPhaseFlux::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_dCompFrac_dCompDens, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - else if( m_kernelFlags.isSet( FluxComputeKernelFlags::IHU ) ) - { - isothermalCompositionalMultiphaseFVMKernelUtilities::IHUPhaseFlux::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_dCompFrac_dCompDens, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - else - { - if( m_kernelFlags.isSet( FluxComputeKernelFlags::useZFormulation ) ) - { - isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFluxZFormulation::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - else - { - isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFlux::compute< numComp, numFluxSupportPoints > - ( m_numPhases, - ip, - m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), - seri, sesri, sei, - trans, - dTrans_dPres, - m_pres, - m_gravCoef, - m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, - m_phaseCompFrac, m_dPhaseCompFrac, - m_dCompFrac_dCompDens, - m_phaseMassDens, m_dPhaseMassDens, - m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, - k_up, - potGrad, - phaseFlux, - dPhaseFlux_dP, - dPhaseFlux_dC, - compFlux, - dCompFlux_dP, - dCompFlux_dC ); - } - - } + + + isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFluxZFormulation::compute< numComp, numFluxSupportPoints > + ( m_numPhases, + ip, + m_kernelFlags.isSet( FluxComputeKernelFlags::CapPressure ), + seri, sesri, sei, + trans, + dTrans_dPres, + m_pres, + m_gravCoef, + m_phaseMob, m_dPhaseMob, + m_dPhaseVolFrac, + m_phaseCompFrac, m_dPhaseCompFrac, + m_phaseMassDens, m_dPhaseMassDens, + m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, + k_up, + potGrad, + phaseFlux, + dPhaseFlux_dP, + dPhaseFlux_dC, + compFlux, + dCompFlux_dP, + dCompFlux_dC ); // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase @@ -525,9 +442,9 @@ class FluxComputeKernel : public FluxComputeKernelBase }; /** - * @class FluxComputeKernelFactory + * @class FluxComputeZFormulationKernelFactory */ -class FluxComputeKernelFactory +class FluxComputeZFormulationKernelFactory { public: @@ -555,7 +472,6 @@ class FluxComputeKernelFactory string const & dofKey, integer const hasCapPressure, integer const useTotalMassEquation, - integer const useZFormulation, UpwindingParameters upwindingParams, string const & solverName, ElementRegionManager const & elemManager, @@ -580,13 +496,18 @@ class FluxComputeKernelFactory kernelFlags.set( FluxComputeKernelFlags::TotalMassEquation ); if( upwindingParams.upwindingScheme == UpwindingScheme::C1PPU && isothermalCompositionalMultiphaseFVMKernelUtilities::epsC1PPU > 0 ) + { kernelFlags.set( FluxComputeKernelFlags::C1PPU ); + //GEOS_FMT("CompositionalMultiphaseBase {}: Z Formulation is currently not available for C1PPU ", getDataContext() ); + } else if( upwindingParams.upwindingScheme == UpwindingScheme::IHU ) + { kernelFlags.set( FluxComputeKernelFlags::IHU ); - if( useZFormulation ) - kernelFlags.set( FluxComputeKernelFlags::useZFormulation ); + //GEOS_FMT("CompositionalMultiphaseBase {}: Z Formulation is currently not available for IHU ", getDataContext() ); + } + - using kernelType = FluxComputeKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; + using kernelType = FluxComputeZFormulationKernel< NUM_COMP, NUM_DOF, STENCILWRAPPER >; typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); typename kernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); @@ -604,4 +525,4 @@ class FluxComputeKernelFactory } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEKERNEL_HPP +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_FLUXCOMPUTEZFORMULATIONKERNEL_HPP From 7c7b0bafa79575193299f8b095a064a75190f557 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Wed, 13 Nov 2024 17:17:54 -0600 Subject: [PATCH 36/47] applySystemSolution updates zc for Z formulation --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 46 ++++++++++++++----- .../PhaseMobilityZFormulationKernel.hpp | 9 ++-- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 5295f1e9fa2..dde3d7bf071 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -772,22 +772,44 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana pressureMask ); } - if( localScaling ) + if (m_useZFormulation) { - dofManager.addVectorToField( localSolution, - viewKeyStruct::elemDofFieldString(), - fields::flow::globalCompDensity::key(), - fields::flow::globalCompDensityScalingFactor::key(), - componentMask ); + if( localScaling ) + { + dofManager.addVectorToField( localSolution, + viewKeyStruct::elemDofFieldString(), + fields::flow::globalCompFraction::key(), + fields::flow::globalCompDensityScalingFactor::key(), + componentMask ); + } + else + { + dofManager.addVectorToField( localSolution, + viewKeyStruct::elemDofFieldString(), + fields::flow::globalCompFraction::key(), + scalingFactor, + componentMask ); + } } else { - dofManager.addVectorToField( localSolution, - viewKeyStruct::elemDofFieldString(), - fields::flow::globalCompDensity::key(), - scalingFactor, - componentMask ); - } + if( localScaling ) + { + dofManager.addVectorToField( localSolution, + viewKeyStruct::elemDofFieldString(), + fields::flow::globalCompDensity::key(), + fields::flow::globalCompDensityScalingFactor::key(), + componentMask ); + } + else + { + dofManager.addVectorToField( localSolution, + viewKeyStruct::elemDofFieldString(), + fields::flow::globalCompDensity::key(), + scalingFactor, + componentMask ); + } + } if( m_isThermal ) { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp index 3bf95052767..7bdc78d85eb 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp @@ -59,7 +59,6 @@ class PhaseMobilityZFormulationKernel : public isothermalCompositionalMultiphase : Base(), m_phaseVolFrac( subRegion.getField< fields::flow::phaseVolumeFraction >() ), m_dPhaseVolFrac( subRegion.getField< fields::flow::dPhaseVolumeFraction >() ), - m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() ), m_phaseDens( fluid.phaseDensity() ), m_dPhaseDens( fluid.dPhaseDensity() ), m_phaseVisc( fluid.phaseViscosity() ), @@ -83,7 +82,6 @@ class PhaseMobilityZFormulationKernel : public isothermalCompositionalMultiphase { using Deriv = constitutive::multifluid::DerivativeOffset; - arraySlice2d< real64 const, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei]; arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseDens = m_phaseDens[ei][0]; arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_DC - 2 > const dPhaseDens = m_dPhaseDens[ei][0]; arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE - 2 > const phaseVisc = m_phaseVisc[ei][0]; @@ -116,11 +114,13 @@ class PhaseMobilityZFormulationKernel : public isothermalCompositionalMultiphase real64 const density = phaseDens[ip]; real64 const dDens_dP = dPhaseDens[ip][Deriv::dP]; - applyChainRule( numComp, dCompFrac_dCompDens, dPhaseDens[ip], dDens_dC, Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + dDens_dC[jc] = dPhaseDens[ip][Deriv::dC+jc]; real64 const viscosity = phaseVisc[ip]; real64 const dVisc_dP = dPhaseVisc[ip][Deriv::dP]; - applyChainRule( numComp, dCompFrac_dCompDens, dPhaseVisc[ip], dVisc_dC, Deriv::dC ); + for( integer jc = 0; jc < numComp; ++jc ) + dDens_dC[jc] = dPhaseVisc[ip][Deriv::dC+jc]; real64 const relPerm = phaseRelPerm[ip]; real64 dRelPerm_dP = 0.0; @@ -166,7 +166,6 @@ class PhaseMobilityZFormulationKernel : public isothermalCompositionalMultiphase /// Views on the phase volume fractions arrayView2d< real64 const, compflow::USD_PHASE > m_phaseVolFrac; arrayView3d< real64 const, compflow::USD_PHASE_DC > m_dPhaseVolFrac; - arrayView3d< real64 const, compflow::USD_COMP_DC > m_dCompFrac_dCompDens; /// Views on the phase densities arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > m_phaseDens; From 3efc82e8348004a277deacf9074d4b2e0f37a6ca Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 14 Nov 2024 15:22:14 -0600 Subject: [PATCH 37/47] missing --- .vscode-codespaces/settings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.vscode-codespaces/settings.json b/.vscode-codespaces/settings.json index 0a3374c5270..03d8b0fc930 100644 --- a/.vscode-codespaces/settings.json +++ b/.vscode-codespaces/settings.json @@ -1,9 +1,9 @@ { "cmake": { "sourceDirectory": "${workspaceFolder}/src", - "buildDirectory": "${workspaceFolder}/build-self_build-relwithdebinfo", - "installPrefix": "${workspaceFolder}/install-self_build-relwithdebinfo", - "cacheInit": "${workspaceFolder}/host-configs/CVX/self_build.cmake", + "buildDirectory": "${userHome}/geos-build", + "installPrefix": "${userHome}/geos-install", + "cacheInit": "/workspaces/GEOS/host-configs/environment.cmake", "configureSettings": { "BLT_MPI_COMMAND_APPEND": "--use-hwthread-cpus;--oversubscribe", "ENABLE_OPENMP": "OFF", From cebee64aa80f53f6520cf05927ca9850bba42fd4 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Fri, 15 Nov 2024 17:14:49 -0600 Subject: [PATCH 38/47] Many fixes, SolutionScaling for Z, removing compDensity field for Z --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 442 ++++++++++++------ .../fluidFlow/CompositionalMultiphaseBase.hpp | 10 + .../CompositionalMultiphaseBaseFields.hpp | 16 + .../fluidFlow/CompositionalMultiphaseFVM.cpp | 391 ++++++++++------ .../fluidFlow/CompositionalMultiphaseFVM.hpp | 7 +- .../CompositionalMultiphaseHybridFVM.cpp | 10 + .../CompositionalMultiphaseHybridFVM.hpp | 5 + .../ReactiveCompositionalMultiphaseOBL.cpp | 4 - ...activeCompositionalMultiphaseOBLFields.hpp | 8 - .../AccumulationZFormulationKernel.hpp | 2 + ...alingAndCheckingZFormulationKernelBase.hpp | 182 ++++++++ .../SolutionScalingZFormulationKernel.hpp | 348 ++++++++++++++ 12 files changed, 1136 insertions(+), 289 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingAndCheckingZFormulationKernelBase.hpp create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingZFormulationKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 45b41351c7a..18f98c0553d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -80,7 +80,8 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, m_allowCompDensChopping( 1 ), m_useTotalMassEquation( 1 ), m_useSimpleAccumulation( 1 ), - m_minCompDens( isothermalCompositionalMultiphaseBaseKernels::minDensForDivision ) + m_minCompDens( isothermalCompositionalMultiphaseBaseKernels::minDensForDivision ), + m_minCompFrac( isothermalCompositionalMultiphaseBaseKernels::minCompFracForDivision ) { //START_SPHINX_INCLUDE_00 this->registerWrapper( viewKeyStruct::inputTemperatureString(), &m_inputTemperature ). @@ -176,6 +177,12 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, setApplyDefaultValue( isothermalCompositionalMultiphaseBaseKernels::minDensForDivision ). setDescription( "Minimum allowed global component density" ); + this->registerWrapper( viewKeyStruct::minCompFracString(), &m_minCompFrac ). + setSizedFromParent( 0 ). + setInputFlag( InputFlags::OPTIONAL ). + setApplyDefaultValue( isothermalCompositionalMultiphaseBaseKernels::minCompFracForDivision ). + setDescription( "Minimum allowed global component fraction" ); + this->registerWrapper( viewKeyStruct::maxSequentialCompDensChangeString(), &m_maxSequentialCompDensChange ). setSizedFromParent( 0 ). setInputFlag( InputFlags::OPTIONAL ). @@ -385,10 +392,23 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< pressureScalingFactor >( getName() ); subRegion.registerField< temperatureScalingFactor >( getName() ); subRegion.registerField< globalCompDensityScalingFactor >( getName() ); + subRegion.registerField< globalCompFractionScalingFactor >( getName() ); // The resizing of the arrays needs to happen here, before the call to initializePreSubGroups, // to make sure that the dimensions are properly set before the timeHistoryOutput starts its initialization. - +/* + subRegion.registerField< globalCompFraction >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + subRegion.registerField< globalCompFraction_n >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< globalCompFraction_k >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + } subRegion.registerField< globalCompDensity >( getName() ). setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); @@ -400,12 +420,46 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); } - - subRegion.registerField< globalCompFraction >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); subRegion.registerField< dGlobalCompFraction_dGlobalCompDensity >( getName() ). - reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); + reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); + */ + + + if (m_useZFormulation) + { + subRegion.registerField< globalCompFraction >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + subRegion.registerField< globalCompFraction_n >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< globalCompFraction_k >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + } + } + else + { + subRegion.registerField< globalCompDensity >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + subRegion.registerField< globalCompDensity_n >( getName() ). + reference().resizeDimension< 1 >( m_numComponents ); + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< globalCompDensity_k >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + } + subRegion.registerField< globalCompFraction >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + subRegion.registerField< dGlobalCompFraction_dGlobalCompDensity >( getName() ). + reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); + } + subRegion.registerField< phaseVolumeFraction >( getName() ). setDimLabels( 1, fluid.phaseNames() ). @@ -938,23 +992,29 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); - - arrayView2d< real64 const, compflow::USD_COMP > const compFrac = - subRegion.getField< fields::flow::globalCompFraction >(); - arrayView2d< real64, compflow::USD_COMP > const compDens = - subRegion.getField< fields::flow::globalCompDensity >(); - - forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + + if (!m_useZFormulation) { - for( integer ic = 0; ic < numComp; ++ic ) + arrayView2d< real64 const, compflow::USD_COMP > const compFrac = + subRegion.getField< fields::flow::globalCompFraction >(); + arrayView2d< real64, compflow::USD_COMP > const compDens = + subRegion.getField< fields::flow::globalCompDensity >(); + + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) { - compDens[ei][ic] = totalDens[ei][0] * compFrac[ei][ic]; - } - } ); + for( integer ic = 0; ic < numComp; ++ic ) + { + compDens[ei][ic] = totalDens[ei][0] * compFrac[ei][ic]; + } + } ); + } } ); // with initial component densities defined - check if they need to be corrected to avoid zero diags etc - chopNegativeDensities( domain ); + if (m_useZFormulation) + chopNegativeCompFractions( domain ); + else + chopNegativeDensities( domain ); // for some reason CUDA does not want the host_device lambda to be defined inside the generic lambda // I need the exact type of the subRegion for updateSolidflowProperties to work well. @@ -978,8 +1038,18 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, porousSolid.scaleReferencePorosity( netToGross ); saveConvergedState( subRegion ); // necessary for a meaningful porosity update in sequential schemes updatePorosityAndPermeability( subRegion ); - updateCompAmount( subRegion ); - updatePhaseVolumeFraction( subRegion ); + if( m_useZFormulation ) + { + updateCompAmountZFormulation( subRegion ); + updatePhaseVolumeFractionZFormulation( subRegion ); + } + else + { + updateCompAmount( subRegion ); + updatePhaseVolumeFraction( subRegion ); + } + + // Now, we initialize and update each constitutive model one by one @@ -1365,9 +1435,19 @@ void CompositionalMultiphaseBase::initializePostInitialConditionsPreSubGroups() arrayView1d< string const > const & regionNames ) { FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addElementFields( { fields::flow::pressure::key(), + if (m_useZFormulation) + { + fieldsToBeSync.addElementFields( { fields::flow::pressure::key(), + fields::flow::globalCompFraction::key() }, + regionNames ); + } + else + { + fieldsToBeSync.addElementFields( { fields::flow::pressure::key(), fields::flow::globalCompDensity::key() }, regionNames ); + } + CommunicationTools::getInstance().synchronizeFields( fieldsToBeSync, mesh, domain.getNeighbors(), false ); @@ -2060,9 +2140,16 @@ void CompositionalMultiphaseBase::applyDirichletBC( real64 const time_n, subRegion.getReference< array1d< globalIndex > >( dofKey ); arrayView1d< real64 const > const pres = subRegion.getReference< array1d< real64 > >( fields::flow::pressure::key() ); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = - subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompDensity::key() ); + + // for now to avoid lambda function complain + arrayView2d< real64 const, compflow::USD_COMP > compDens = + subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompFraction::key() ); arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); + if (!m_useZFormulation) + { + compDens = subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompDensity::key() ); + } + integer const numComp = m_numComponents; forAll< parallelDevicePolicy<> >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) @@ -2086,16 +2173,19 @@ void CompositionalMultiphaseBase::applyDirichletBC( real64 const time_n, pres[ei] ); localRhs[localRow] = rhsValue; - // 4.2. For each component, apply target global density value - for( integer ic = 0; ic < numComp; ++ic ) + if (!m_useZFormulation) { - FieldSpecificationEqual::SpecifyFieldValue( dofIndex + ic + 1, - rankOffset, - localMatrix, - rhsValue, - totalDens[ei][0] * compFrac[ei][ic], - compDens[ei][ic] ); - localRhs[localRow + ic + 1] = rhsValue; + // 4.2. For each component, apply target global density value + for( integer ic = 0; ic < numComp; ++ic ) + { + FieldSpecificationEqual::SpecifyFieldValue( dofIndex + ic + 1, + rankOffset, + localMatrix, + rhsValue, + totalDens[ei][0] * compFrac[ei][ic], + compDens[ei][ic] ); + localRhs[localRow + ic + 1] = rhsValue; + } } } ); } ); @@ -2266,24 +2356,14 @@ void CompositionalMultiphaseBase::chopNegativeDensities( DomainPartition & domai } ); } -real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & currentDt, - DomainPartition & domain ) +void CompositionalMultiphaseBase::chopNegativeCompFractions( DomainPartition & domain ) { - if( m_targetRelativePresChange >= 1.0 && - m_targetPhaseVolFracChange >= 1.0 && - m_targetRelativeCompDensChange >= 1.0 && - ( !m_isThermal || m_targetRelativeTempChange >= 1.0 ) ) - { - return LvArray::NumericLimits< real64 >::max; - } + GEOS_MARK_FUNCTION; - real64 maxRelativePresChange = 0.0; - real64 maxRelativeTempChange = 0.0; - real64 maxAbsolutePhaseVolFracChange = 0.0; - real64 maxRelativeCompDensChange = 0.0; + using namespace isothermalCompositionalMultiphaseBaseKernels; - integer const numPhase = m_numPhases; integer const numComp = m_numComponents; + real64 const minCompFrac = m_minCompFrac; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -2295,100 +2375,158 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & { arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const pres_n = subRegion.getField< fields::flow::pressure_n >(); - arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); - arrayView1d< real64 const > const temp_n = subRegion.getField< fields::flow::temperature_n >(); - arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = - subRegion.getField< fields::flow::phaseVolumeFraction >(); - arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac_n = - subRegion.getField< fields::flow::phaseVolumeFraction_n >(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = - subRegion.getField< fields::flow::globalCompDensity >(); - arrayView2d< real64, compflow::USD_COMP > const compDens_n = - subRegion.getField< fields::flow::globalCompDensity_n >(); - - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPresChange( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTempChange( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPhaseVolFracChange( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxCompDensChange( 0.0 ); + arrayView2d< real64, compflow::USD_COMP > const compFrac = + subRegion.getField< fields::flow::globalCompFraction >(); forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) { if( ghostRank[ei] < 0 ) { - // switch from relative to absolute when values less than 1 - subRegionMaxPresChange.max( LvArray::math::abs( pres[ei] - pres_n[ei] ) / LvArray::math::max( LvArray::math::abs( pres_n[ei] ), 1.0 ) ); - subRegionMaxTempChange.max( LvArray::math::abs( temp[ei] - temp_n[ei] ) / LvArray::math::max( LvArray::math::abs( temp_n[ei] ), 1.0 ) ); - for( integer ip = 0; ip < numPhase; ++ip ) - { - subRegionMaxPhaseVolFracChange.max( LvArray::math::abs( phaseVolFrac[ei][ip] - phaseVolFrac_n[ei][ip] ) ); - } for( integer ic = 0; ic < numComp; ++ic ) { - subRegionMaxCompDensChange.max( LvArray::math::abs( compDens[ei][ic] - compDens_n[ei][ic] ) / LvArray::math::max( LvArray::math::abs( compDens_n[ei][ic] ), 1.0 ) ); + if( compFrac[ei][ic] < minCompFrac ) + { + compFrac[ei][ic] = minCompFrac; + } } } } ); + } ); + } ); +} + +real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & currentDt, + DomainPartition & domain ) +{ + // TODO: implement Dt estimation based on compFrac change + + if (m_useZFormulation) + { + return LvArray::NumericLimits< real64 >::max; + } + else + { + if( m_targetRelativePresChange >= 1.0 && + m_targetPhaseVolFracChange >= 1.0 && + m_targetRelativeCompDensChange >= 1.0 && + ( !m_isThermal || m_targetRelativeTempChange >= 1.0 ) ) + { + return LvArray::NumericLimits< real64 >::max; + } + + real64 maxRelativePresChange = 0.0; + real64 maxRelativeTempChange = 0.0; + real64 maxAbsolutePhaseVolFracChange = 0.0; + real64 maxRelativeCompDensChange = 0.0; + + integer const numPhase = m_numPhases; + integer const numComp = m_numComponents; + + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) + { + mesh.getElemManager().forElementSubRegions( regionNames, + [&]( localIndex const, + ElementSubRegionBase & subRegion ) + { + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const pres_n = subRegion.getField< fields::flow::pressure_n >(); + arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); + arrayView1d< real64 const > const temp_n = subRegion.getField< fields::flow::temperature_n >(); + arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = + subRegion.getField< fields::flow::phaseVolumeFraction >(); + arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac_n = + subRegion.getField< fields::flow::phaseVolumeFraction_n >(); + arrayView2d< real64 const, compflow::USD_COMP > const compDens = + subRegion.getField< fields::flow::globalCompDensity >(); + arrayView2d< real64, compflow::USD_COMP > const compDens_n = + subRegion.getField< fields::flow::globalCompDensity_n >(); + + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPresChange( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTempChange( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPhaseVolFracChange( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxCompDensChange( 0.0 ); + + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( ghostRank[ei] < 0 ) + { + // switch from relative to absolute when values less than 1 + subRegionMaxPresChange.max( LvArray::math::abs( pres[ei] - pres_n[ei] ) / LvArray::math::max( LvArray::math::abs( pres_n[ei] ), 1.0 ) ); + subRegionMaxTempChange.max( LvArray::math::abs( temp[ei] - temp_n[ei] ) / LvArray::math::max( LvArray::math::abs( temp_n[ei] ), 1.0 ) ); + for( integer ip = 0; ip < numPhase; ++ip ) + { + subRegionMaxPhaseVolFracChange.max( LvArray::math::abs( phaseVolFrac[ei][ip] - phaseVolFrac_n[ei][ip] ) ); + } + for( integer ic = 0; ic < numComp; ++ic ) + { + subRegionMaxCompDensChange.max( LvArray::math::abs( compDens[ei][ic] - compDens_n[ei][ic] ) / LvArray::math::max( LvArray::math::abs( compDens_n[ei][ic] ), 1.0 ) ); + } + } + } ); - maxRelativePresChange = LvArray::math::max( maxRelativePresChange, subRegionMaxPresChange.get() ); - maxRelativeTempChange = LvArray::math::max( maxRelativeTempChange, subRegionMaxTempChange.get() ); - maxAbsolutePhaseVolFracChange = LvArray::math::max( maxAbsolutePhaseVolFracChange, subRegionMaxPhaseVolFracChange.get() ); - maxRelativeCompDensChange = LvArray::math::max( maxRelativeCompDensChange, subRegionMaxCompDensChange.get() ); + maxRelativePresChange = LvArray::math::max( maxRelativePresChange, subRegionMaxPresChange.get() ); + maxRelativeTempChange = LvArray::math::max( maxRelativeTempChange, subRegionMaxTempChange.get() ); + maxAbsolutePhaseVolFracChange = LvArray::math::max( maxAbsolutePhaseVolFracChange, subRegionMaxPhaseVolFracChange.get() ); + maxRelativeCompDensChange = LvArray::math::max( maxRelativeCompDensChange, subRegionMaxCompDensChange.get() ); + } ); } ); - } ); - maxRelativePresChange = MpiWrapper::max( maxRelativePresChange ); - maxAbsolutePhaseVolFracChange = MpiWrapper::max( maxAbsolutePhaseVolFracChange ); + maxRelativePresChange = MpiWrapper::max( maxRelativePresChange ); + maxAbsolutePhaseVolFracChange = MpiWrapper::max( maxAbsolutePhaseVolFracChange ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative pressure change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativePresChange, 3 ) ) ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max absolute phase volume fraction change during time step = {}", - getName(), GEOS_FMT( "{:.{}f}", maxAbsolutePhaseVolFracChange, 3 ) ) ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative pressure change during time step = {} %", + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativePresChange, 3 ) ) ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max absolute phase volume fraction change during time step = {}", + getName(), GEOS_FMT( "{:.{}f}", maxAbsolutePhaseVolFracChange, 3 ) ) ); - if( m_targetRelativeCompDensChange < LvArray::NumericLimits< real64 >::max ) - { - maxRelativeCompDensChange = MpiWrapper::max( maxRelativeCompDensChange ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative component density change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeCompDensChange, 3 ) ) ); - } + if( m_targetRelativeCompDensChange < LvArray::NumericLimits< real64 >::max ) + { + maxRelativeCompDensChange = MpiWrapper::max( maxRelativeCompDensChange ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative component density change during time step = {} %", + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeCompDensChange, 3 ) ) ); + } - if( m_isThermal ) - { - maxRelativeTempChange = MpiWrapper::max( maxRelativeTempChange ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative temperature change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeTempChange, 3 ) ) ); - } + if( m_isThermal ) + { + maxRelativeTempChange = MpiWrapper::max( maxRelativeTempChange ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative temperature change during time step = {} %", + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeTempChange, 3 ) ) ); + } - real64 const eps = LvArray::NumericLimits< real64 >::epsilon; - - real64 const nextDtPressure = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativePresChange - / std::max( eps, maxRelativePresChange + m_solutionChangeScalingFactor * m_targetRelativePresChange ); - if( m_nonlinearSolverParameters.getLogLevel() > 0 ) - GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on pressure change = {}", getName(), nextDtPressure )); - real64 const nextDtPhaseVolFrac = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetPhaseVolFracChange - / std::max( eps, maxAbsolutePhaseVolFracChange + m_solutionChangeScalingFactor * m_targetPhaseVolFracChange ); - if( m_nonlinearSolverParameters.getLogLevel() > 0 ) - GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on phase volume fraction change = {}", getName(), nextDtPhaseVolFrac )); - real64 nextDtCompDens = LvArray::NumericLimits< real64 >::max; - if( m_targetRelativeCompDensChange < LvArray::NumericLimits< real64 >::max ) - { - nextDtCompDens = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativeCompDensChange - / std::max( eps, maxRelativeCompDensChange + m_solutionChangeScalingFactor * m_targetRelativeCompDensChange ); + real64 const eps = LvArray::NumericLimits< real64 >::epsilon; + + real64 const nextDtPressure = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativePresChange + / std::max( eps, maxRelativePresChange + m_solutionChangeScalingFactor * m_targetRelativePresChange ); if( m_nonlinearSolverParameters.getLogLevel() > 0 ) - GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on component density change = {}", getName(), nextDtCompDens )); - } - real64 nextDtTemperature = LvArray::NumericLimits< real64 >::max; - if( m_isThermal ) - { - nextDtTemperature = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativeTempChange - / std::max( eps, maxRelativeTempChange + m_solutionChangeScalingFactor * m_targetRelativeTempChange ); + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on pressure change = {}", getName(), nextDtPressure )); + real64 const nextDtPhaseVolFrac = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetPhaseVolFracChange + / std::max( eps, maxAbsolutePhaseVolFracChange + m_solutionChangeScalingFactor * m_targetPhaseVolFracChange ); if( m_nonlinearSolverParameters.getLogLevel() > 0 ) - GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on temperature change = {}", getName(), nextDtPhaseVolFrac )); - } + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on phase volume fraction change = {}", getName(), nextDtPhaseVolFrac )); + real64 nextDtCompDens = LvArray::NumericLimits< real64 >::max; + if( m_targetRelativeCompDensChange < LvArray::NumericLimits< real64 >::max ) + { + nextDtCompDens = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativeCompDensChange + / std::max( eps, maxRelativeCompDensChange + m_solutionChangeScalingFactor * m_targetRelativeCompDensChange ); + if( m_nonlinearSolverParameters.getLogLevel() > 0 ) + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on component density change = {}", getName(), nextDtCompDens )); + } + real64 nextDtTemperature = LvArray::NumericLimits< real64 >::max; + if( m_isThermal ) + { + nextDtTemperature = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativeTempChange + / std::max( eps, maxRelativeTempChange + m_solutionChangeScalingFactor * m_targetRelativeTempChange ); + if( m_nonlinearSolverParameters.getLogLevel() > 0 ) + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on temperature change = {}", getName(), nextDtPhaseVolFrac )); + } - return std::min( std::min( nextDtPressure, std::min( nextDtPhaseVolFrac, nextDtCompDens ) ), nextDtTemperature ); + return std::min( std::min( nextDtPressure, std::min( nextDtPhaseVolFrac, nextDtCompDens ) ), nextDtTemperature ); + } } real64 CompositionalMultiphaseBase::setNextDtBasedOnCFL( const geos::real64 & currentDt, geos::DomainPartition & domain ) @@ -2575,11 +2713,23 @@ void CompositionalMultiphaseBase::resetStateToBeginningOfStep( DomainPartition & subRegion.template getField< fields::flow::pressure_n >(); pres.setValues< parallelDevicePolicy<> >( pres_n ); - arrayView2d< real64, compflow::USD_COMP > const & compDens = - subRegion.template getField< fields::flow::globalCompDensity >(); - arrayView2d< real64 const, compflow::USD_COMP > const & compDens_n = - subRegion.template getField< fields::flow::globalCompDensity_n >(); - compDens.setValues< parallelDevicePolicy<> >( compDens_n ); + if (m_useZFormulation) + { + arrayView2d< real64, compflow::USD_COMP > const & compFrac = + subRegion.template getField< fields::flow::globalCompFraction >(); + arrayView2d< real64 const, compflow::USD_COMP > const & compFrac_n = + subRegion.template getField< fields::flow::globalCompFraction_n >(); + compFrac.setValues< parallelDevicePolicy<> >( compFrac_n ); + } + else + { + arrayView2d< real64, compflow::USD_COMP > const & compDens = + subRegion.template getField< fields::flow::globalCompDensity >(); + arrayView2d< real64 const, compflow::USD_COMP > const & compDens_n = + subRegion.template getField< fields::flow::globalCompDensity_n >(); + compDens.setValues< parallelDevicePolicy<> >( compDens_n ); + } + if( m_isThermal ) { @@ -2706,24 +2856,42 @@ void CompositionalMultiphaseBase::saveConvergedState( ElementSubRegionBase & sub { FlowSolverBase::saveConvergedState( subRegion ); - arrayView2d< real64 const, compflow::USD_COMP > const & compDens = - subRegion.template getField< fields::flow::globalCompDensity >(); - arrayView2d< real64, compflow::USD_COMP > const & compDens_n = - subRegion.template getField< fields::flow::globalCompDensity_n >(); - compDens_n.setValues< parallelDevicePolicy<> >( compDens ); + if (m_useZFormulation) + { + arrayView2d< real64 const, compflow::USD_COMP > const & compFrac = + subRegion.template getField< fields::flow::globalCompFraction >(); + arrayView2d< real64, compflow::USD_COMP > const & compFrac_n = + subRegion.template getField< fields::flow::globalCompFraction_n >(); + compFrac_n.setValues< parallelDevicePolicy<> >( compFrac ); + if( m_isFixedStressPoromechanicsUpdate ) + { + arrayView2d< real64, compflow::USD_COMP > const & compFrac_k = + subRegion.template getField< fields::flow::globalCompFraction_k >(); + compFrac_k.setValues< parallelDevicePolicy<> >( compFrac ); + } + } + else + { + arrayView2d< real64 const, compflow::USD_COMP > const & compDens = + subRegion.template getField< fields::flow::globalCompDensity >(); + arrayView2d< real64, compflow::USD_COMP > const & compDens_n = + subRegion.template getField< fields::flow::globalCompDensity_n >(); + compDens_n.setValues< parallelDevicePolicy<> >( compDens ); + if( m_isFixedStressPoromechanicsUpdate ) + { + arrayView2d< real64, compflow::USD_COMP > const & compDens_k = + subRegion.template getField< fields::flow::globalCompDensity_k >(); + compDens_k.setValues< parallelDevicePolicy<> >( compDens ); + } + } + + arrayView2d< real64 const, compflow::USD_COMP > const & compAmount = subRegion.template getField< fields::flow::compAmount >(); arrayView2d< real64, compflow::USD_COMP > const & compAmount_n = subRegion.template getField< fields::flow::compAmount_n >(); compAmount_n.setValues< parallelDevicePolicy<> >( compAmount ); - - if( m_isFixedStressPoromechanicsUpdate ) - { - arrayView2d< real64, compflow::USD_COMP > const & compDens_k = - subRegion.template getField< fields::flow::globalCompDensity_k >(); - compDens_k.setValues< parallelDevicePolicy<> >( compDens ); - } } void CompositionalMultiphaseBase::saveSequentialIterationState( DomainPartition & domain ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index 539998ed06f..1f5f9f1be14 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -313,6 +313,7 @@ class CompositionalMultiphaseBase : public FlowSolverBase static constexpr char const * useTotalMassEquationString() { return "useTotalMassEquation"; } static constexpr char const * useSimpleAccumulationString() { return "useSimpleAccumulation"; } static constexpr char const * minCompDensString() { return "minCompDens"; } + static constexpr char const * minCompFracString() { return "minCompFrac"; } static constexpr char const * maxSequentialCompDensChangeString() { return "maxSequentialCompDensChange"; } static constexpr char const * minScalingFactorString() { return "minScalingFactor"; } @@ -406,6 +407,12 @@ class CompositionalMultiphaseBase : public FlowSolverBase */ void chopNegativeDensities( DomainPartition & domain ); + /** + * @brief Sets all the negative component fractions (if any) to zero. + * @param domain the physical domain object + */ + void chopNegativeCompFractions( DomainPartition & domain ); + virtual real64 setNextDtBasedOnStateChange( real64 const & currentDt, DomainPartition & domain ) override; @@ -532,6 +539,9 @@ class CompositionalMultiphaseBase : public FlowSolverBase /// minimum allowed global component density real64 m_minCompDens; + /// minimum allowed global component fraction + real64 m_minCompFrac; + /// name of the fluid constitutive model used as a reference for component/phase description string m_referenceFluidModelName; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp index 8fddb175273..019cea65b6d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp @@ -72,6 +72,14 @@ DECLARE_FIELD( globalCompFraction, WRITE_AND_READ, "Global component fraction" ); +DECLARE_FIELD( globalCompFraction_n, + "globalCompFraction_n", + array2dLayoutComp, + 0, + NOPLOT, + NO_WRITE, + "Global component fraction at the previous converged time step" ); + DECLARE_FIELD( globalCompFraction_k, "globalCompFraction_k", array2dLayoutComp, @@ -177,6 +185,14 @@ DECLARE_FIELD( globalCompDensityScalingFactor, NO_WRITE, "Scaling factors for global component densities" ); +DECLARE_FIELD( globalCompFractionScalingFactor, + "globalCompFractionScalingFactor", + array1d< real64 >, + 1, + NOPLOT, + NO_WRITE, + "Scaling factors for global component fractions" ); + DECLARE_FIELD( compAmount, "compAmount", array2dLayoutComp, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index b035825351a..7e1f861e274 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -58,6 +58,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingZFormulationKernel.hpp" namespace geos { @@ -538,10 +539,127 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d { GEOS_MARK_FUNCTION; + if (m_useZFormulation) + { + return scalingForSystemSolutionZFormulation( domain, dofManager, localSolution ); + } + else + { + string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); + real64 scalingFactor = 1.0; + real64 maxDeltaPres = 0.0, maxDeltaCompDens = 0.0, maxDeltaTemp = 0.0; + real64 minPresScalingFactor = 1.0, minCompDensScalingFactor = 1.0, minTempScalingFactor = 1.0; + + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) + { + mesh.getElemManager().forElementSubRegions( regionNames, + [&]( localIndex const, + ElementSubRegionBase & subRegion ) + { + arrayView1d< real64 const > const pressure = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const temperature = subRegion.getField< fields::flow::temperature >(); + arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getField< fields::flow::globalCompDensity >(); + arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); + arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); + arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); + + const integer temperatureOffset = m_numComponents+1; + auto const subRegionData = + m_isThermal + ? thermalCompositionalMultiphaseBaseKernels:: + SolutionScalingKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, + m_maxAbsolutePresChange, + m_maxRelativeTempChange, + m_maxCompFracChange, + m_maxRelativeCompDensChange, + pressure, + temperature, + compDens, + pressureScalingFactor, + compDensScalingFactor, + temperatureScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution, + temperatureOffset ) + : isothermalCompositionalMultiphaseBaseKernels:: + SolutionScalingKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, + m_maxAbsolutePresChange, + m_maxCompFracChange, + m_maxRelativeCompDensChange, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution ); + + if( m_scalingType == ScalingType::Global ) + { + scalingFactor = std::min( scalingFactor, subRegionData.localMinVal ); + } + maxDeltaPres = std::max( maxDeltaPres, subRegionData.localMaxDeltaPres ); + maxDeltaCompDens = std::max( maxDeltaCompDens, subRegionData.localMaxDeltaCompDens ); + maxDeltaTemp = std::max( maxDeltaTemp, subRegionData.localMaxDeltaTemp ); + minPresScalingFactor = std::min( minPresScalingFactor, subRegionData.localMinPresScalingFactor ); + minCompDensScalingFactor = std::min( minCompDensScalingFactor, subRegionData.localMinCompDensScalingFactor ); + minTempScalingFactor = std::min( minTempScalingFactor, subRegionData.localMinTempScalingFactor ); + } ); + } ); + + scalingFactor = MpiWrapper::min( scalingFactor ); + maxDeltaPres = MpiWrapper::max( maxDeltaPres ); + maxDeltaCompDens = MpiWrapper::max( maxDeltaCompDens ); + minPresScalingFactor = MpiWrapper::min( minPresScalingFactor ); + minCompDensScalingFactor = MpiWrapper::min( minCompDensScalingFactor ); + + string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max pressure change = {} Pa (before scaling)", + getName(), GEOS_FMT( "{:.{}f}", maxDeltaPres, 3 ) ) ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max component density change = {} {} (before scaling)", + getName(), GEOS_FMT( "{:.{}f}", maxDeltaCompDens, 3 ), massUnit ) ); + + if( m_isThermal ) + { + maxDeltaTemp = MpiWrapper::max( maxDeltaTemp ); + minTempScalingFactor = MpiWrapper::min( minTempScalingFactor ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max temperature change = {} K (before scaling)", + getName(), GEOS_FMT( "{:.{}f}", maxDeltaTemp, 3 ) ) ); + } + + if( m_scalingType == ScalingType::Local ) + { + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Min pressure scaling factor = {}", getName(), minPresScalingFactor ) ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Min component density scaling factor = {}", getName(), minCompDensScalingFactor ) ); + if( m_isThermal ) + { + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Min temperature scaling factor = {}", getName(), minTempScalingFactor ) ); + } + } + + return LvArray::math::max( scalingFactor, m_minScalingFactor ); + } +} + +real64 CompositionalMultiphaseFVM::scalingForSystemSolutionZFormulation( DomainPartition & domain, + DofManager const & dofManager, + arrayView1d< real64 const > const & localSolution ) +{ + GEOS_MARK_FUNCTION; + string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); real64 scalingFactor = 1.0; - real64 maxDeltaPres = 0.0, maxDeltaCompDens = 0.0, maxDeltaTemp = 0.0; - real64 minPresScalingFactor = 1.0, minCompDensScalingFactor = 1.0, minTempScalingFactor = 1.0; + real64 maxDeltaPres = 0.0, maxDeltaCompFrac = 0.0, maxDeltaTemp = 0.0; + real64 minPresScalingFactor = 1.0, minCompFracScalingFactor = 1.0, minTempScalingFactor = 1.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -553,73 +671,52 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d { arrayView1d< real64 const > const pressure = subRegion.getField< fields::flow::pressure >(); arrayView1d< real64 const > const temperature = subRegion.getField< fields::flow::temperature >(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getField< fields::flow::globalCompDensity >(); + arrayView2d< real64 const, compflow::USD_COMP > const compFrac = subRegion.getField< fields::flow::globalCompFraction >(); arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); - arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); - - const integer temperatureOffset = m_numComponents+1; - auto const subRegionData = - m_isThermal - ? thermalCompositionalMultiphaseBaseKernels:: - SolutionScalingKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, - m_maxAbsolutePresChange, - m_maxRelativeTempChange, - m_maxCompFracChange, - m_maxRelativeCompDensChange, - pressure, - temperature, - compDens, - pressureScalingFactor, - compDensScalingFactor, - temperatureScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution, - temperatureOffset ) - : isothermalCompositionalMultiphaseBaseKernels:: - SolutionScalingKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, - m_maxAbsolutePresChange, - m_maxCompFracChange, - m_maxRelativeCompDensChange, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution ); + arrayView1d< real64 > compFracScalingFactor = subRegion.getField< fields::flow::globalCompFractionScalingFactor >(); + + GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + + auto const subRegionData = isothermalCompositionalMultiphaseBaseKernels:: + SolutionScalingZFormulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, + m_maxAbsolutePresChange, + m_maxCompFracChange, + pressure, + compFrac, + pressureScalingFactor, + compFracScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution ); if( m_scalingType == ScalingType::Global ) { scalingFactor = std::min( scalingFactor, subRegionData.localMinVal ); } maxDeltaPres = std::max( maxDeltaPres, subRegionData.localMaxDeltaPres ); - maxDeltaCompDens = std::max( maxDeltaCompDens, subRegionData.localMaxDeltaCompDens ); + maxDeltaCompFrac = std::max( maxDeltaCompFrac, subRegionData.localMaxDeltaCompFrac ); maxDeltaTemp = std::max( maxDeltaTemp, subRegionData.localMaxDeltaTemp ); minPresScalingFactor = std::min( minPresScalingFactor, subRegionData.localMinPresScalingFactor ); - minCompDensScalingFactor = std::min( minCompDensScalingFactor, subRegionData.localMinCompDensScalingFactor ); + minCompFracScalingFactor = std::min( minCompFracScalingFactor, subRegionData.localMinCompFracScalingFactor ); minTempScalingFactor = std::min( minTempScalingFactor, subRegionData.localMinTempScalingFactor ); + } ); } ); scalingFactor = MpiWrapper::min( scalingFactor ); maxDeltaPres = MpiWrapper::max( maxDeltaPres ); - maxDeltaCompDens = MpiWrapper::max( maxDeltaCompDens ); + maxDeltaCompFrac = MpiWrapper::max( maxDeltaCompFrac ); minPresScalingFactor = MpiWrapper::min( minPresScalingFactor ); - minCompDensScalingFactor = MpiWrapper::min( minCompDensScalingFactor ); + minCompFracScalingFactor = MpiWrapper::min( minCompFracScalingFactor ); - string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max pressure change = {} Pa (before scaling)", getName(), GEOS_FMT( "{:.{}f}", maxDeltaPres, 3 ) ) ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max component density change = {} {} (before scaling)", - getName(), GEOS_FMT( "{:.{}f}", maxDeltaCompDens, 3 ), massUnit ) ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max component fraction change = {} (before scaling)", + getName(), GEOS_FMT( "{:.{}f}", maxDeltaCompFrac, 3 ) ) ); if( m_isThermal ) { @@ -632,7 +729,7 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d if( m_scalingType == ScalingType::Local ) { GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Min pressure scaling factor = {}", getName(), minPresScalingFactor ) ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Min component density scaling factor = {}", getName(), minCompDensScalingFactor ) ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Min component fraction scaling factor = {}", getName(), minCompFracScalingFactor ) ); if( m_isThermal ) { GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Min temperature scaling factor = {}", getName(), minTempScalingFactor ) ); @@ -649,97 +746,103 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, { GEOS_MARK_FUNCTION; - string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); - integer localCheck = 1; - real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; - integer numNegPres = 0, numNegDens = 0, numNegTotalDens = 0; - - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel & mesh, - arrayView1d< string const > const & regionNames ) + // TO DO: Implement the solution check for Z Formulation + if (m_useZFormulation) + return true; + else { - mesh.getElemManager().forElementSubRegions( regionNames, - [&]( localIndex const, - ElementSubRegionBase & subRegion ) - { - arrayView1d< real64 const > const pressure = - subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const temperature = - subRegion.getField< fields::flow::temperature >(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = - subRegion.getField< fields::flow::globalCompDensity >(); - arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); - arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); - arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); - // check that pressure and component densities are non-negative - // for thermal, check that temperature is above 273.15 K - const integer temperatureOffset = m_numComponents+1; - auto const subRegionData = - m_isThermal - ? thermalCompositionalMultiphaseBaseKernels:: - SolutionCheckKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - temperature, - compDens, - pressureScalingFactor, - temperatureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution, - temperatureOffset ) - : isothermalCompositionalMultiphaseBaseKernels:: - SolutionCheckKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution ); + string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); + integer localCheck = 1; + real64 minPres = 0.0, minDens = 0.0, minTotalDens = 0.0; + integer numNegPres = 0, numNegDens = 0, numNegTotalDens = 0; - localCheck = std::min( localCheck, subRegionData.localMinVal ); - - minPres = std::min( minPres, subRegionData.localMinPres ); - minDens = std::min( minDens, subRegionData.localMinDens ); - minTotalDens = std::min( minTotalDens, subRegionData.localMinTotalDens ); - numNegPres += subRegionData.localNumNegPressures; - numNegDens += subRegionData.localNumNegDens; - numNegTotalDens += subRegionData.localNumNegTotalDens; + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) + { + mesh.getElemManager().forElementSubRegions( regionNames, + [&]( localIndex const, + ElementSubRegionBase & subRegion ) + { + arrayView1d< real64 const > const pressure = + subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const temperature = + subRegion.getField< fields::flow::temperature >(); + arrayView2d< real64 const, compflow::USD_COMP > const compDens = + subRegion.getField< fields::flow::globalCompDensity >(); + arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); + arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); + arrayView1d< real64 > compDensScalingFactor = subRegion.getField< fields::flow::globalCompDensityScalingFactor >(); + // check that pressure and component densities are non-negative + // for thermal, check that temperature is above 273.15 K + const integer temperatureOffset = m_numComponents+1; + auto const subRegionData = + m_isThermal + ? thermalCompositionalMultiphaseBaseKernels:: + SolutionCheckKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + temperature, + compDens, + pressureScalingFactor, + temperatureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution, + temperatureOffset ) + : isothermalCompositionalMultiphaseBaseKernels:: + SolutionCheckKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution ); + + localCheck = std::min( localCheck, subRegionData.localMinVal ); + + minPres = std::min( minPres, subRegionData.localMinPres ); + minDens = std::min( minDens, subRegionData.localMinDens ); + minTotalDens = std::min( minTotalDens, subRegionData.localMinTotalDens ); + numNegPres += subRegionData.localNumNegPressures; + numNegDens += subRegionData.localNumNegDens; + numNegTotalDens += subRegionData.localNumNegTotalDens; + } ); } ); - } ); - minPres = MpiWrapper::min( minPres ); - minDens = MpiWrapper::min( minDens ); - minTotalDens = MpiWrapper::min( minTotalDens ); - numNegPres = MpiWrapper::sum( numNegPres ); - numNegDens = MpiWrapper::sum( numNegDens ); - numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); - - if( numNegPres > 0 ) - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative pressure values: {}, minimum value: {} Pa", - getName(), numNegPres, fmt::format( "{:.{}f}", minPres, 3 ) ) ); - string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; - if( numNegDens > 0 ) - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative component density values: {}, minimum value: {} {}}", - getName(), numNegDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); - if( minTotalDens > 0 ) - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}}", - getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); - - return MpiWrapper::min( localCheck ); + minPres = MpiWrapper::min( minPres ); + minDens = MpiWrapper::min( minDens ); + minTotalDens = MpiWrapper::min( minTotalDens ); + numNegPres = MpiWrapper::sum( numNegPres ); + numNegDens = MpiWrapper::sum( numNegDens ); + numNegTotalDens = MpiWrapper::sum( numNegTotalDens ); + + if( numNegPres > 0 ) + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative pressure values: {}, minimum value: {} Pa", + getName(), numNegPres, fmt::format( "{:.{}f}", minPres, 3 ) ) ); + string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; + if( numNegDens > 0 ) + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative component density values: {}, minimum value: {} {}}", + getName(), numNegDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + if( minTotalDens > 0 ) + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}}", + getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + + return MpiWrapper::min( localCheck ); + } } void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofManager, @@ -834,7 +937,9 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana // if component density chopping is allowed, some component densities may be negative after the update // these negative component densities are set to zero in this function - if( m_allowCompDensChopping ) + + // TODO: implement chopNegativeZ + if( m_allowCompDensChopping && !m_useZFormulation) { chopNegativeDensities( domain ); } @@ -843,7 +948,15 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana MeshLevel & mesh, arrayView1d< string const > const & regionNames ) { - std::vector< string > fields{ fields::flow::pressure::key(), fields::flow::globalCompDensity::key() }; + std::vector< string > fields{ fields::flow::pressure::key() }; + if (m_useZFormulation) + { + fields.emplace_back( fields::flow::globalCompFraction::key() ); + } + else + { + fields.emplace_back( fields::flow::globalCompDensity::key() ); + } if( m_isThermal ) { fields.emplace_back( fields::flow::temperature::key() ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp index 242a1e27fa2..9747469c37c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp @@ -109,6 +109,11 @@ class CompositionalMultiphaseFVM : public CompositionalMultiphaseBase DofManager const & dofManager, arrayView1d< real64 const > const & localSolution ) override; + virtual real64 + scalingForSystemSolutionZFormulation( DomainPartition & domain, + DofManager const & dofManager, + arrayView1d< real64 const > const & localSolution ); + virtual bool checkSystemSolution( DomainPartition & domain, DofManager const & dofManager, @@ -121,7 +126,7 @@ class CompositionalMultiphaseFVM : public CompositionalMultiphaseBase real64 const scalingFactor, real64 const dt, DomainPartition & domain ) override; - + /**@}*/ virtual void diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index c4bf42ba28d..9659637f56e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -521,6 +521,16 @@ real64 CompositionalMultiphaseHybridFVM::scalingForSystemSolution( DomainPartiti return LvArray::math::max( MpiWrapper::min( scalingFactor ), m_minScalingFactor ); } +real64 CompositionalMultiphaseHybridFVM::scalingForSystemSolutionZFormulation( DomainPartition & domain, + DofManager const & dofManager, + arrayView1d< real64 const > const & localSolution ) +{ + GEOS_MARK_FUNCTION; + // z formulation not implemented + GEOS_UNUSED_VAR( domain, dofManager, localSolution ); + GEOS_ERROR( "Z formulation not yet available for this flow solver" ); + return 0; +} bool CompositionalMultiphaseHybridFVM::checkSystemSolution( DomainPartition & domain, DofManager const & dofManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp index 00dc9a37a37..8693d4f44b3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp @@ -111,6 +111,11 @@ class CompositionalMultiphaseHybridFVM : public CompositionalMultiphaseBase DofManager const & dofManager, arrayView1d< real64 const > const & localSolution ) override; + virtual real64 + scalingForSystemSolutionZFormulation( DomainPartition & domain, + DofManager const & dofManager, + arrayView1d< real64 const > const & localSolution ); + virtual bool checkSystemSolution( DomainPartition & domain, DofManager const & dofManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp index 3d8143e0d83..56875f9619c 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp @@ -272,10 +272,6 @@ void ReactiveCompositionalMultiphaseOBL::registerDataOnMesh( Group & meshBodies subRegion.registerField< bcGlobalCompFraction >( solverName ). reference().resizeDimension< 1 >( m_numComponents ); - // we need to register this fiels in any case (if there is a single component or not) - // to be able to pass the view to OBLOperatorsKernel - subRegion.registerField< globalCompFraction_n >( solverName ). - reference().resizeDimension< 1 >( m_numComponents ); // in principle, referencePorosity could be used directly from solid model, // but was duplicated to remove dependency on solid subRegion.registerField< referencePorosity >( solverName ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp index 84d9f0e5f54..f549c75467e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBLFields.hpp @@ -38,14 +38,6 @@ using array2dLayoutComp = array2d< real64, compflow::LAYOUT_COMP >; using array2dLayoutOBLOpVals = array2d< real64, compflow::LAYOUT_OBL_OPERATOR_VALUES >; using array3dLayoutOBLOpDers = array3d< real64, compflow::LAYOUT_OBL_OPERATOR_DERIVATIVES >; -DECLARE_FIELD( globalCompFraction_n, - "globalCompFraction_n", - array2dLayoutComp, - 0, - NOPLOT, - NO_WRITE, - "Global component fraction at the previous converged time step" ); - DECLARE_FIELD( bcGlobalCompFraction, "bcGlobalCompFraction", array2dLayoutComp, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp index 21d369c3201..e8dbe549ac4 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp @@ -38,6 +38,8 @@ namespace geos namespace isothermalCompositionalMultiphaseBaseKernels { + static constexpr real64 minCompFracForDivision = 0; + /******************************** AccumulationKernel ********************************/ /** diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingAndCheckingZFormulationKernelBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingAndCheckingZFormulationKernelBase.hpp new file mode 100644 index 00000000000..d724dcbced1 --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingAndCheckingZFormulationKernelBase.hpp @@ -0,0 +1,182 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SolutionScalingAndCheckingZFormulationKernelBase.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGZFORMULATIONKERNELBASE_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGZFORMULATIONKERNELBASE_HPP + +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "mesh/ElementSubRegionBase.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/** + * @class SolutionScalingAndCheckingZFormulationKernelBase + * @brief Define the kernel for scaling the solution and check its validity + */ +template< typename TYPE > +class SolutionScalingAndCheckingZFormulationKernelBase +{ +public: + + /** + * @brief Create a new kernel instance + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @param[in] pressure the pressure vector + * @param[in] compFrac the component density vector + * @param[in] pressureScalingFactor the pressure local scaling factor + * @param[in] compFracScalingFactor the component local scaling factor + */ + SolutionScalingAndCheckingZFormulationKernelBase( globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compFrac, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compFracScalingFactor ) + : m_rankOffset( rankOffset ), + m_numComp( numComp ), + m_dofNumber( subRegion.getReference< array1d< globalIndex > >( dofKey ) ), + m_ghostRank( subRegion.ghostRank() ), + m_localSolution( localSolution ), + m_pressure( pressure ), // not passed with fields::flow to be able to reuse this for wells + m_compFrac( compFrac ), // same here + m_pressureScalingFactor( pressureScalingFactor ), + m_compFracScalingFactor( compFracScalingFactor ) + { } + + /** + * @struct StackVariables + * @brief Kernel variables located on the stack + */ + struct StackVariables + { + GEOS_HOST_DEVICE + StackVariables() + { } + + StackVariables( real64 _localMinVal ) + : + localMinVal( _localMinVal ) + { } + + /// Index of the local row corresponding to this element + localIndex localRow; + + /// The local value + TYPE localMinVal; + }; + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] ei the element index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + stack.localMinVal = 1; + + // set row index and degrees of freedom indices for this element + stack.localRow = m_dofNumber[ei] - m_rankOffset; + } + + /** + * @brief Getter for the ghost rank + * @param[in] i the looping index of the element/node/face + * @return the ghost rank of the element/node/face + */ + GEOS_HOST_DEVICE + integer ghostRank( localIndex const i ) const + { return m_ghostRank( i ); } + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static TYPE + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + RAJA::ReduceMin< ReducePolicy< POLICY >, TYPE > minVal( 1 ); + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( kernelComponent.ghostRank( ei ) >= 0 ) + { + return; + } + + StackVariables stack; + kernelComponent.setup( ei, stack ); + kernelComponent.compute( ei, stack ); + minVal.min( stack.localMinVal ); + } ); + + return minVal.get(); + } + +protected: + + /// Offset for my MPI rank + globalIndex const m_rankOffset; + + /// Number of components + real64 const m_numComp; + + /// View on the dof numbers + arrayView1d< globalIndex const > const m_dofNumber; + + /// View on the ghost ranks + arrayView1d< integer const > const m_ghostRank; + + /// View on the local residual + arrayView1d< real64 const > const m_localSolution; + + /// View on the primary variables + arrayView1d< real64 const > const m_pressure; + arrayView2d< real64 const, compflow::USD_COMP > const m_compFrac; + + /// View on the scaling factors + arrayView1d< real64 > const m_pressureScalingFactor; + arrayView1d< real64 > const m_compFracScalingFactor; + +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGANDCHECKINGZFORMULATIONKERNELBASE_HPP diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingZFormulationKernel.hpp new file mode 100644 index 00000000000..a227ee8238b --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingZFormulationKernel.hpp @@ -0,0 +1,348 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 SolutionScalingZFormulationKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGZFORMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGZFORMULATIONKERNEL_HPP + +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingAndCheckingZFormulationKernelBase.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp" + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseBaseKernels +{ + +/******************************** SolutionScalingZFormulationKernel ********************************/ + +/** + * @class SolutionScalingZFormulationKernel + * @brief Define the kernel for scaling the Newton update + */ +class SolutionScalingZFormulationKernel : public SolutionScalingAndCheckingZFormulationKernelBase< real64 > +{ +public: + + using Base = SolutionScalingAndCheckingZFormulationKernelBase< real64 >; + using Base::m_rankOffset; + using Base::m_numComp; + using Base::m_dofNumber; + using Base::m_ghostRank; + using Base::m_localSolution; + using Base::m_pressure; + using Base::m_compFrac; + using Base::m_pressureScalingFactor; + using Base::m_compFracScalingFactor; + + /** + * @brief Create a new kernel instance + * @param[in] maxRelativePresChange the max allowed relative pressure change + * @param[in] maxAbsolutePresChange the max allowed absolute pressure change + * @param[in] maxCompFracChange the max allowed comp fraction change + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @param[in] pressure the pressure vector + * @param[in] compFrac the component density vector + * @param[in] pressureScalingFactor the pressure local scaling factor + * @param[in] compFracScalingFactor the component density local scaling factor + */ + SolutionScalingZFormulationKernel( real64 const maxRelativePresChange, + real64 const maxAbsolutePresChange, + real64 const maxCompFracChange, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase const & subRegion, + arrayView1d< real64 const > const localSolution, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compFrac, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compFracScalingFactor ) + : Base( rankOffset, + numComp, + dofKey, + subRegion, + localSolution, + pressure, + compFrac, + pressureScalingFactor, + compFracScalingFactor ), + m_maxRelativePresChange( maxRelativePresChange ), + m_maxAbsolutePresChange( maxAbsolutePresChange ), + m_maxCompFracChange( maxCompFracChange ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables located on the stack + */ + struct StackVariables : public Base::StackVariables + { + GEOS_HOST_DEVICE + StackVariables() + { } + + StackVariables( real64 _localMinVal, + real64 _localMaxDeltaPres, + real64 _localMaxDeltaTemp, + real64 _localMaxDeltaCompFrac, + real64 _localMinPresScalingFactor, + real64 _localMinTempScalingFactor, + real64 _localMinCompFracScalingFactor ) + : + Base::StackVariables( _localMinVal ), + localMaxDeltaPres( _localMaxDeltaPres ), + localMaxDeltaTemp( _localMaxDeltaTemp ), + localMaxDeltaCompFrac( _localMaxDeltaCompFrac ), + localMinPresScalingFactor( _localMinPresScalingFactor ), + localMinTempScalingFactor( _localMinTempScalingFactor ), + localMinCompFracScalingFactor( _localMinCompFracScalingFactor ) + { } + + real64 localMaxDeltaPres; + real64 localMaxDeltaTemp; + real64 localMaxDeltaCompFrac; + + real64 localMinPresScalingFactor; + real64 localMinTempScalingFactor; + real64 localMinCompFracScalingFactor; + + }; + + /** + * @brief Performs the kernel launch + * @tparam POLICY the policy used in the RAJA kernels + * @tparam KERNEL_TYPE the kernel type + * @param[in] numElems the number of elements + * @param[inout] kernelComponent the kernel component providing access to the compute function + */ + template< typename POLICY, typename KERNEL_TYPE > + static StackVariables + launch( localIndex const numElems, + KERNEL_TYPE const & kernelComponent ) + { + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > globalScalingFactor( 1.0 ); + + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 ); + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaTemp( 0.0 ); + RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaCompFrac( 0.0 ); + + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minPresScalingFactor( 1.0 ); + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minTempScalingFactor( 1.0 ); + RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > minCompFracScalingFactor( 1.0 ); + + forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( kernelComponent.ghostRank( ei ) >= 0 ) + { + return; + } + + StackVariables stack; + kernelComponent.setup( ei, stack ); + kernelComponent.compute( ei, stack ); + + globalScalingFactor.min( stack.localMinVal ); + + maxDeltaPres.max( stack.localMaxDeltaPres ); + maxDeltaTemp.max( stack.localMaxDeltaTemp ); + maxDeltaCompFrac.max( stack.localMaxDeltaCompFrac ); + + minPresScalingFactor.min( stack.localMinPresScalingFactor ); + minTempScalingFactor.min( stack.localMinTempScalingFactor ); + minCompFracScalingFactor.min( stack.localMinCompFracScalingFactor ); + } ); + + return StackVariables( globalScalingFactor.get(), + maxDeltaPres.get(), + maxDeltaTemp.get(), + maxDeltaCompFrac.get(), + minPresScalingFactor.get(), + minTempScalingFactor.get(), + minCompFracScalingFactor.get() ); + } + + GEOS_HOST_DEVICE + void setup( localIndex const ei, + StackVariables & stack ) const + { + Base::setup( ei, stack ); + + stack.localMaxDeltaPres = 0.0; + stack.localMaxDeltaTemp = 0.0; + stack.localMaxDeltaCompFrac = 0.0; + + stack.localMinPresScalingFactor = 1.0; + stack.localMinTempScalingFactor = 1.0; + stack.localMinCompFracScalingFactor = 1.0; + } + + /** + * @brief Compute the local value + * @param[in] ei the element index + * @param[inout] stack the stack variables + */ + GEOS_HOST_DEVICE + void compute( localIndex const ei, + StackVariables & stack ) const + { + computeScalingFactor( ei, stack ); + } + + /** + * @brief Compute the local value of the scaling factor + * @tparam FUNC the type of the function that can be used to customize the kernel + * @param[in] ei the element index + * @param[inout] stack the stack variables + * @param[in] kernelOp the function used to customize the kernel + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeScalingFactor( localIndex const ei, + StackVariables & stack, + FUNC && kernelOp = NoOpFunc{} ) const + { + real64 constexpr eps = minDensForDivision; + + // compute the change in pressure + real64 const pres = m_pressure[ei]; + real64 const absPresChange = LvArray::math::abs( m_localSolution[stack.localRow] ); + if( stack.localMaxDeltaPres < absPresChange ) + { + stack.localMaxDeltaPres = absPresChange; + } + + // compute pressure scaling factor + real64 presScalingFactor = 1.0; + // when enabled, absolute change scaling has a priority over relative change + if( m_maxAbsolutePresChange > 0.0 ) // maxAbsolutePresChange <= 0.0 means that absolute scaling is disabled + { + if( absPresChange > m_maxAbsolutePresChange ) + { + presScalingFactor = m_maxAbsolutePresChange / absPresChange; + } + } + else if( pres > eps ) + { + real64 const relativePresChange = absPresChange / pres; + if( relativePresChange > m_maxRelativePresChange ) + { + presScalingFactor = m_maxRelativePresChange / relativePresChange; + } + } + m_pressureScalingFactor[ei] = presScalingFactor; + if( stack.localMinVal > presScalingFactor ) + { + stack.localMinVal = presScalingFactor; + } + if( stack.localMinPresScalingFactor > presScalingFactor ) + { + stack.localMinPresScalingFactor = presScalingFactor; + } + + // Component Fraction Change Scaling + m_compFracScalingFactor[ei] = 1.0; + + for( integer ic = 0; ic < m_numComp; ++ic ) + { + // compute scaling factor based on relative change in component densities + real64 const absCompFracChange = LvArray::math::abs( m_localSolution[stack.localRow + ic + 1] ); + if( stack.localMaxDeltaCompFrac < absCompFracChange ) + { + stack.localMaxDeltaCompFrac = absCompFracChange; + } + + if( absCompFracChange > m_maxCompFracChange && absCompFracChange > eps ) + { + real64 const compScalingFactor = m_maxCompFracChange / absCompFracChange; + m_compFracScalingFactor[ei] = LvArray::math::min( m_compFracScalingFactor[ei], compScalingFactor ); + if( stack.localMinVal > compScalingFactor ) + { + stack.localMinVal = compScalingFactor; + } + if( stack.localMinCompFracScalingFactor > compScalingFactor ) + { + stack.localMinCompFracScalingFactor = compScalingFactor; + } + } + } + + // compute the scaling factor for other vars, such as temperature + kernelOp(); + } + +protected: + + /// Max allowed changes in primary variables + real64 const m_maxRelativePresChange; + real64 const m_maxAbsolutePresChange; + real64 const m_maxCompFracChange; + +}; + +/** + * @class SolutionScalingZFormulationKernelFactory + */ +class SolutionScalingZFormulationKernelFactory +{ +public: + + /* + * @brief Create and launch the kernel computing the scaling factor + * @tparam POLICY the kernel policy + * @param[in] maxRelativePresChange the max allowed relative pressure change + * @param[in] maxAbsolutePresChange the max allowed absolute pressure change + * @param[in] maxCompFracChange the max allowed comp fraction change + * @param[in] rankOffset the rank offset + * @param[in] numComp the number of components + * @param[in] dofKey the dof key to get dof numbers + * @param[in] subRegion the subRegion + * @param[in] localSolution the Newton update + * @return the scaling factor + */ + template< typename POLICY > + static SolutionScalingZFormulationKernel::StackVariables + createAndLaunch( real64 const maxRelativePresChange, + real64 const maxAbsolutePresChange, + real64 const maxCompFracChange, + arrayView1d< real64 const > const pressure, + arrayView2d< real64 const, compflow::USD_COMP > const compFrac, + arrayView1d< real64 > pressureScalingFactor, + arrayView1d< real64 > compFracScalingFactor, + globalIndex const rankOffset, + integer const numComp, + string const dofKey, + ElementSubRegionBase & subRegion, + arrayView1d< real64 const > const localSolution ) + { + SolutionScalingZFormulationKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, rankOffset, + numComp, dofKey, subRegion, localSolution, pressure, compFrac, pressureScalingFactor, compFracScalingFactor ); + return SolutionScalingZFormulationKernel::launch< POLICY >( subRegion.size(), kernel ); + } +}; + +} // namespace isothermalCompositionalMultiphaseBaseKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGZFORMULATIONKERNEL_HPP From e6a4a99d7fe37a6a0f451216cb12ab1b2847845c Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Tue, 19 Nov 2024 12:15:24 -0600 Subject: [PATCH 39/47] Implemented missing functions, validated for 1D CO2 injection case --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 265 +++++++++++++----- .../fluidFlow/CompositionalMultiphaseBase.hpp | 4 + .../CompositionalMultiphaseBaseFields.hpp | 8 + .../fluidFlow/CompositionalMultiphaseFVM.cpp | 10 +- 4 files changed, 220 insertions(+), 67 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 18f98c0553d..11ef92084b1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -125,6 +125,11 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, setInputFlag( InputFlags::OPTIONAL ). setApplyDefaultValue( LvArray::NumericLimits< real64 >::max ). // disabled by default setDescription( "Target (relative) change in component density in a time step" ); + this->registerWrapper( viewKeyStruct::targetCompFracChangeString(), &m_targetCompFracChange ). + setSizedFromParent( 0 ). + setInputFlag( InputFlags::OPTIONAL ). + setApplyDefaultValue( LvArray::NumericLimits< real64 >::max ). // disabled by default + setDescription( "Target change in component fraction in a time step" ); this->registerWrapper( viewKeyStruct::maxCompFracChangeString(), &m_maxCompFracChange ). setSizedFromParent( 0 ). @@ -225,8 +230,11 @@ void CompositionalMultiphaseBase::postInputInitialization() getWrapperDataContext( viewKeyStruct::targetPhaseVolFracChangeString() ) << ": The target change in phase volume fraction in a time step must be larger than 0.0" ); GEOS_ERROR_IF_LE_MSG( m_targetRelativeCompDensChange, 0.0, - getWrapperDataContext( viewKeyStruct::targetPhaseVolFracChangeString() ) << + getWrapperDataContext( viewKeyStruct::targetRelativeCompDensChangeString() ) << ": The target change in component density in a time step must be larger than 0.0" ); + GEOS_ERROR_IF_LE_MSG( m_targetCompFracChange, 0.0, + getWrapperDataContext( viewKeyStruct::targetCompFracChangeString() ) << + ": The target change in component fraction in a time step must be larger than 0.0" ); GEOS_ERROR_IF_LT_MSG( m_solutionChangeScalingFactor, 0.0, getWrapperDataContext( viewKeyStruct::solutionChangeScalingFactorString() ) << @@ -395,36 +403,7 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< globalCompFractionScalingFactor >( getName() ); // The resizing of the arrays needs to happen here, before the call to initializePreSubGroups, - // to make sure that the dimensions are properly set before the timeHistoryOutput starts its initialization. -/* - subRegion.registerField< globalCompFraction >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); - subRegion.registerField< globalCompFraction_n >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< globalCompFraction_k >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); - } - subRegion.registerField< globalCompDensity >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); - subRegion.registerField< globalCompDensity_n >( getName() ). - reference().resizeDimension< 1 >( m_numComponents ); - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< globalCompDensity_k >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); - } - subRegion.registerField< dGlobalCompFraction_dGlobalCompDensity >( getName() ). - reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); - */ - - + // to make sure that the dimensions are properly set before the timeHistoryOutput starts its initialization. if (m_useZFormulation) { subRegion.registerField< globalCompFraction >( getName() ). @@ -459,7 +438,10 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< dGlobalCompFraction_dGlobalCompDensity >( getName() ). reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); } - + // for Dirichlet boundary condition + subRegion.registerField< fields::flow::bcglobalCompFraction >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); subRegion.registerField< phaseVolumeFraction >( getName() ). setDimLabels( 1, fluid.phaseNames() ). @@ -2142,41 +2124,77 @@ void CompositionalMultiphaseBase::applyDirichletBC( real64 const time_n, subRegion.getReference< array1d< real64 > >( fields::flow::pressure::key() ); // for now to avoid lambda function complain - arrayView2d< real64 const, compflow::USD_COMP > compDens = - subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompFraction::key() ); - arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); - if (!m_useZFormulation) - { - compDens = subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompDensity::key() ); - } - - integer const numComp = m_numComponents; - forAll< parallelDevicePolicy<> >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) + if (m_useZFormulation) { - localIndex const ei = targetSet[a]; - if( ghostRank[ei] >= 0 ) + //arrayView2d< real64 const, compflow::USD_COMP > const compFrac = + //subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompFraction::key() ); + + integer const numComp = m_numComponents; + forAll< parallelDevicePolicy<> >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) { - return; - } + localIndex const ei = targetSet[a]; + if( ghostRank[ei] >= 0 ) + { + return; + } - globalIndex const dofIndex = dofNumber[ei]; - localIndex const localRow = dofIndex - rankOffset; - real64 rhsValue; + globalIndex const dofIndex = dofNumber[ei]; + localIndex const localRow = dofIndex - rankOffset; + real64 rhsValue; - // 4.1. Apply pressure value to the matrix/rhs - FieldSpecificationEqual::SpecifyFieldValue( dofIndex, - rankOffset, - localMatrix, - rhsValue, - bcPres[ei], - pres[ei] ); - localRhs[localRow] = rhsValue; + // 4.1. Apply pressure value to the matrix/rhs + FieldSpecificationEqual::SpecifyFieldValue( dofIndex, + rankOffset, + localMatrix, + rhsValue, + bcPres[ei], + pres[ei] ); + localRhs[localRow] = rhsValue; - if (!m_useZFormulation) - { // 4.2. For each component, apply target global density value for( integer ic = 0; ic < numComp; ++ic ) + { + FieldSpecificationEqual::SpecifyFieldValue( dofIndex + ic + 1, + rankOffset, + localMatrix, + rhsValue, + compFrac[ei][ic], + compFrac[ei][ic] ); + localRhs[localRow + ic + 1] = rhsValue; + } + } ); + } + else + { + arrayView2d< real64 const, compflow::USD_COMP > const compDens = + subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompDensity::key() ); + arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); + + integer const numComp = m_numComponents; + forAll< parallelDevicePolicy<> >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) + { + localIndex const ei = targetSet[a]; + if( ghostRank[ei] >= 0 ) + { + return; + } + + globalIndex const dofIndex = dofNumber[ei]; + localIndex const localRow = dofIndex - rankOffset; + real64 rhsValue; + + // 4.1. Apply pressure value to the matrix/rhs + FieldSpecificationEqual::SpecifyFieldValue( dofIndex, + rankOffset, + localMatrix, + rhsValue, + bcPres[ei], + pres[ei] ); + localRhs[localRow] = rhsValue; + + // 4.2. For each component, apply target global component fraction value + for( integer ic = 0; ic < numComp; ++ic ) { FieldSpecificationEqual::SpecifyFieldValue( dofIndex + ic + 1, rankOffset, @@ -2186,9 +2204,10 @@ void CompositionalMultiphaseBase::applyDirichletBC( real64 const time_n, compDens[ei][ic] ); localRhs[localRow + ic + 1] = rhsValue; } - } - } ); + } ); + } } ); + // 5. Apply temperature to the system if( m_isThermal ) @@ -2398,11 +2417,129 @@ void CompositionalMultiphaseBase::chopNegativeCompFractions( DomainPartition & d real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & currentDt, DomainPartition & domain ) { - // TODO: implement Dt estimation based on compFrac change - + // TODO: put in a seprate function or put flags to avoid duplication of code if (m_useZFormulation) { - return LvArray::NumericLimits< real64 >::max; + if( m_targetRelativePresChange >= 1.0 && + m_targetPhaseVolFracChange >= 1.0 && + m_targetCompFracChange >= 1.0 && + ( !m_isThermal || m_targetRelativeTempChange >= 1.0 ) ) + { + return LvArray::NumericLimits< real64 >::max; + } + + real64 maxRelativePresChange = 0.0; + real64 maxRelativeTempChange = 0.0; + real64 maxAbsolutePhaseVolFracChange = 0.0; + real64 maxCompFracChange = 0.0; + + integer const numPhase = m_numPhases; + integer const numComp = m_numComponents; + + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) + { + mesh.getElemManager().forElementSubRegions( regionNames, + [&]( localIndex const, + ElementSubRegionBase & subRegion ) + { + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const pres_n = subRegion.getField< fields::flow::pressure_n >(); + arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); + arrayView1d< real64 const > const temp_n = subRegion.getField< fields::flow::temperature_n >(); + arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = + subRegion.getField< fields::flow::phaseVolumeFraction >(); + arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac_n = + subRegion.getField< fields::flow::phaseVolumeFraction_n >(); + arrayView2d< real64 const, compflow::USD_COMP > const compFrac = + subRegion.getField< fields::flow::globalCompFraction >(); + arrayView2d< real64, compflow::USD_COMP > const compFrac_n = + subRegion.getField< fields::flow::globalCompFraction_n >(); + + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPresChange( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTempChange( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPhaseVolFracChange( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxCompFracChange( 0.0 ); + + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( ghostRank[ei] < 0 ) + { + // switch from relative to absolute when values less than 1 + subRegionMaxPresChange.max( LvArray::math::abs( pres[ei] - pres_n[ei] ) / LvArray::math::max( LvArray::math::abs( pres_n[ei] ), 1.0 ) ); + subRegionMaxTempChange.max( LvArray::math::abs( temp[ei] - temp_n[ei] ) / LvArray::math::max( LvArray::math::abs( temp_n[ei] ), 1.0 ) ); + for( integer ip = 0; ip < numPhase; ++ip ) + { + subRegionMaxPhaseVolFracChange.max( LvArray::math::abs( phaseVolFrac[ei][ip] - phaseVolFrac_n[ei][ip] ) ); + } + for( integer ic = 0; ic < numComp; ++ic ) + { + subRegionMaxCompFracChange.max( LvArray::math::abs( compFrac[ei][ic] - compFrac_n[ei][ic] ) ); + } + } + } ); + + maxRelativePresChange = LvArray::math::max( maxRelativePresChange, subRegionMaxPresChange.get() ); + maxRelativeTempChange = LvArray::math::max( maxRelativeTempChange, subRegionMaxTempChange.get() ); + maxAbsolutePhaseVolFracChange = LvArray::math::max( maxAbsolutePhaseVolFracChange, subRegionMaxPhaseVolFracChange.get() ); + maxCompFracChange = LvArray::math::max( maxCompFracChange, subRegionMaxCompFracChange.get() ); + + } ); + } ); + + maxRelativePresChange = MpiWrapper::max( maxRelativePresChange ); + maxAbsolutePhaseVolFracChange = MpiWrapper::max( maxAbsolutePhaseVolFracChange ); + + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative pressure change during time step = {} %", + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativePresChange, 3 ) ) ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max absolute phase volume fraction change during time step = {}", + getName(), GEOS_FMT( "{:.{}f}", maxAbsolutePhaseVolFracChange, 3 ) ) ); + + if( m_targetCompFracChange < LvArray::NumericLimits< real64 >::max ) + { + maxCompFracChange = MpiWrapper::max( maxCompFracChange ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max component fraction change during time step = {} %", + getName(), GEOS_FMT( "{:.{}f}", 100*maxCompFracChange, 3 ) ) ); + } + + if( m_isThermal ) + { + maxRelativeTempChange = MpiWrapper::max( maxRelativeTempChange ); + GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative temperature change during time step = {} %", + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeTempChange, 3 ) ) ); + } + + real64 const eps = LvArray::NumericLimits< real64 >::epsilon; + + real64 const nextDtPressure = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativePresChange + / std::max( eps, maxRelativePresChange + m_solutionChangeScalingFactor * m_targetRelativePresChange ); + if( m_nonlinearSolverParameters.getLogLevel() > 0 ) + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on pressure change = {}", getName(), nextDtPressure )); + real64 const nextDtPhaseVolFrac = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetPhaseVolFracChange + / std::max( eps, maxAbsolutePhaseVolFracChange + m_solutionChangeScalingFactor * m_targetPhaseVolFracChange ); + if( m_nonlinearSolverParameters.getLogLevel() > 0 ) + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on phase volume fraction change = {}", getName(), nextDtPhaseVolFrac )); + real64 nextDtCompFrac = LvArray::NumericLimits< real64 >::max; + if( m_targetCompFracChange < LvArray::NumericLimits< real64 >::max ) + { + nextDtCompFrac = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetCompFracChange + / std::max( eps, maxCompFracChange + m_solutionChangeScalingFactor * m_targetCompFracChange ); + if( m_nonlinearSolverParameters.getLogLevel() > 0 ) + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on component fraction change = {}", getName(), nextDtCompFrac )); + } + real64 nextDtTemperature = LvArray::NumericLimits< real64 >::max; + if( m_isThermal ) + { + nextDtTemperature = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativeTempChange + / std::max( eps, maxRelativeTempChange + m_solutionChangeScalingFactor * m_targetRelativeTempChange ); + if( m_nonlinearSolverParameters.getLogLevel() > 0 ) + GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on temperature change = {}", getName(), nextDtPhaseVolFrac )); + } + + return std::min( std::min( nextDtPressure, std::min( nextDtPhaseVolFrac, nextDtCompFrac ) ), nextDtTemperature ); } else { diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index 1f5f9f1be14..81fe5541dab 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -300,6 +300,7 @@ class CompositionalMultiphaseBase : public FlowSolverBase static constexpr char const * targetRelativeTempChangeString() { return "targetRelativeTemperatureChangeInTimeStep"; } static constexpr char const * targetPhaseVolFracChangeString() { return "targetPhaseVolFractionChangeInTimeStep"; } static constexpr char const * targetRelativeCompDensChangeString() { return "targetRelativeCompDensChangeInTimeStep"; } + static constexpr char const * targetCompFracChangeString() { return "targetCompFracChangeInTimeStep"; } static constexpr char const * targetFlowCFLString() { return "targetFlowCFL"; } @@ -524,6 +525,9 @@ class CompositionalMultiphaseBase : public FlowSolverBase /// target (relative) change in component density in a time step real64 m_targetRelativeCompDensChange; + /// target (absolute) change in component fraction in a time step + real64 m_targetCompFracChange; + /// minimum value of the scaling factor obtained by enforcing maxCompFracChange real64 m_minScalingFactor; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp index 019cea65b6d..96c1b5090af 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp @@ -88,6 +88,14 @@ DECLARE_FIELD( globalCompFraction_k, NO_WRITE, "Global component fraction updates at the previous sequential iteration" ); +DECLARE_FIELD( bcglobalCompFraction, + "bcglobalCompFraction", + array2dLayoutComp, + 0, + NOPLOT, + WRITE_AND_READ, + "Dirichlet boundary condition composition" ); + DECLARE_FIELD( faceGlobalCompFraction, "faceGlobalCompFraction", array2dLayoutComp, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 7e1f861e274..87304f613ce 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -882,7 +882,7 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana dofManager.addVectorToField( localSolution, viewKeyStruct::elemDofFieldString(), fields::flow::globalCompFraction::key(), - fields::flow::globalCompDensityScalingFactor::key(), + fields::flow::globalCompFractionScalingFactor::key(), componentMask ); } else @@ -939,9 +939,13 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana // these negative component densities are set to zero in this function // TODO: implement chopNegativeZ - if( m_allowCompDensChopping && !m_useZFormulation) + + if( m_allowCompDensChopping) { - chopNegativeDensities( domain ); + if (m_useZFormulation) + chopNegativeCompFractions( domain ); + else + chopNegativeDensities( domain ); } forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, From ee910437bd037509ed65cfc6169e45c272243d51 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Thu, 21 Nov 2024 10:17:46 -0600 Subject: [PATCH 40/47] Added DirichletFluxCompute for Z formulation --- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 87 ++- ...DirichletFluxComputeZFormulationKernel.hpp | 544 ++++++++++++++++++ 2 files changed, 600 insertions(+), 31 deletions(-) create mode 100644 src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/DirichletFluxComputeZFormulationKernel.hpp diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 87304f613ce..7fc32e86f7f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -59,6 +59,7 @@ #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp" #include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/SolutionScalingZFormulationKernel.hpp" +#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/DirichletFluxComputeZFormulationKernel.hpp" namespace geos { @@ -1243,42 +1244,66 @@ void CompositionalMultiphaseFVM::applyFaceDirichletBC( real64 const time_n, string const & elemDofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); - if( m_isThermal ) + if( m_useZFormulation ) { - //todo (jafranc) extend upwindScheme name if satisfied in isothermalCase - thermalCompositionalMultiphaseFVMKernels:: - DirichletFluxComputeKernelFactory:: + GEOS_ERROR_IF( m_isThermal, GEOS_FMT( + "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + isothermalCompositionalMultiphaseFVMKernels:: + DirichletFluxComputeZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - elemDofKey, - getName(), - faceManager, - elemManager, - stencilWrapper, - multiFluidBase, - dt, - localMatrix, - localRhs ); + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + elemDofKey, + getName(), + faceManager, + elemManager, + stencilWrapper, + multiFluidBase, + dt, + localMatrix, + localRhs ); + } else { - isothermalCompositionalMultiphaseFVMKernels:: - DirichletFluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - elemDofKey, - getName(), - faceManager, - elemManager, - stencilWrapper, - multiFluidBase, - dt, - localMatrix, - localRhs ); + if( m_isThermal ) + { + //todo (jafranc) extend upwindScheme name if satisfied in isothermalCase + thermalCompositionalMultiphaseFVMKernels:: + DirichletFluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + elemDofKey, + getName(), + faceManager, + elemManager, + stencilWrapper, + multiFluidBase, + dt, + localMatrix, + localRhs ); + } + else + { + isothermalCompositionalMultiphaseFVMKernels:: + DirichletFluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + elemDofKey, + getName(), + faceManager, + elemManager, + stencilWrapper, + multiFluidBase, + dt, + localMatrix, + localRhs ); + } } } ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/DirichletFluxComputeZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/DirichletFluxComputeZFormulationKernel.hpp new file mode 100644 index 00000000000..9e62724533c --- /dev/null +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/DirichletFluxComputeZFormulationKernel.hpp @@ -0,0 +1,544 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2024 Total, S.A + * 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 DirichletFluxComputeZFormulationKernel.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEZFORMULATIONKERNEL_HPP +#define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEZFORMULATIONKERNEL_HPP + +#include "codingUtilities/Utilities.hpp" +#include "common/DataLayouts.hpp" +#include "common/DataTypes.hpp" +#include "common/GEOS_RAJA_Interface.hpp" +#include "constitutive/fluid/multifluid/MultiFluidBase.hpp" +#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp" +#include "finiteVolume/BoundaryStencil.hpp" +#include "mesh/ElementRegionManager.hpp" +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp" +#include "physicsSolvers/fluidFlow/CompositionalMultiphaseUtilities.hpp" +#include "physicsSolvers/fluidFlow/StencilAccessors.hpp" + + +namespace geos +{ + +namespace isothermalCompositionalMultiphaseFVMKernels +{ + +/******************************** DirichletFluxComputeZFormulationKernel ********************************/ + +/** + * @class DirichletFluxComputeZFormulationKernel + * @tparam NUM_COMP number of fluid components + * @tparam NUM_DOF number of degrees of freedom + * @tparam FLUIDWRAPPER the type of the fluid wrapper + * @brief Define the interface for the assembly kernel in charge of Dirichlet face flux terms + */ +template< integer NUM_COMP, integer NUM_DOF, typename FLUIDWRAPPER > +class DirichletFluxComputeZFormulationKernel : public FluxComputeKernel< NUM_COMP, + NUM_DOF, + BoundaryStencilWrapper > +{ +public: + + /** + * @brief The type for element-based data. Consists entirely of ArrayView's. + * + * Can be converted from ElementRegionManager::ElementViewConstAccessor + * by calling .toView() or .toViewConst() on an accessor instance + */ + template< typename VIEWTYPE > + using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >; + + using AbstractBase = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernelBase; + using DofNumberAccessor = AbstractBase::DofNumberAccessor; + using CompFlowAccessors = AbstractBase::CompFlowAccessors; + using MultiFluidAccessors = AbstractBase::MultiFluidAccessors; + using CapPressureAccessors = AbstractBase::CapPressureAccessors; + using PermeabilityAccessors = AbstractBase::PermeabilityAccessors; + + using AbstractBase::m_dt; + using AbstractBase::m_numPhases; + using AbstractBase::m_rankOffset; + using AbstractBase::m_dofNumber; + using AbstractBase::m_ghostRank; + using AbstractBase::m_gravCoef; + using AbstractBase::m_pres; + using AbstractBase::m_phaseCompFrac; + using AbstractBase::m_dPhaseCompFrac; + using AbstractBase::m_localMatrix; + using AbstractBase::m_localRhs; + using AbstractBase::m_kernelFlags; + + using Base = isothermalCompositionalMultiphaseFVMKernels::FluxComputeKernel< NUM_COMP, NUM_DOF, BoundaryStencilWrapper >; + using Base::numComp; + using Base::numDof; + using Base::numEqn; + using Base::m_stencilWrapper; + using Base::m_phaseMob; + using Base::m_dPhaseMob; + using Base::m_phaseMassDens; + using Base::m_dPhaseMassDens; + using Base::m_permeability; + using Base::m_dPerm_dPres; + using Base::m_seri; + using Base::m_sesri; + using Base::m_sei; + + /** + * @brief Constructor for the kernel interface + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] faceManager the face manager + * @param[in] stencilWrapper reference to the stencil wrapper + * @param[in] fluidWrapper reference to the fluid wrapper + * @param[in] dofNumberAccessor + * @param[in] compFlowAccessors + * @param[in] multiFluidAccessors + * @param[in] capPressureAccessors + * @param[in] permeabilityAccessors + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + * @param[in] kernelFlags flags packed together + */ + DirichletFluxComputeZFormulationKernel( integer const numPhases, + globalIndex const rankOffset, + FaceManager const & faceManager, + BoundaryStencilWrapper const & stencilWrapper, + FLUIDWRAPPER const & fluidWrapper, + DofNumberAccessor const & dofNumberAccessor, + CompFlowAccessors const & compFlowAccessors, + MultiFluidAccessors const & multiFluidAccessors, + CapPressureAccessors const & capPressureAccessors, + PermeabilityAccessors const & permeabilityAccessors, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs, + BitFlags< KernelFlags > kernelFlags ) + : Base( numPhases, + rankOffset, + stencilWrapper, + dofNumberAccessor, + compFlowAccessors, + multiFluidAccessors, + capPressureAccessors, + permeabilityAccessors, + dt, + localMatrix, + localRhs, + kernelFlags ), + m_facePres( faceManager.getField< fields::flow::facePressure >() ), + m_faceTemp( faceManager.getField< fields::flow::faceTemperature >() ), + m_faceCompFrac( faceManager.getField< fields::flow::faceGlobalCompFraction >() ), + m_faceGravCoef( faceManager.getField< fields::flow::gravityCoefficient >() ), + m_fluidWrapper( fluidWrapper ) + {} + + /** + * @struct StackVariables + * @brief Kernel variables (dof numbers, jacobian and residual) located on the stack + */ + struct StackVariables + { +public: + + /** + * @brief Constructor for the stack variables + * @param[in] size size of the stencil for this connection + * @param[in] numElems number of elements for this connection + */ + GEOS_HOST_DEVICE + StackVariables( localIndex const GEOS_UNUSED_PARAM( size ), + localIndex GEOS_UNUSED_PARAM( numElems )) {} + + // Transmissibility + real64 transmissibility = 0.0; + + // Component fluxes and derivatives + + /// Component fluxes + real64 compFlux[numComp]{}; + /// Derivatives of component fluxes wrt pressure + real64 dCompFlux_dP[numComp]{}; + /// Derivatives of component fluxes wrt component densities + real64 dCompFlux_dC[numComp][numComp]{}; + + // Local degrees of freedom and local residual/jacobian + + /// Indices of the matrix rows/columns corresponding to the dofs in this face + globalIndex dofColIndices[numDof]{}; + + /// Storage for the face local residual vector + real64 localFlux[numEqn]{}; + /// Storage for the face local Jacobian matrix + real64 localFluxJacobian[numEqn][numDof]{}; + + }; + + + /** + * @brief Performs the setup phase for the kernel. + * @param[in] iconn the connection index + * @param[in] stack the stack variables + */ + GEOS_HOST_DEVICE + void setup( localIndex const iconn, + StackVariables & stack ) const + { + globalIndex const offset = + m_dofNumber[m_seri( iconn, BoundaryStencil::Order::ELEM )][m_sesri( iconn, BoundaryStencil::Order::ELEM )][m_sei( iconn, BoundaryStencil::Order::ELEM )]; + + for( integer jdof = 0; jdof < numDof; ++jdof ) + { + stack.dofColIndices[jdof] = offset + jdof; + } + } + + + /** + * @brief Compute the local Dirichlet face flux contributions to the residual and Jacobian + * @tparam FUNC the type of the function that can be used to customize the computation of the phase fluxes + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + * @param[in] compFluxKernelOp the function used to customize the computation of the component fluxes + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void computeFlux( localIndex const iconn, + StackVariables & stack, + FUNC && compFluxKernelOp = NoOpFunc{} ) const + { + using Deriv = constitutive::multifluid::DerivativeOffset; + using Order = BoundaryStencil::Order; + + localIndex const er = m_seri( iconn, Order::ELEM ); + localIndex const esr = m_sesri( iconn, Order::ELEM ); + localIndex const ei = m_sei( iconn, Order::ELEM ); + localIndex const kf = m_sei( iconn, Order::FACE ); + + // Step 1: compute the transmissibility at the boundary face + + real64 dTrans_dPerm[3]{}; + m_stencilWrapper.computeWeights( iconn, + m_permeability, + stack.transmissibility, + dTrans_dPerm ); + real64 const dTrans_dPres = LvArray::tensorOps::AiBi< 3 >( dTrans_dPerm, m_dPerm_dPres[er][esr][ei][0] ); + + // Step 2: compute the fluid properties on the face + // This is needed to get the phase mass density and the phase comp fraction at the face + // Because we approximate the face mobility using the total element mobility + + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseFrac( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseDens( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseMassDens( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseVisc( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseEnthalpy( 1, 1, m_numPhases ); + StackArray< real64, 3, constitutive::MultiFluidBase::MAX_NUM_PHASES, constitutive::multifluid::LAYOUT_PHASE > facePhaseInternalEnergy( 1, 1, m_numPhases ); + StackArray< real64, 4, constitutive::MultiFluidBase::MAX_NUM_PHASES * NUM_COMP, + constitutive::multifluid::LAYOUT_PHASE_COMP > facePhaseCompFrac( 1, 1, m_numPhases, NUM_COMP ); + real64 faceTotalDens = 0.0; + + constitutive::MultiFluidBase::KernelWrapper::computeValues( m_fluidWrapper, + m_facePres[kf], + m_faceTemp[kf], + m_faceCompFrac[kf], + facePhaseFrac[0][0], + facePhaseDens[0][0], + facePhaseMassDens[0][0], + facePhaseVisc[0][0], + facePhaseEnthalpy[0][0], + facePhaseInternalEnergy[0][0], + facePhaseCompFrac[0][0], + faceTotalDens ); + + // Step 3: loop over phases, compute and upwind phase flux and sum contributions to each component's flux + + for( integer ip = 0; ip < m_numPhases; ++ip ) + { + + // working variables + real64 dDensMean_dC[numComp]{}; + real64 dF_dC[numComp]{}; + + real64 phaseFlux = 0.0; // for the lambda + real64 dPhaseFlux_dP = 0.0; + real64 dPhaseFlux_dC[numComp]{}; + + + // Step 3.1: compute the average phase mass density at the face + // average density and derivatives + real64 const densMean = 0.5 * ( m_phaseMassDens[er][esr][ei][0][ip] + facePhaseMassDens[0][0][ip] ); + real64 const dDensMean_dP = 0.5 * m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDensMean_dC[jc] = 0.5 * m_dPhaseMassDens[er][esr][ei][0][ip][Deriv::dC+jc]; + } + + + // Step 3.2: compute the (TPFA) potential difference at the face + + real64 const gravTimesDz = m_gravCoef[er][esr][ei] - m_faceGravCoef[kf]; + real64 const potDif = m_pres[er][esr][ei] - m_facePres[kf] - densMean * gravTimesDz; + real64 const f = stack.transmissibility * potDif; + real64 const dF_dP = stack.transmissibility * ( 1.0 - dDensMean_dP * gravTimesDz ) + dTrans_dPres * potDif; + for( integer jc = 0; jc < numComp; ++jc ) + { + dF_dC[jc] = -stack.transmissibility * dDensMean_dC[jc] * gravTimesDz; + } + + // Step 3.3: computation of the mobility + // We do that before the if/else statement to be able to pass it to the compFluxOpKernel + + // recomputing the exact mobility at the face would be quite complex, as it would require: + // 1) computing the saturation + // 2) computing the relperm + // 3) computing the mobility as \lambda_p = \rho_p kr_p( S_p ) / \mu_p + // the second step in particular would require yet another dispatch to get the relperm model + // so, for simplicity, we approximate the face mobility as + // \lambda^approx_p = \rho_p S_p / \mu_p + // = \rho_p ( (nu_p / rho_p) * rho_t ) / \mu_p (plugging the expression of saturation) + // = \nu_p * rho_t / \mu_p + // fortunately, we don't need the derivatives + real64 const facePhaseMob = ( facePhaseFrac[0][0][ip] > 0.0 ) + ? facePhaseFrac[0][0][ip] * faceTotalDens / facePhaseVisc[0][0][ip] + : 0.0; + + // *** upwinding *** + // Step 3.4: upwinding based on the sign of the phase potential gradient + // It is easier to hard-code the if/else because it is difficult to address elem and face variables in a uniform way + + if( potDif >= 0 ) // the element is upstream + { + + // compute the phase flux and derivatives using the element mobility + phaseFlux = m_phaseMob[er][esr][ei][ip] * f; + dPhaseFlux_dP = m_phaseMob[er][esr][ei][ip] * dF_dP + m_dPhaseMob[er][esr][ei][ip][Deriv::dP] * f; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[jc] = + m_phaseMob[er][esr][ei][ip] * dF_dC[jc] + m_dPhaseMob[er][esr][ei][ip][Deriv::dC+jc] * f; + } + + // slice some constitutive arrays to avoid too much indexing in component loop + arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub = + m_phaseCompFrac[er][esr][ei][0][ip]; + arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub = + m_dPhaseCompFrac[er][esr][ei][0][ip]; + + // compute component fluxes and derivatives using element composition + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = phaseCompFracSub[ic]; + stack.compFlux[ic] += phaseFlux * ycp; + stack.dCompFlux_dP[ic] += dPhaseFlux_dP * ycp + phaseFlux * dPhaseCompFracSub[ic][Deriv::dP]; + + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.dCompFlux_dC[ic][jc] += dPhaseFlux_dC[jc] * ycp + phaseFlux * dPhaseCompFracSub[ic][Deriv::dC+jc]; + } + } + + } + else // the face is upstream + { + + // compute the phase flux and derivatives using the approximated face mobility + // we only have to take derivatives of the potential gradient in this case + phaseFlux = facePhaseMob * f; + dPhaseFlux_dP = facePhaseMob * dF_dP; + for( integer jc = 0; jc < numComp; ++jc ) + { + dPhaseFlux_dC[jc] = facePhaseMob * dF_dC[jc]; + } + + // compute component fluxes and derivatives using the face composition + for( integer ic = 0; ic < numComp; ++ic ) + { + real64 const ycp = facePhaseCompFrac[0][0][ip][ic]; + stack.compFlux[ic] += phaseFlux * ycp; + stack.dCompFlux_dP[ic] += dPhaseFlux_dP * ycp; + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.dCompFlux_dC[ic][jc] += dPhaseFlux_dC[jc] * ycp; + } + } + } + + // call the lambda in the phase loop to allow the reuse of the phase fluxes and their derivatives + // possible use: assemble the derivatives wrt temperature, and the flux term of the energy equation for this phase + compFluxKernelOp( ip, er, esr, ei, kf, f, + facePhaseMob, facePhaseEnthalpy[0][0], facePhaseCompFrac[0][0], + phaseFlux, dPhaseFlux_dP, dPhaseFlux_dC ); + + } + + // *** end of upwinding + + // Step 4: populate local flux vector and derivatives + for( integer ic = 0; ic < numComp; ++ic ) + { + stack.localFlux[ic] = m_dt * stack.compFlux[ic]; + stack.localFluxJacobian[ic][0] = m_dt * stack.dCompFlux_dP[ic]; + for( integer jc = 0; jc < numComp; ++jc ) + { + stack.localFluxJacobian[ic][jc+1] = m_dt * stack.dCompFlux_dC[ic][jc]; + } + } + } + + /** + * @brief Performs the complete phase for the kernel. + * @param[in] iconn the connection index + * @param[inout] stack the stack variables + */ + template< typename FUNC = NoOpFunc > + GEOS_HOST_DEVICE + void complete( localIndex const iconn, + StackVariables & stack, + FUNC && assemblyKernelOp = NoOpFunc{} ) const + { + using namespace compositionalMultiphaseUtilities; + using Order = BoundaryStencil::Order; + + if( AbstractBase::m_kernelFlags.isSet( KernelFlags::TotalMassEquation ) ) + { + // Apply equation/variable change transformation(s) + real64 work[numDof]{}; + shiftRowsAheadByOneAndReplaceFirstRowWithColumnSum( numComp, numDof, stack.localFluxJacobian, work ); + shiftElementsAheadByOneAndReplaceFirstElementWithSum( numComp, stack.localFlux ); + } + + // add contribution to residual and jacobian into: + // - the component mass balance equations (i = 0 to i = numComp-1) + // note that numDof includes derivatives wrt temperature if this class is derived in ThermalKernels + if( m_ghostRank[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )] < 0 ) + { + globalIndex const globalRow = m_dofNumber[m_seri( iconn, Order::ELEM )][m_sesri( iconn, Order::ELEM )][m_sei( iconn, Order::ELEM )]; + localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - m_rankOffset ); + GEOS_ASSERT_GE( localRow, 0 ); + GEOS_ASSERT_GT( AbstractBase::m_localMatrix.numRows(), localRow + numComp ); + + for( integer ic = 0; ic < numComp; ++ic ) + { + RAJA::atomicAdd( parallelDeviceAtomic{}, &AbstractBase::m_localRhs[localRow + ic], stack.localFlux[ic] ); + AbstractBase::m_localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic > + ( localRow + ic, + stack.dofColIndices, + stack.localFluxJacobian[ic], + numDof ); + } + + // call the lambda to assemble additional terms, such as thermal terms + assemblyKernelOp( localRow ); + } + } + +protected: + + /// Views on face pressure, temperature, and composition + arrayView1d< real64 const > const m_facePres; + arrayView1d< real64 const > const m_faceTemp; + arrayView2d< real64 const, compflow::USD_COMP > const m_faceCompFrac; + + /// View on the face gravity coefficient + arrayView1d< real64 const > const m_faceGravCoef; + + /// Reference to the fluid wrapper + FLUIDWRAPPER const m_fluidWrapper; + +}; + + +/** + * @class DirichletFluxComputeZFormulationKernelFactory + */ +class DirichletFluxComputeZFormulationKernelFactory +{ +public: + + /** + * @brief Create a new kernel and launch + * @tparam POLICY the policy used in the RAJA kernel + * @param[in] numComps the number of fluid components + * @param[in] numPhases the number of fluid phases + * @param[in] rankOffset the offset of my MPI rank + * @param[in] dofKey string to get the element degrees of freedom numbers + * @param[in] solverName name of the solver (to name accessors) + * @param[in] faceManager reference to the face manager + * @param[in] elemManager reference to the element region manager + * @param[in] stencilWrapper reference to the boundary stencil wrapper + * @param[in] fluidBase the multifluid constitutive model + * @param[in] dt time step size + * @param[inout] localMatrix the local CRS matrix + * @param[inout] localRhs the local right-hand side vector + */ + template< typename POLICY > + static void + createAndLaunch( integer const numComps, + integer const numPhases, + globalIndex const rankOffset, + integer const useTotalMassEquation, + string const & dofKey, + string const & solverName, + FaceManager const & faceManager, + ElementRegionManager const & elemManager, + BoundaryStencilWrapper const & stencilWrapper, + constitutive::MultiFluidBase & fluidBase, + real64 const dt, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) + { + constitutive::constitutiveComponentUpdatePassThru( fluidBase, numComps, [&]( auto & fluid, auto NC ) + { + using FluidType = TYPEOFREF( fluid ); + typename FluidType::KernelWrapper const fluidWrapper = fluid.createKernelWrapper(); + + integer constexpr NUM_COMP = NC(); + integer constexpr NUM_DOF = NC() + 1; + + ElementRegionManager::ElementViewAccessor< arrayView1d< globalIndex const > > dofNumberAccessor = + elemManager.constructArrayViewAccessor< globalIndex, 1 >( dofKey ); + dofNumberAccessor.setName( solverName + "/accessors/" + dofKey ); + + // for now, we neglect capillary pressure in the kernel + BitFlags< KernelFlags > kernelFlags; + if( useTotalMassEquation ) + kernelFlags.set( KernelFlags::TotalMassEquation ); + + using kernelType = DirichletFluxComputeZFormulationKernel< NUM_COMP, NUM_DOF, typename FluidType::KernelWrapper >; + typename kernelType::CompFlowAccessors compFlowAccessors( elemManager, solverName ); + typename kernelType::MultiFluidAccessors multiFluidAccessors( elemManager, solverName ); + typename kernelType::CapPressureAccessors capPressureAccessors( elemManager, solverName ); + typename kernelType::PermeabilityAccessors permeabilityAccessors( elemManager, solverName ); + + kernelType kernel( numPhases, rankOffset, faceManager, stencilWrapper, fluidWrapper, + dofNumberAccessor, compFlowAccessors, multiFluidAccessors, capPressureAccessors, permeabilityAccessors, + dt, localMatrix, localRhs, kernelFlags ); + kernelType::template launch< POLICY >( stencilWrapper.size(), kernel ); + } ); + } +}; + +} // namespace isothermalCompositionalMultiphaseFVMKernels + +} // namespace geos + + +#endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_DIRICHLETFLUXCOMPUTEZFORMULATIONKERNEL_HPP From 46b6a1eab2c990a2eaf75dc7282f62d6faaeb2e1 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Thu, 21 Nov 2024 13:39:08 -0600 Subject: [PATCH 41/47] fix: average density in potential gradient is computed depending on if the phase exists --- .../FluxComputeZFormulationKernel.hpp | 2 +- .../zFormulation/PPUPhaseFluxZFormulation.hpp | 3 ++- .../zFormulation/PotGradZFormulation.hpp | 27 ++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp index 6e616bb6886..0e8805e8d98 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp @@ -284,7 +284,7 @@ class FluxComputeZFormulationKernel : public FluxComputeKernelBase m_pres, m_gravCoef, m_phaseMob, m_dPhaseMob, - m_dPhaseVolFrac, + m_phaseVolFrac, m_dPhaseVolFrac, m_phaseCompFrac, m_dPhaseCompFrac, m_phaseMassDens, m_dPhaseMassDens, m_phaseCapPressure, m_dPhaseCapPressure_dPhaseVolFrac, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp index 9a203987795..d30d14406a5 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp @@ -83,6 +83,7 @@ struct PPUPhaseFluxZFormulation ElementViewConst< arrayView1d< real64 const > > const & gravCoef, ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseMob, ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseMob, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac, ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac, @@ -104,7 +105,7 @@ struct PPUPhaseFluxZFormulation real64 dGravHead_dP[numFluxSupportPoints]{}; real64 dGravHead_dC[numFluxSupportPoints][numComp]{}; PotGradZFormulation::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, seri, sesri, sei, trans, dTrans_dPres, pres, - gravCoef, dPhaseVolFrac, phaseMassDens, dPhaseMassDens, + gravCoef, phaseVolFrac, dPhaseVolFrac, phaseMassDens, dPhaseMassDens, phaseCapPressure, dPhaseCapPressure_dPhaseVolFrac, potGrad, dPresGrad_dP, dPresGrad_dC, dGravHead_dP, dGravHead_dC ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp index a4a55513156..6aa9be4d161 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp @@ -53,6 +53,7 @@ struct PotGradZFormulation real64 const ( &dTrans_dPres )[numFluxSupportPoints], ElementViewConst< arrayView1d< real64 const > > const & pres, ElementViewConst< arrayView1d< real64 const > > const & gravCoef, + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, ElementViewConst< arrayView3d< real64 const, compflow::USD_PHASE_DC > > const & dPhaseVolFrac, ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, @@ -86,22 +87,42 @@ struct PotGradZFormulation real64 dCapPressure_dC[numComp]{}; // calculate quantities on primary connected cells + integer denom = 0; for( integer i = 0; i < numFluxSupportPoints; ++i ) { localIndex const er = seri[i]; localIndex const esr = sesri[i]; localIndex const ei = sei[i]; + bool const phaseExists = (phaseVolFrac[er][esr][ei][ip] > 0); + if( !phaseExists ) + { + continue; + } + // density real64 const density = phaseMassDens[er][esr][ei][0][ip]; real64 const dDens_dP = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; // average density and derivatives - densMean += 0.5 * density; - dDensMean_dP[i] = 0.5 * dDens_dP; + densMean += density; + dDensMean_dP[i] = dDens_dP; for( integer jc = 0; jc < numComp; ++jc ) { - dDensMean_dC[i][jc] = 0.5 * dPhaseMassDens[er][esr][ei][0][ip][Deriv::dC+jc]; + dDensMean_dC[i][jc] = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dC+jc]; + } + denom++; + } + if( denom > 1 ) + { + densMean /= denom; + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + dDensMean_dP[i] /= denom; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDensMean_dC[i][jc] /= denom; + } } } From 979b121980f8093d7b875e45f324a67c03d1a9fe Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Wed, 18 Dec 2024 09:39:41 -0600 Subject: [PATCH 42/47] minor bugs fixes --- .../zFormulation/PhaseComponentFluxZFormulation.hpp | 1 - .../zFormulation/PhaseMobilityZFormulationKernel.hpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp index ed6c4b0adef..16afaae3b3f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseComponentFluxZFormulation.hpp @@ -50,7 +50,6 @@ struct PhaseComponentFluxZFormulation * @param sei arraySlice of the stencil-implied element index * @param phaseCompFrac phase component fraction * @param dPhaseCompFrac derivative of phase component fraction wrt pressure, temperature, component fraction - * @param dCompFrac_dCompDens derivative of component fraction wrt component density * @param phaseFlux phase flux * @param dPhaseFlux_dP derivative of phase flux wrt pressure * @param dPhaseFlux_dC derivative of phase flux wrt comp density diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp index 1ee73cc64c9..63f6f25d945 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseMobilityZFormulationKernel.hpp @@ -120,7 +120,7 @@ class PhaseMobilityZFormulationKernel : public isothermalCompositionalMultiphase real64 const viscosity = phaseVisc[ip]; real64 const dVisc_dP = dPhaseVisc[ip][Deriv::dP]; for( integer jc = 0; jc < numComp; ++jc ) - dDens_dC[jc] = dPhaseVisc[ip][Deriv::dC+jc]; + dVisc_dC[jc] = dPhaseVisc[ip][Deriv::dC+jc]; real64 const relPerm = phaseRelPerm[ip]; real64 dRelPerm_dP = 0.0; From e10ba38342e8d9e66ff17bbfbc028ba7c2e9ab38 Mon Sep 17 00:00:00 2001 From: Rasim Hasanzade Date: Wed, 18 Dec 2024 16:48:46 -0600 Subject: [PATCH 43/47] cosmetic changes --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 120 ++++---- .../CompositionalMultiphaseBaseFields.hpp | 12 +- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 264 +++++++++--------- .../fluidFlow/CompositionalMultiphaseFVM.hpp | 4 +- .../CompositionalMultiphaseHybridFVM.cpp | 4 +- .../AccumulationZFormulationKernel.hpp | 8 +- 6 files changed, 196 insertions(+), 216 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 11ef92084b1..f40c87c6320 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -129,7 +129,7 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, setSizedFromParent( 0 ). setInputFlag( InputFlags::OPTIONAL ). setApplyDefaultValue( LvArray::NumericLimits< real64 >::max ). // disabled by default - setDescription( "Target change in component fraction in a time step" ); + setDescription( "Target change in component fraction in a time step" ); this->registerWrapper( viewKeyStruct::maxCompFracChangeString(), &m_maxCompFracChange ). setSizedFromParent( 0 ). @@ -186,7 +186,7 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, setSizedFromParent( 0 ). setInputFlag( InputFlags::OPTIONAL ). setApplyDefaultValue( isothermalCompositionalMultiphaseBaseKernels::minCompFracForDivision ). - setDescription( "Minimum allowed global component fraction" ); + setDescription( "Minimum allowed global component fraction" ); this->registerWrapper( viewKeyStruct::maxSequentialCompDensChangeString(), &m_maxSequentialCompDensChange ). setSizedFromParent( 0 ). @@ -234,7 +234,7 @@ void CompositionalMultiphaseBase::postInputInitialization() ": The target change in component density in a time step must be larger than 0.0" ); GEOS_ERROR_IF_LE_MSG( m_targetCompFracChange, 0.0, getWrapperDataContext( viewKeyStruct::targetCompFracChangeString() ) << - ": The target change in component fraction in a time step must be larger than 0.0" ); + ": The target change in component fraction in a time step must be larger than 0.0" ); GEOS_ERROR_IF_LT_MSG( m_solutionChangeScalingFactor, 0.0, getWrapperDataContext( viewKeyStruct::solutionChangeScalingFactorString() ) << @@ -403,8 +403,8 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< globalCompFractionScalingFactor >( getName() ); // The resizing of the arrays needs to happen here, before the call to initializePreSubGroups, - // to make sure that the dimensions are properly set before the timeHistoryOutput starts its initialization. - if (m_useZFormulation) + // to make sure that the dimensions are properly set before the timeHistoryOutput starts its initialization. + if( m_useZFormulation ) { subRegion.registerField< globalCompFraction >( getName() ). setDimLabels( 1, fluid.componentNames() ). @@ -417,7 +417,7 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< globalCompFraction_k >( getName() ). setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); - } + } } else { @@ -436,12 +436,8 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); subRegion.registerField< dGlobalCompFraction_dGlobalCompDensity >( getName() ). - reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); + reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); } - // for Dirichlet boundary condition - subRegion.registerField< fields::flow::bcglobalCompFraction >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); subRegion.registerField< phaseVolumeFraction >( getName() ). setDimLabels( 1, fluid.phaseNames() ). @@ -730,7 +726,7 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFractionZFormulation( Objec MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( dataGroup, fluidName ); // For now: isothermal only - GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); real64 maxDeltaPhaseVolFrac = isothermalCompositionalMultiphaseBaseKernels:: @@ -918,17 +914,14 @@ real64 CompositionalMultiphaseBase::updateFluidState( ElementSubRegionBase & sub { GEOS_MARK_FUNCTION; - real64 maxdS; + real64 maxDeltaPhaseVolFrac; if( m_useZFormulation ) { // For p, z_c as the primary unknowns updateFluidModel( subRegion ); // rho_T is now a function of p, z_c from volume balance updateCompAmountZFormulation( subRegion ); - maxdS = updatePhaseVolumeFractionZFormulation( subRegion ); - updateRelPermModel( subRegion ); - updatePhaseMobility( subRegion ); - updateCapPressureModel( subRegion ); + maxDeltaPhaseVolFrac = updatePhaseVolumeFractionZFormulation( subRegion ); } else { @@ -936,16 +929,15 @@ real64 CompositionalMultiphaseBase::updateFluidState( ElementSubRegionBase & sub updateGlobalComponentFraction( subRegion ); updateFluidModel( subRegion ); updateCompAmount( subRegion ); - maxdS = updatePhaseVolumeFraction( subRegion ); - updateRelPermModel( subRegion ); - updatePhaseMobility( subRegion ); - updateCapPressureModel( subRegion ); - // note1: for now, thermal conductivity is treated explicitly, so no update here - // note2: for now, diffusion and dispersion are also treated explicitly - } + maxDeltaPhaseVolFrac = updatePhaseVolumeFraction( subRegion ); + } - real64 const maxDeltaPhaseVolFrac = maxdS; + updateRelPermModel( subRegion ); + updatePhaseMobility( subRegion ); + updateCapPressureModel( subRegion ); + // note1: for now, thermal conductivity is treated explicitly, so no update here + // note2: for now, diffusion and dispersion are also treated explicitly return maxDeltaPhaseVolFrac; } @@ -974,8 +966,8 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); - - if (!m_useZFormulation) + + if( !m_useZFormulation ) { arrayView2d< real64 const, compflow::USD_COMP > const compFrac = subRegion.getField< fields::flow::globalCompFraction >(); @@ -993,7 +985,7 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, } ); // with initial component densities defined - check if they need to be corrected to avoid zero diags etc - if (m_useZFormulation) + if( m_useZFormulation ) chopNegativeCompFractions( domain ); else chopNegativeDensities( domain ); @@ -1030,8 +1022,8 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, updateCompAmount( subRegion ); updatePhaseVolumeFraction( subRegion ); } - - + + // Now, we initialize and update each constitutive model one by one @@ -1417,19 +1409,19 @@ void CompositionalMultiphaseBase::initializePostInitialConditionsPreSubGroups() arrayView1d< string const > const & regionNames ) { FieldIdentifiers fieldsToBeSync; - if (m_useZFormulation) + if( m_useZFormulation ) { fieldsToBeSync.addElementFields( { fields::flow::pressure::key(), - fields::flow::globalCompFraction::key() }, - regionNames ); + fields::flow::globalCompFraction::key() }, + regionNames ); } else { fieldsToBeSync.addElementFields( { fields::flow::pressure::key(), - fields::flow::globalCompDensity::key() }, - regionNames ); + fields::flow::globalCompDensity::key() }, + regionNames ); } - + CommunicationTools::getInstance().synchronizeFields( fieldsToBeSync, mesh, domain.getNeighbors(), false ); @@ -2124,11 +2116,11 @@ void CompositionalMultiphaseBase::applyDirichletBC( real64 const time_n, subRegion.getReference< array1d< real64 > >( fields::flow::pressure::key() ); // for now to avoid lambda function complain - - if (m_useZFormulation) + + if( m_useZFormulation ) { //arrayView2d< real64 const, compflow::USD_COMP > const compFrac = - //subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompFraction::key() ); + //subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompFraction::key() ); integer const numComp = m_numComponents; forAll< parallelDevicePolicy<> >( targetSet.size(), [=] GEOS_HOST_DEVICE ( localIndex const a ) @@ -2165,7 +2157,7 @@ void CompositionalMultiphaseBase::applyDirichletBC( real64 const time_n, } } ); } - else + else { arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getReference< array2d< real64, compflow::LAYOUT_COMP > >( fields::flow::globalCompDensity::key() ); @@ -2207,7 +2199,7 @@ void CompositionalMultiphaseBase::applyDirichletBC( real64 const time_n, } ); } } ); - + // 5. Apply temperature to the system if( m_isThermal ) @@ -2340,8 +2332,6 @@ void CompositionalMultiphaseBase::chopNegativeDensities( DomainPartition & domai { GEOS_MARK_FUNCTION; - using namespace isothermalCompositionalMultiphaseBaseKernels; - integer const numComp = m_numComponents; real64 const minCompDens = m_minCompDens; @@ -2418,7 +2408,7 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & DomainPartition & domain ) { // TODO: put in a seprate function or put flags to avoid duplication of code - if (m_useZFormulation) + if( m_useZFormulation ) { if( m_targetRelativePresChange >= 1.0 && m_targetPhaseVolFracChange >= 1.0 && @@ -2437,12 +2427,12 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & integer const numComp = m_numComponents; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel & mesh, - arrayView1d< string const > const & regionNames ) + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) { mesh.getElemManager().forElementSubRegions( regionNames, [&]( localIndex const, - ElementSubRegionBase & subRegion ) + ElementSubRegionBase & subRegion ) { arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); @@ -2494,22 +2484,22 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & maxAbsolutePhaseVolFracChange = MpiWrapper::max( maxAbsolutePhaseVolFracChange ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative pressure change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativePresChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativePresChange, 3 ) ) ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max absolute phase volume fraction change during time step = {}", - getName(), GEOS_FMT( "{:.{}f}", maxAbsolutePhaseVolFracChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", maxAbsolutePhaseVolFracChange, 3 ) ) ); if( m_targetCompFracChange < LvArray::NumericLimits< real64 >::max ) { maxCompFracChange = MpiWrapper::max( maxCompFracChange ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max component fraction change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxCompFracChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", 100*maxCompFracChange, 3 ) ) ); } if( m_isThermal ) { maxRelativeTempChange = MpiWrapper::max( maxRelativeTempChange ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative temperature change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeTempChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeTempChange, 3 ) ) ); } real64 const eps = LvArray::NumericLimits< real64 >::epsilon; @@ -2526,7 +2516,7 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & if( m_targetCompFracChange < LvArray::NumericLimits< real64 >::max ) { nextDtCompFrac = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetCompFracChange - / std::max( eps, maxCompFracChange + m_solutionChangeScalingFactor * m_targetCompFracChange ); + / std::max( eps, maxCompFracChange + m_solutionChangeScalingFactor * m_targetCompFracChange ); if( m_nonlinearSolverParameters.getLogLevel() > 0 ) GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on component fraction change = {}", getName(), nextDtCompFrac )); } @@ -2540,7 +2530,7 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & } return std::min( std::min( nextDtPressure, std::min( nextDtPhaseVolFrac, nextDtCompFrac ) ), nextDtTemperature ); - } + } else { if( m_targetRelativePresChange >= 1.0 && @@ -2560,12 +2550,12 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & integer const numComp = m_numComponents; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel & mesh, - arrayView1d< string const > const & regionNames ) + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) { mesh.getElemManager().forElementSubRegions( regionNames, [&]( localIndex const, - ElementSubRegionBase & subRegion ) + ElementSubRegionBase & subRegion ) { arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); @@ -2617,22 +2607,22 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & maxAbsolutePhaseVolFracChange = MpiWrapper::max( maxAbsolutePhaseVolFracChange ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative pressure change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativePresChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativePresChange, 3 ) ) ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max absolute phase volume fraction change during time step = {}", - getName(), GEOS_FMT( "{:.{}f}", maxAbsolutePhaseVolFracChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", maxAbsolutePhaseVolFracChange, 3 ) ) ); if( m_targetRelativeCompDensChange < LvArray::NumericLimits< real64 >::max ) { maxRelativeCompDensChange = MpiWrapper::max( maxRelativeCompDensChange ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative component density change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeCompDensChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeCompDensChange, 3 ) ) ); } if( m_isThermal ) { maxRelativeTempChange = MpiWrapper::max( maxRelativeTempChange ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( "{}: max relative temperature change during time step = {} %", - getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeTempChange, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", 100*maxRelativeTempChange, 3 ) ) ); } real64 const eps = LvArray::NumericLimits< real64 >::epsilon; @@ -2649,7 +2639,7 @@ real64 CompositionalMultiphaseBase::setNextDtBasedOnStateChange( real64 const & if( m_targetRelativeCompDensChange < LvArray::NumericLimits< real64 >::max ) { nextDtCompDens = currentDt * ( 1.0 + m_solutionChangeScalingFactor ) * m_targetRelativeCompDensChange - / std::max( eps, maxRelativeCompDensChange + m_solutionChangeScalingFactor * m_targetRelativeCompDensChange ); + / std::max( eps, maxRelativeCompDensChange + m_solutionChangeScalingFactor * m_targetRelativeCompDensChange ); if( m_nonlinearSolverParameters.getLogLevel() > 0 ) GEOS_LOG_RANK_0( GEOS_FMT( "{}: next time step based on component density change = {}", getName(), nextDtCompDens )); } @@ -2850,7 +2840,7 @@ void CompositionalMultiphaseBase::resetStateToBeginningOfStep( DomainPartition & subRegion.template getField< fields::flow::pressure_n >(); pres.setValues< parallelDevicePolicy<> >( pres_n ); - if (m_useZFormulation) + if( m_useZFormulation ) { arrayView2d< real64, compflow::USD_COMP > const & compFrac = subRegion.template getField< fields::flow::globalCompFraction >(); @@ -2866,7 +2856,7 @@ void CompositionalMultiphaseBase::resetStateToBeginningOfStep( DomainPartition & subRegion.template getField< fields::flow::globalCompDensity_n >(); compDens.setValues< parallelDevicePolicy<> >( compDens_n ); } - + if( m_isThermal ) { @@ -2993,7 +2983,7 @@ void CompositionalMultiphaseBase::saveConvergedState( ElementSubRegionBase & sub { FlowSolverBase::saveConvergedState( subRegion ); - if (m_useZFormulation) + if( m_useZFormulation ) { arrayView2d< real64 const, compflow::USD_COMP > const & compFrac = subRegion.template getField< fields::flow::globalCompFraction >(); @@ -3022,7 +3012,7 @@ void CompositionalMultiphaseBase::saveConvergedState( ElementSubRegionBase & sub } } - + arrayView2d< real64 const, compflow::USD_COMP > const & compAmount = subRegion.template getField< fields::flow::compAmount >(); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp index 96c1b5090af..c4fecd7e431 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp @@ -78,7 +78,7 @@ DECLARE_FIELD( globalCompFraction_n, 0, NOPLOT, NO_WRITE, - "Global component fraction at the previous converged time step" ); + "Global component fraction at the previous converged time step" ); DECLARE_FIELD( globalCompFraction_k, "globalCompFraction_k", @@ -88,14 +88,6 @@ DECLARE_FIELD( globalCompFraction_k, NO_WRITE, "Global component fraction updates at the previous sequential iteration" ); -DECLARE_FIELD( bcglobalCompFraction, - "bcglobalCompFraction", - array2dLayoutComp, - 0, - NOPLOT, - WRITE_AND_READ, - "Dirichlet boundary condition composition" ); - DECLARE_FIELD( faceGlobalCompFraction, "faceGlobalCompFraction", array2dLayoutComp, @@ -199,7 +191,7 @@ DECLARE_FIELD( globalCompFractionScalingFactor, 1, NOPLOT, NO_WRITE, - "Scaling factors for global component fractions" ); + "Scaling factors for global component fractions" ); DECLARE_FIELD( compAmount, "compAmount", diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 7fc32e86f7f..f578f9d0442 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -317,9 +317,9 @@ void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); GEOS_ERROR_IF( m_isThermal, GEOS_FMT( - "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); GEOS_ERROR_IF( m_hasDiffusion || m_hasDispersion, GEOS_FMT( - "CompositionalMultiphaseBase {}: Z Formulation is currently not available for Diffusion or Dispersion", getDataContext() ) ); + "{}: Z Formulation is currently not available for Diffusion or Dispersion", getDataContext() ) ); // isothermal only for now isothermalCompositionalMultiphaseFVMKernels:: @@ -540,7 +540,7 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d { GEOS_MARK_FUNCTION; - if (m_useZFormulation) + if( m_useZFormulation ) { return scalingForSystemSolutionZFormulation( domain, dofManager, localSolution ); } @@ -552,12 +552,12 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d real64 minPresScalingFactor = 1.0, minCompDensScalingFactor = 1.0, minTempScalingFactor = 1.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel & mesh, - arrayView1d< string const > const & regionNames ) + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) { mesh.getElemManager().forElementSubRegions( regionNames, [&]( localIndex const, - ElementSubRegionBase & subRegion ) + ElementSubRegionBase & subRegion ) { arrayView1d< real64 const > const pressure = subRegion.getField< fields::flow::pressure >(); arrayView1d< real64 const > const temperature = subRegion.getField< fields::flow::temperature >(); @@ -572,37 +572,37 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d ? thermalCompositionalMultiphaseBaseKernels:: SolutionScalingKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, - m_maxAbsolutePresChange, - m_maxRelativeTempChange, - m_maxCompFracChange, - m_maxRelativeCompDensChange, - pressure, - temperature, - compDens, - pressureScalingFactor, - compDensScalingFactor, - temperatureScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution, - temperatureOffset ) + m_maxAbsolutePresChange, + m_maxRelativeTempChange, + m_maxCompFracChange, + m_maxRelativeCompDensChange, + pressure, + temperature, + compDens, + pressureScalingFactor, + compDensScalingFactor, + temperatureScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution, + temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionScalingKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, - m_maxAbsolutePresChange, - m_maxCompFracChange, - m_maxRelativeCompDensChange, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution ); + m_maxAbsolutePresChange, + m_maxCompFracChange, + m_maxRelativeCompDensChange, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution ); if( m_scalingType == ScalingType::Global ) { @@ -625,16 +625,16 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max pressure change = {} Pa (before scaling)", - getName(), GEOS_FMT( "{:.{}f}", maxDeltaPres, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", maxDeltaPres, 3 ) ) ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max component density change = {} {} (before scaling)", - getName(), GEOS_FMT( "{:.{}f}", maxDeltaCompDens, 3 ), massUnit ) ); + getName(), GEOS_FMT( "{:.{}f}", maxDeltaCompDens, 3 ), massUnit ) ); if( m_isThermal ) { maxDeltaTemp = MpiWrapper::max( maxDeltaTemp ); minTempScalingFactor = MpiWrapper::min( minTempScalingFactor ); GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Max temperature change = {} K (before scaling)", - getName(), GEOS_FMT( "{:.{}f}", maxDeltaTemp, 3 ) ) ); + getName(), GEOS_FMT( "{:.{}f}", maxDeltaTemp, 3 ) ) ); } if( m_scalingType == ScalingType::Local ) @@ -652,8 +652,8 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolution( DomainPartition & d } real64 CompositionalMultiphaseFVM::scalingForSystemSolutionZFormulation( DomainPartition & domain, - DofManager const & dofManager, - arrayView1d< real64 const > const & localSolution ) + DofManager const & dofManager, + arrayView1d< real64 const > const & localSolution ) { GEOS_MARK_FUNCTION; @@ -677,22 +677,20 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolutionZFormulation( DomainP arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); arrayView1d< real64 > compFracScalingFactor = subRegion.getField< fields::flow::globalCompFractionScalingFactor >(); - GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); - auto const subRegionData = isothermalCompositionalMultiphaseBaseKernels:: - SolutionScalingZFormulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, - m_maxAbsolutePresChange, - m_maxCompFracChange, - pressure, - compFrac, - pressureScalingFactor, - compFracScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution ); + SolutionScalingZFormulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_maxRelativePresChange, + m_maxAbsolutePresChange, + m_maxCompFracChange, + pressure, + compFrac, + pressureScalingFactor, + compFracScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution ); if( m_scalingType == ScalingType::Global ) { @@ -704,7 +702,7 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolutionZFormulation( DomainP minPresScalingFactor = std::min( minPresScalingFactor, subRegionData.localMinPresScalingFactor ); minCompFracScalingFactor = std::min( minCompFracScalingFactor, subRegionData.localMinCompFracScalingFactor ); minTempScalingFactor = std::min( minTempScalingFactor, subRegionData.localMinTempScalingFactor ); - + } ); } ); @@ -747,8 +745,8 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, { GEOS_MARK_FUNCTION; - // TO DO: Implement the solution check for Z Formulation - if (m_useZFormulation) + // TO DO: Implement the solution check for Z Formulation + if( m_useZFormulation ) return true; else { @@ -758,12 +756,12 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, integer numNegPres = 0, numNegDens = 0, numNegTotalDens = 0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel & mesh, - arrayView1d< string const > const & regionNames ) + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) { mesh.getElemManager().forElementSubRegions( regionNames, [&]( localIndex const, - ElementSubRegionBase & subRegion ) + ElementSubRegionBase & subRegion ) { arrayView1d< real64 const > const pressure = subRegion.getField< fields::flow::pressure >(); @@ -782,36 +780,36 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, ? thermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - temperature, - compDens, - pressureScalingFactor, - temperatureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution, - temperatureOffset ) + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + temperature, + compDens, + pressureScalingFactor, + temperatureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution, + temperatureOffset ) : isothermalCompositionalMultiphaseBaseKernels:: SolutionCheckKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_allowCompDensChopping, - m_allowNegativePressure, - m_scalingType, - scalingFactor, - pressure, - compDens, - pressureScalingFactor, - compDensScalingFactor, - dofManager.rankOffset(), - m_numComponents, - dofKey, - subRegion, - localSolution ); + m_allowNegativePressure, + m_scalingType, + scalingFactor, + pressure, + compDens, + pressureScalingFactor, + compDensScalingFactor, + dofManager.rankOffset(), + m_numComponents, + dofKey, + subRegion, + localSolution ); localCheck = std::min( localCheck, subRegionData.localMinVal ); @@ -833,14 +831,14 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, if( numNegPres > 0 ) GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative pressure values: {}, minimum value: {} Pa", - getName(), numNegPres, fmt::format( "{:.{}f}", minPres, 3 ) ) ); + getName(), numNegPres, fmt::format( "{:.{}f}", minPres, 3 ) ) ); string const massUnit = m_useMass ? "kg/m3" : "mol/m3"; if( numNegDens > 0 ) GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative component density values: {}, minimum value: {} {}}", - getName(), numNegDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + getName(), numNegDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); if( minTotalDens > 0 ) GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::Solution, GEOS_FMT( " {}: Number of negative total density values: {}, minimum value: {} {}}", - getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); + getName(), minTotalDens, fmt::format( "{:.{}f}", minDens, 3 ), massUnit ) ); return MpiWrapper::min( localCheck ); } @@ -940,10 +938,10 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana // these negative component densities are set to zero in this function // TODO: implement chopNegativeZ - - if( m_allowCompDensChopping) + + if( m_allowCompDensChopping ) { - if (m_useZFormulation) + if( m_useZFormulation ) chopNegativeCompFractions( domain ); else chopNegativeDensities( domain ); @@ -954,7 +952,7 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana arrayView1d< string const > const & regionNames ) { std::vector< string > fields{ fields::flow::pressure::key() }; - if (m_useZFormulation) + if( m_useZFormulation ) { fields.emplace_back( fields::flow::globalCompFraction::key() ); } @@ -990,7 +988,7 @@ void CompositionalMultiphaseFVM::updatePhaseMobility( ObjectManagerBase & dataGr { // For now: isothermal only GEOS_ERROR_IF( m_isThermal, GEOS_FMT( - "CompositionalMultiphaseBase {}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); } else { @@ -1187,7 +1185,7 @@ void CompositionalMultiphaseFVM::applyFaceDirichletBC( real64 const time_n, if( m_nonlinearSolverParameters.m_numNewtonIterations == 0 ) { bool const bcConsistent = validateFaceDirichletBC( domain, time_n + dt ); - GEOS_ERROR_IF( !bcConsistent, GEOS_FMT( "CompositionalMultiphaseBase {}: inconsistent boundary conditions", getDataContext() ) ); + GEOS_ERROR_IF( !bcConsistent, GEOS_FMT( "{}: inconsistent boundary conditions", getDataContext() ) ); } FieldSpecificationManager & fsManager = FieldSpecificationManager::getInstance(); @@ -1247,22 +1245,22 @@ void CompositionalMultiphaseFVM::applyFaceDirichletBC( real64 const time_n, if( m_useZFormulation ) { GEOS_ERROR_IF( m_isThermal, GEOS_FMT( - "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); + "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); isothermalCompositionalMultiphaseFVMKernels:: DirichletFluxComputeZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - elemDofKey, - getName(), - faceManager, - elemManager, - stencilWrapper, - multiFluidBase, - dt, - localMatrix, - localRhs ); + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + elemDofKey, + getName(), + faceManager, + elemManager, + stencilWrapper, + multiFluidBase, + dt, + localMatrix, + localRhs ); } else @@ -1273,36 +1271,36 @@ void CompositionalMultiphaseFVM::applyFaceDirichletBC( real64 const time_n, thermalCompositionalMultiphaseFVMKernels:: DirichletFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - elemDofKey, - getName(), - faceManager, - elemManager, - stencilWrapper, - multiFluidBase, - dt, - localMatrix, - localRhs ); + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + elemDofKey, + getName(), + faceManager, + elemManager, + stencilWrapper, + multiFluidBase, + dt, + localMatrix, + localRhs ); } else { isothermalCompositionalMultiphaseFVMKernels:: DirichletFluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - elemDofKey, - getName(), - faceManager, - elemManager, - stencilWrapper, - multiFluidBase, - dt, - localMatrix, - localRhs ); + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + elemDofKey, + getName(), + faceManager, + elemManager, + stencilWrapper, + multiFluidBase, + dt, + localMatrix, + localRhs ); } } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp index 9747469c37c..0f75765c2b9 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp @@ -112,7 +112,7 @@ class CompositionalMultiphaseFVM : public CompositionalMultiphaseBase virtual real64 scalingForSystemSolutionZFormulation( DomainPartition & domain, DofManager const & dofManager, - arrayView1d< real64 const > const & localSolution ); + arrayView1d< real64 const > const & localSolution ); virtual bool checkSystemSolution( DomainPartition & domain, @@ -126,7 +126,7 @@ class CompositionalMultiphaseFVM : public CompositionalMultiphaseBase real64 const scalingFactor, real64 const dt, DomainPartition & domain ) override; - + /**@}*/ virtual void diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index 9659637f56e..8d1c843bd42 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -522,8 +522,8 @@ real64 CompositionalMultiphaseHybridFVM::scalingForSystemSolution( DomainPartiti } real64 CompositionalMultiphaseHybridFVM::scalingForSystemSolutionZFormulation( DomainPartition & domain, - DofManager const & dofManager, - arrayView1d< real64 const > const & localSolution ) + DofManager const & dofManager, + arrayView1d< real64 const > const & localSolution ) { GEOS_MARK_FUNCTION; // z formulation not implemented diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp index e8dbe549ac4..29029f6a7df 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/AccumulationZFormulationKernel.hpp @@ -38,7 +38,7 @@ namespace geos namespace isothermalCompositionalMultiphaseBaseKernels { - static constexpr real64 minCompFracForDivision = 0; +static constexpr real64 minCompFracForDivision = 0; /******************************** AccumulationKernel ********************************/ @@ -217,8 +217,8 @@ class AccumulationZFormulationKernel */ template< typename FUNC = NoOpFunc > GEOS_HOST_DEVICE - void computeVolumeBalance( localIndex const ei, - StackVariables & stack ) const + void computeCompFracSum( localIndex const ei, + StackVariables & stack ) const { arraySlice1d< real64 const, compflow::USD_PHASE - 1 > compFrac = m_compFrac[ei]; @@ -305,7 +305,7 @@ class AccumulationZFormulationKernel kernelComponent.setup( ei, stack ); kernelComponent.computeAccumulation( ei, stack ); - kernelComponent.computeVolumeBalance( ei, stack ); + kernelComponent.computeCompFracSum( ei, stack ); kernelComponent.complete( ei, stack ); } ); } From 56cb9b3392f5dd00ef18465f8fa42c886668cd4f Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Thu, 19 Dec 2024 14:32:43 -0600 Subject: [PATCH 44/47] gravity plus some other code improvements --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 162 ++++++++---------- .../fluidFlow/CompositionalMultiphaseBase.hpp | 6 - .../fluidFlow/CompositionalMultiphaseFVM.cpp | 1 + .../FluxComputeZFormulationKernel.hpp | 12 +- .../zFormulation/PPUPhaseFluxZFormulation.hpp | 3 +- .../zFormulation/PotGradZFormulation.hpp | 95 +++++----- 6 files changed, 137 insertions(+), 142 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 6d64562d74a..2aadc509e55 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -256,11 +256,26 @@ void CompositionalMultiphaseBase::postInputInitialization() getWrapperDataContext( viewKeyStruct::minScalingFactorString() ) << ": The minumum scaling factor must be smaller or equal to 1.0" ); - if( m_isThermal && m_useSimpleAccumulation == 1 ) // useSimpleAccumulation is not yet compatible with thermal + if( m_isThermal && m_useSimpleAccumulation ) // useSimpleAccumulation is not yet compatible with thermal { - GEOS_LOG_RANK_0( "'useSimpleAccumulation' is not yet implemented for thermal simulation. Switched to phase sum accumulation." ); + GEOS_LOG_RANK_0( GEOS_FMT( "{}: '{}' is not yet implemented for thermal simulation. Switched to phase sum accumulation.", + getDataContext(), viewKeyStruct::useSimpleAccumulationString() ) ); m_useSimpleAccumulation = 0; } + + if( m_useZFormulation ) + { + if( m_isThermal ) // useZFormulation is not yet compatible with thermal + { + GEOS_ERROR( GEOS_FMT( "{}: '{}' is currently not available for thermal simulations", + getDataContext(), viewKeyStruct::useZFormulationFlagString() ) ); + } + if( m_isJumpStabilized ) // useZFormulation is not yet compatible with pressure stabilization + { + GEOS_ERROR( GEOS_FMT( "{}: pressure stabilization is not yet supported by {}", + getDataContext(), viewKeyStruct::useZFormulationFlagString() ) ); + } + } } void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) @@ -323,10 +338,12 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) if( m_useZFormulation ) + { // Z formulation - component densities and pressure are primary unknowns // (n_c-1) overall compositions + one pressure // Testing: let's have sum_c zc = 1 as explicit equation for now m_numDofPerCell = m_numComponents + 1; + } else { // default formulation - component densities and pressure are primary unknowns @@ -406,16 +423,14 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< pressureScalingFactor >( getName() ); subRegion.registerField< temperatureScalingFactor >( getName() ); - subRegion.registerField< globalCompDensityScalingFactor >( getName() ); - subRegion.registerField< globalCompFractionScalingFactor >( getName() ); // The resizing of the arrays needs to happen here, before the call to initializePreSubGroups, // to make sure that the dimensions are properly set before the timeHistoryOutput starts its initialization. + subRegion.registerField< globalCompFraction >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); if( m_useZFormulation ) { - subRegion.registerField< globalCompFraction >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); subRegion.registerField< globalCompFraction_n >( getName() ). setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); @@ -425,6 +440,7 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); } + subRegion.registerField< globalCompFractionScalingFactor >( getName() ); } else { @@ -439,9 +455,7 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); } - subRegion.registerField< globalCompFraction >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); + subRegion.registerField< globalCompDensityScalingFactor >( getName() ); subRegion.registerField< dGlobalCompFraction_dGlobalCompDensity >( getName() ). reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents ); } @@ -707,43 +721,36 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFraction( ObjectManagerBase string const & fluidName = dataGroup.getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( dataGroup, fluidName ); - real64 maxDeltaPhaseVolFrac = - m_isThermal ? - thermalCompositionalMultiphaseBaseKernels:: - PhaseVolumeFractionKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dataGroup, - fluid ) -: isothermalCompositionalMultiphaseBaseKernels:: - PhaseVolumeFractionKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dataGroup, - fluid ); - - return maxDeltaPhaseVolFrac; -} - -real64 CompositionalMultiphaseBase::updatePhaseVolumeFractionZFormulation( ObjectManagerBase & dataGroup ) const -{ - GEOS_MARK_FUNCTION; - - string const & fluidName = dataGroup.getReference< string >( viewKeyStruct::fluidNamesString() ); - MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( dataGroup, fluidName ); - - // For now: isothermal only - GEOS_ERROR_IF( m_isThermal, GEOS_FMT( "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); - - real64 maxDeltaPhaseVolFrac = - isothermalCompositionalMultiphaseBaseKernels:: - PhaseVolumeFractionZFormulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dataGroup, - fluid ); - - return maxDeltaPhaseVolFrac; + if( m_isThermal ) + { + return thermalCompositionalMultiphaseBaseKernels:: + PhaseVolumeFractionKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid ); + } + else + { + if( m_useZFormulation ) + { + return isothermalCompositionalMultiphaseBaseKernels:: + PhaseVolumeFractionZFormulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid ); + } + else + { + return isothermalCompositionalMultiphaseBaseKernels:: + PhaseVolumeFractionKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid ); + } + } } void CompositionalMultiphaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const @@ -926,9 +933,8 @@ real64 CompositionalMultiphaseBase::updateFluidState( ElementSubRegionBase & sub if( m_useZFormulation ) { // For p, z_c as the primary unknowns - updateFluidModel( subRegion ); // rho_T is now a function of p, z_c from volume balance + updateFluidModel( subRegion ); // rho_T is now a function of p, z_c from volume balance updateCompAmountZFormulation( subRegion ); - maxDeltaPhaseVolFrac = updatePhaseVolumeFractionZFormulation( subRegion ); } else { @@ -936,10 +942,8 @@ real64 CompositionalMultiphaseBase::updateFluidState( ElementSubRegionBase & sub updateGlobalComponentFraction( subRegion ); updateFluidModel( subRegion ); updateCompAmount( subRegion ); - maxDeltaPhaseVolFrac = updatePhaseVolumeFraction( subRegion ); - } - + maxDeltaPhaseVolFrac = updatePhaseVolumeFraction( subRegion ); updateRelPermModel( subRegion ); updatePhaseMobility( subRegion ); updateCapPressureModel( subRegion ); @@ -1011,13 +1015,12 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, if( m_useZFormulation ) { updateCompAmountZFormulation( subRegion ); - updatePhaseVolumeFractionZFormulation( subRegion ); } else { updateCompAmount( subRegion ); - updatePhaseVolumeFraction( subRegion ); } + updatePhaseVolumeFraction( subRegion ); // Update the constitutive models that only depend on // - the primary variables @@ -1036,9 +1039,9 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, // - This step depends on phaseVolFraction RelativePermeabilityBase & relPerm = getConstitutiveModel< RelativePermeabilityBase >( subRegion, subRegion.template getReference< string >( viewKeyStruct::relPermNamesString() ) ); - relPerm.saveConvergedPhaseVolFractionState( phaseVolFrac ); // this needs to happen before calling updateRelPermModel + relPerm.saveConvergedPhaseVolFractionState( phaseVolFrac ); // this needs to happen before calling updateRelPermModel updateRelPermModel( subRegion ); - relPerm.saveConvergedState(); // this needs to happen after calling updateRelPermModel + relPerm.saveConvergedState(); // this needs to happen after calling updateRelPermModel string const & fluidName = subRegion.template getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); @@ -1068,7 +1071,7 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, CapillaryPressureBase const & capPressure = getConstitutiveModel< CapillaryPressureBase >( subRegion, subRegion.template getReference< string >( viewKeyStruct::capPressureNamesString() ) ); - capPressure.initializeRockState( porosity, permeability ); // this needs to happen before calling updateCapPressureModel + capPressure.initializeRockState( porosity, permeability ); // this needs to happen before calling updateCapPressureModel updateCapPressureModel( subRegion ); } @@ -1200,7 +1203,7 @@ void CompositionalMultiphaseBase::computeHydrostaticEquilibrium( DomainPartition real64 const equilTolerance = fs.getEquilibrationTolerance(); real64 const datumElevation = fs.getDatumElevation(); real64 const datumPressure = fs.getDatumPressure(); - string const initPhaseName = fs.getInitPhaseName(); // will go away when GOC/WOC are implemented + string const initPhaseName = fs.getInitPhaseName(); // will go away when GOC/WOC are implemented localIndex const equilIndex = equilNameToEquilId.at( fs.getName() ); real64 const minElevation = LvArray::math::min( globalMinElevation[equilIndex], datumElevation ); @@ -1208,7 +1211,7 @@ void CompositionalMultiphaseBase::computeHydrostaticEquilibrium( DomainPartition real64 const elevationIncrement = LvArray::math::min( fs.getElevationIncrement(), maxElevation - minElevation ); localIndex const numPointsInTable = ( elevationIncrement > 0 ) ? std::ceil( (maxElevation - minElevation) / elevationIncrement ) + 1 : 1; - real64 const eps = 0.1 * (maxElevation - minElevation); // we add a small buffer to only log in the pathological cases + real64 const eps = 0.1 * (maxElevation - minElevation); // we add a small buffer to only log in the pathological cases GEOS_LOG_RANK_0_IF( ( (datumElevation > globalMaxElevation[equilIndex]+eps) || (datumElevation < globalMinElevation[equilIndex]-eps) ), getCatalogName() << " " << getDataContext() << ": By looking at the elevation of the cell centers in this model, GEOS found that " << @@ -1247,7 +1250,7 @@ void CompositionalMultiphaseBase::computeHydrostaticEquilibrium( DomainPartition auto itRegionFilter = regionFilter.find( region.getName() ); if( itRegionFilter == regionFilter.end() ) { - return; // the region is not in target, there is nothing to do + return; // the region is not in target, there is nothing to do } string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); @@ -1577,27 +1580,6 @@ void CompositionalMultiphaseBase::assembleZFormulationAccumulation( DomainPartit MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); CoupledSolidBase const & solid = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); - // TODO: add the thermal case - /* - if( m_isThermal ) - { - thermalCompositionalMultiphaseBaseKernels:: - AccumulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - dofKey, - subRegion, - fluid, - solid, - localMatrix, - localRhs ); - } - else - { - } - */ // isothermal for now isothermalCompositionalMultiphaseBaseKernels:: AccumulationZFormulationKernelFactory:: @@ -1791,7 +1773,7 @@ void CompositionalMultiphaseBase::applySourceFluxBC( real64 const time, return; } - real64 const rhsValue = rhsContributionArrayView[a] / sizeScalingFactor; // scale the contribution by the sizeScalingFactor here! + real64 const rhsValue = rhsContributionArrayView[a] / sizeScalingFactor; // scale the contribution by the sizeScalingFactor here! massProd += rhsValue; if( useTotalMassEquation > 0 ) { @@ -1800,7 +1782,7 @@ void CompositionalMultiphaseBase::applySourceFluxBC( real64 const time, localRhs[totalMassBalanceRow] += rhsValue; if( fluidComponentId < numFluidComponents - 1 ) { - globalIndex const compMassBalanceRow = totalMassBalanceRow + fluidComponentId + 1; // component mass bal equations are shifted + globalIndex const compMassBalanceRow = totalMassBalanceRow + fluidComponentId + 1; // component mass bal equations are shifted localRhs[compMassBalanceRow] += rhsValue; } } @@ -1928,7 +1910,7 @@ bool CompositionalMultiphaseBase::validateDirichletBC( DomainPartition & domain, bcConsistent = false; GEOS_WARNING( BCMessage::invalidComponentIndex( comp, fs.getName(), fields::flow::globalCompFraction::key() ) ); - return; // can't check next part with invalid component id + return; // can't check next part with invalid component id } ComponentMask< MAX_NC > & compMask = subRegionSetMap[setName]; @@ -2244,7 +2226,7 @@ void CompositionalMultiphaseBase::keepVariablesConstantDuringInitStep( real64 co rankOffset, localMatrix, rhsValue, - pres[ei], // freeze the current pressure value + pres[ei], // freeze the current pressure value pres[ei] ); localRhs[localRow] = rhsValue; @@ -2255,7 +2237,7 @@ void CompositionalMultiphaseBase::keepVariablesConstantDuringInitStep( real64 co rankOffset, localMatrix, rhsValue, - temp[ei], // freeze the current temperature value + temp[ei], // freeze the current temperature value temp[ei] ); localRhs[localRow + numComp + 1] = rhsValue; } @@ -2267,7 +2249,7 @@ void CompositionalMultiphaseBase::keepVariablesConstantDuringInitStep( real64 co rankOffset, localMatrix, rhsValue, - compDens[ei][ic], // freeze the current component density values + compDens[ei][ic], // freeze the current component density values compDens[ei][ic] ); localRhs[localRow + ic + 1] = rhsValue; } @@ -2869,11 +2851,11 @@ void CompositionalMultiphaseBase::implicitStepComplete( real64 const & time, CoupledSolidBase const & porousMaterial = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); if( m_keepVariablesConstantDuringInitStep ) { - porousMaterial.ignoreConvergedState(); // newPorosity <- porosity_n + porousMaterial.ignoreConvergedState(); // newPorosity <- porosity_n } else { - porousMaterial.saveConvergedState(); // porosity_n <- porosity + porousMaterial.saveConvergedState(); // porosity_n <- porosity } // Step 4: save converged state for the relperm model to handle hysteresis @@ -3017,7 +2999,7 @@ void CompositionalMultiphaseBase::saveSequentialIterationState( DomainPartition } ); } ); - m_sequentialCompDensChange = MpiWrapper::max( maxCompDensChange ); // store to be later used for convergence check + m_sequentialCompDensChange = MpiWrapper::max( maxCompDensChange ); // store to be later used for convergence check } void CompositionalMultiphaseBase::updateState( DomainPartition & domain ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index b6fd40cb6e0..0503eaad4c1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -116,12 +116,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase */ real64 updatePhaseVolumeFraction( ObjectManagerBase & dataGroup ) const; - /** - * @brief Recompute phase volume fractions (saturations) from constitutive and primary variables (pressure and global component fractions) - * @param dataGroup the group storing the required fields - */ - real64 updatePhaseVolumeFractionZFormulation( ObjectManagerBase & dataGroup ) const; - /** * @brief Update all relevant fluid models using current values of pressure and composition * @param dataGroup the group storing the required fields diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 694008ccd14..84fed924935 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -329,6 +329,7 @@ void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, elemDofKey, m_hasCapPressure, m_useTotalMassEquation, + m_useNewGravity, fluxApprox.upwindingParams(), getName(), mesh.getElemManager(), diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp index 0e8805e8d98..0286d1e6746 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/FluxComputeZFormulationKernel.hpp @@ -272,12 +272,11 @@ class FluxComputeZFormulationKernel : public FluxComputeKernelBase localIndex k_up = -1; - - isothermalCompositionalMultiphaseFVMKernelUtilities::PPUPhaseFluxZFormulation::compute< numComp, numFluxSupportPoints > ( m_numPhases, ip, m_kernelFlags.isSet( KernelFlags::CapPressure ), + m_kernelFlags.isSet( KernelFlags::NewGravity ), seri, sesri, sei, trans, dTrans_dPres, @@ -472,6 +471,7 @@ class FluxComputeZFormulationKernelFactory string const & dofKey, integer const hasCapPressure, integer const useTotalMassEquation, + integer const useNewGravity, UpwindingParameters upwindingParams, string const & solverName, ElementRegionManager const & elemManager, @@ -494,16 +494,16 @@ class FluxComputeZFormulationKernelFactory kernelFlags.set( KernelFlags::CapPressure ); if( useTotalMassEquation ) kernelFlags.set( KernelFlags::TotalMassEquation ); + if( useNewGravity ) + kernelFlags.set( KernelFlags::NewGravity ); if( upwindingParams.upwindingScheme == UpwindingScheme::C1PPU && isothermalCompositionalMultiphaseFVMKernelUtilities::epsC1PPU > 0 ) { - kernelFlags.set( KernelFlags::C1PPU ); - //GEOS_FMT("CompositionalMultiphaseBase {}: Z Formulation is currently not available for C1PPU ", getDataContext() ); + GEOS_ERROR( "Z Formulation is currently not available for C1PPU" ); } else if( upwindingParams.upwindingScheme == UpwindingScheme::IHU ) { - kernelFlags.set( KernelFlags::IHU ); - //GEOS_FMT("CompositionalMultiphaseBase {}: Z Formulation is currently not available for IHU ", getDataContext() ); + GEOS_ERROR( "Z Formulation is currently not available for IHU" ); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp index d30d14406a5..cfb4ba9b12f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PPUPhaseFluxZFormulation.hpp @@ -74,6 +74,7 @@ struct PPUPhaseFluxZFormulation compute( integer const numPhase, integer const ip, integer const hasCapPressure, + integer const useNewGravity, localIndex const ( &seri )[numFluxSupportPoints], localIndex const ( &sesri )[numFluxSupportPoints], localIndex const ( &sei )[numFluxSupportPoints], @@ -104,7 +105,7 @@ struct PPUPhaseFluxZFormulation real64 dPresGrad_dC[numFluxSupportPoints][numComp]{}; real64 dGravHead_dP[numFluxSupportPoints]{}; real64 dGravHead_dC[numFluxSupportPoints][numComp]{}; - PotGradZFormulation::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, seri, sesri, sei, trans, dTrans_dPres, pres, + PotGradZFormulation::compute< numComp, numFluxSupportPoints >( numPhase, ip, hasCapPressure, useNewGravity, seri, sesri, sei, trans, dTrans_dPres, pres, gravCoef, phaseVolFrac, dPhaseVolFrac, phaseMassDens, dPhaseMassDens, phaseCapPressure, dPhaseCapPressure_dPhaseVolFrac, potGrad, dPresGrad_dP, dPresGrad_dC, dGravHead_dP, dGravHead_dC ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp index 6aa9be4d161..4cd4a758ea2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PotGradZFormulation.hpp @@ -46,6 +46,7 @@ struct PotGradZFormulation compute ( integer const numPhase, integer const ip, integer const hasCapPressure, + integer const useNewGravity, localIndex const ( &seri )[numFluxSupportPoints], localIndex const ( &sesri )[numFluxSupportPoints], localIndex const ( &sei )[numFluxSupportPoints], @@ -86,45 +87,7 @@ struct PotGradZFormulation real64 gravHead = 0.0; real64 dCapPressure_dC[numComp]{}; - // calculate quantities on primary connected cells - integer denom = 0; - for( integer i = 0; i < numFluxSupportPoints; ++i ) - { - localIndex const er = seri[i]; - localIndex const esr = sesri[i]; - localIndex const ei = sei[i]; - - bool const phaseExists = (phaseVolFrac[er][esr][ei][ip] > 0); - if( !phaseExists ) - { - continue; - } - - // density - real64 const density = phaseMassDens[er][esr][ei][0][ip]; - real64 const dDens_dP = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; - - // average density and derivatives - densMean += density; - dDensMean_dP[i] = dDens_dP; - for( integer jc = 0; jc < numComp; ++jc ) - { - dDensMean_dC[i][jc] = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dC+jc]; - } - denom++; - } - if( denom > 1 ) - { - densMean /= denom; - for( integer i = 0; i < numFluxSupportPoints; ++i ) - { - dDensMean_dP[i] /= denom; - for( integer jc = 0; jc < numComp; ++jc ) - { - dDensMean_dC[i][jc] /= denom; - } - } - } + calculateMeanDensity( useNewGravity, ip, seri, sesri, sei, phaseVolFrac, phaseMassDens, dPhaseMassDens, densMean, dDensMean_dP, dDensMean_dC ); /// compute the TPFA potential difference for( integer i = 0; i < numFluxSupportPoints; i++ ) @@ -190,6 +153,60 @@ struct PotGradZFormulation } + template< integer numComp, integer numFluxSupportPoints > + GEOS_HOST_DEVICE + static void + calculateMeanDensity( integer const useNewGravity, + integer const ip, + localIndex const ( &seri )[numFluxSupportPoints], + localIndex const ( &sesri )[numFluxSupportPoints], + localIndex const ( &sei )[numFluxSupportPoints], + ElementViewConst< arrayView2d< real64 const, compflow::USD_PHASE > > const & phaseVolFrac, + ElementViewConst< arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > > const & phaseMassDens, + ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_DC > > const & dPhaseMassDens, + real64 & densMean, real64 ( & dDensMean_dP)[numFluxSupportPoints], real64 ( & dDensMean_dC )[numFluxSupportPoints][numComp] ) + { + // calculate quantities on primary connected cells + integer denom = 0; + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + localIndex const er = seri[i]; + localIndex const esr = sesri[i]; + localIndex const ei = sei[i]; + + bool const phaseExists = (phaseVolFrac[er][esr][ei][ip] > 0); + if( useNewGravity && !phaseExists ) + { + continue; + } + + // density + real64 const density = phaseMassDens[er][esr][ei][0][ip]; + real64 const dDens_dP = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dP]; + + // average density and derivatives + densMean += density; + dDensMean_dP[i] = dDens_dP; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDensMean_dC[i][jc] = dPhaseMassDens[er][esr][ei][0][ip][Deriv::dC+jc]; + } + denom++; + } + if( denom > 1 ) + { + densMean /= denom; + for( integer i = 0; i < numFluxSupportPoints; ++i ) + { + dDensMean_dP[i] /= denom; + for( integer jc = 0; jc < numComp; ++jc ) + { + dDensMean_dC[i][jc] /= denom; + } + } + } + } + }; } // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities From 736cc7ccf4192f5088b641ec1ddb9ce0df534099 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 20 Dec 2024 14:04:38 -0600 Subject: [PATCH 45/47] build fix, code simplification, input checks --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 301 +++++++----------- .../fluidFlow/CompositionalMultiphaseBase.hpp | 45 +-- .../CompositionalMultiphaseBaseFields.hpp | 15 +- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 218 ++++++------- .../fluidFlow/CompositionalMultiphaseFVM.hpp | 8 - .../CompositionalMultiphaseHybridFVM.cpp | 11 - .../CompositionalMultiphaseHybridFVM.hpp | 7 - .../ReactiveCompositionalMultiphaseOBL.cpp | 4 + 8 files changed, 241 insertions(+), 368 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 2aadc509e55..1c7ba200bdd 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -270,6 +270,11 @@ void CompositionalMultiphaseBase::postInputInitialization() GEOS_ERROR( GEOS_FMT( "{}: '{}' is currently not available for thermal simulations", getDataContext(), viewKeyStruct::useZFormulationFlagString() ) ); } + if( m_hasDiffusion || m_hasDispersion ) + { + GEOS_ERROR( GEOS_FMT( "{}: {} is currently not available for diffusion or dispersion", + getDataContext(), viewKeyStruct::useZFormulationFlagString() ) ); + } if( m_isJumpStabilized ) // useZFormulation is not yet compatible with pressure stabilization { GEOS_ERROR( GEOS_FMT( "{}: pressure stabilization is not yet supported by {}", @@ -434,12 +439,13 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< globalCompFraction_n >( getName() ). setDimLabels( 1, fluid.componentNames() ). reference().resizeDimension< 1 >( m_numComponents ); - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< globalCompFraction_k >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); - } + // may be needed later for sequential poromechanics implementation + //if( m_isFixedStressPoromechanicsUpdate ) + //{ + // subRegion.registerField< globalCompFraction_k >( getName() ). + // setDimLabels( 1, fluid.componentNames() ). + // reference().resizeDimension< 1 >( m_numComponents ); + //} subRegion.registerField< globalCompFractionScalingFactor >( getName() ); } else @@ -721,10 +727,11 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFraction( ObjectManagerBase string const & fluidName = dataGroup.getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( dataGroup, fluidName ); - if( m_isThermal ) + if( m_useZFormulation ) { - return thermalCompositionalMultiphaseBaseKernels:: - PhaseVolumeFractionKernelFactory:: + // isothermal for now + return isothermalCompositionalMultiphaseBaseKernels:: + PhaseVolumeFractionZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dataGroup, @@ -732,10 +739,10 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFraction( ObjectManagerBase } else { - if( m_useZFormulation ) + if( m_isThermal ) { - return isothermalCompositionalMultiphaseBaseKernels:: - PhaseVolumeFractionZFormulationKernelFactory:: + return thermalCompositionalMultiphaseBaseKernels:: + PhaseVolumeFractionKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dataGroup, @@ -832,49 +839,43 @@ void CompositionalMultiphaseBase::updateCompAmount( ElementSubRegionBase & subRe { GEOS_MARK_FUNCTION; + arrayView2d< real64, compflow::USD_COMP > const compAmount = subRegion.getField< fields::flow::compAmount >(); + arrayView1d< real64 const > const volume = subRegion.getElementVolume(); string const & solidName = subRegion.template getReference< string >( viewKeyStruct::solidNamesString() ); CoupledSolidBase const & porousMaterial = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); arrayView2d< real64 const > const porosity = porousMaterial.getPorosity(); - arrayView1d< real64 const > const volume = subRegion.getElementVolume(); - arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getField< fields::flow::globalCompDensity >(); - arrayView2d< real64, compflow::USD_COMP > const compAmount = subRegion.getField< fields::flow::compAmount >(); integer const numComp = m_numComponents; - forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + if( m_useZFormulation ) { - for( integer ic = 0; ic < numComp; ++ic ) - { - compAmount[ei][ic] = porosity[ei][0] * volume[ei] * compDens[ei][ic]; - } - } ); -} - -void CompositionalMultiphaseBase::updateCompAmountZFormulation( ElementSubRegionBase & subRegion ) const -{ - GEOS_MARK_FUNCTION; - - string const & solidName = subRegion.template getReference< string >( viewKeyStruct::solidNamesString() ); - CoupledSolidBase const & porousMaterial = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); - arrayView2d< real64 const > const porosity = porousMaterial.getPorosity(); - arrayView1d< real64 const > const volume = subRegion.getElementVolume(); - arrayView2d< real64 const, compflow::USD_COMP > const compFrac = subRegion.getField< fields::flow::globalCompFraction >(); - arrayView2d< real64, compflow::USD_COMP > const compAmount = subRegion.getField< fields::flow::compAmount >(); - // access total density stored in the fluid - string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); - MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); - arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); - - integer const numComp = m_numComponents; + arrayView2d< real64 const, compflow::USD_COMP > const compFrac = subRegion.getField< fields::flow::globalCompFraction >(); + // access total density stored in the fluid + string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); + MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); + arrayView2d< real64 const, multifluid::USD_FLUID > const totalDens = fluid.totalDensity(); - forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + for( integer ic = 0; ic < numComp; ++ic ) + { + // m = phi*V*z_c*rho_T + compAmount[ei][ic] = porosity[ei][0] * volume[ei] * compFrac[ei][ic] * totalDens[ei][0]; + } + } ); + } + else { - for( integer ic = 0; ic < numComp; ++ic ) + arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getField< fields::flow::globalCompDensity >(); + + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) { - // m = phi*V*z_c*rho_T - compAmount[ei][ic] = porosity[ei][0] * volume[ei] * compFrac[ei][ic] * totalDens[ei][0]; - } - } ); + for( integer ic = 0; ic < numComp; ++ic ) + { + compAmount[ei][ic] = porosity[ei][0] * volume[ei] * compDens[ei][ic]; + } + } ); + } } void CompositionalMultiphaseBase::updateEnergy( ElementSubRegionBase & subRegion ) const @@ -930,19 +931,13 @@ real64 CompositionalMultiphaseBase::updateFluidState( ElementSubRegionBase & sub real64 maxDeltaPhaseVolFrac; - if( m_useZFormulation ) - { - // For p, z_c as the primary unknowns - updateFluidModel( subRegion ); // rho_T is now a function of p, z_c from volume balance - updateCompAmountZFormulation( subRegion ); - } - else + if( !m_useZFormulation ) { // For p, rho_c as the primary unknowns updateGlobalComponentFraction( subRegion ); - updateFluidModel( subRegion ); - updateCompAmount( subRegion ); } + updateFluidModel( subRegion ); + updateCompAmount( subRegion ); maxDeltaPhaseVolFrac = updatePhaseVolumeFraction( subRegion ); updateRelPermModel( subRegion ); updatePhaseMobility( subRegion ); @@ -988,16 +983,16 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, compDens[ei][ic] = totalDens[ei][0] * compFrac[ei][ic]; } } ); - } - // with initial component densities defined - check if they need to be corrected to avoid zero diags etc - if( m_allowCompDensChopping ) - { - chopNegativeDensities( subRegion ); + // with initial component densities defined - check if they need to be corrected to avoid zero diags etc + if( m_allowCompDensChopping ) + { + chopNegativeDensities( subRegion ); + } } } ); - // with initial component densities defined - check if they need to be corrected to avoid zero diags etc + // check if comp fractions need to be corrected to avoid zero diags etc if( m_useZFormulation ) { DomainPartition & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" ); @@ -1012,14 +1007,7 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, { // Initialize/update dependent state quantities - if( m_useZFormulation ) - { - updateCompAmountZFormulation( subRegion ); - } - else - { - updateCompAmount( subRegion ); - } + updateCompAmount( subRegion ); updatePhaseVolumeFraction( subRegion ); // Update the constitutive models that only depend on @@ -1388,16 +1376,8 @@ void CompositionalMultiphaseBase::initializePostInitialConditionsPreSubGroups() arrayView1d< string const > const & regionNames ) { FieldIdentifiers fieldsToBeSync; - if( m_useZFormulation ) - { - fieldsToBeSync.addElementFields( { fields::flow::globalCompFraction::key() }, - regionNames ); - } - else - { - fieldsToBeSync.addElementFields( { fields::flow::globalCompDensity::key() }, - regionNames ); - } + fieldsToBeSync.addElementFields( {m_useZFormulation ? fields::flow::globalCompFraction::key() : fields::flow::globalCompDensity::key() }, + regionNames ); CommunicationTools::getInstance().synchronizeFields( fieldsToBeSync, mesh, domain.getNeighbors(), false ); @@ -1461,50 +1441,34 @@ void CompositionalMultiphaseBase::assembleSystem( real64 const GEOS_UNUSED_PARAM { GEOS_MARK_FUNCTION; - // Accumulation term - if( m_useZFormulation ) + // Accumulation and other local terms + assembleLocalTerms( domain, + dofManager, + localMatrix, + localRhs ); + + if( m_isJumpStabilized ) { - assembleZFormulationAccumulation( domain, - dofManager, - localMatrix, - localRhs ); - - assembleZFormulationFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); + assembleStabilizedFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); } else { - assembleAccumulationAndVolumeBalanceTerms( domain, - dofManager, - localMatrix, - localRhs ); - - if( m_isJumpStabilized ) - { - assembleStabilizedFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); - } - else - { - assembleFluxTerms( dt, - domain, - dofManager, - localMatrix, - localRhs ); - } + assembleFluxTerms( dt, + domain, + dofManager, + localMatrix, + localRhs ); } } -void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( DomainPartition & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const +void CompositionalMultiphaseBase::assembleLocalTerms( DomainPartition & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const { GEOS_MARK_FUNCTION; @@ -1523,14 +1487,16 @@ void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( Dom MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); CoupledSolidBase const & solid = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); - if( m_isThermal ) + if( m_useZFormulation ) { - thermalCompositionalMultiphaseBaseKernels:: - AccumulationKernelFactory:: + // isothermal for now + isothermalCompositionalMultiphaseBaseKernels:: + AccumulationZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), m_useTotalMassEquation, + m_useSimpleAccumulation, dofKey, subRegion, fluid, @@ -1540,64 +1506,42 @@ void CompositionalMultiphaseBase::assembleAccumulationAndVolumeBalanceTerms( Dom } else { - isothermalCompositionalMultiphaseBaseKernels:: - AccumulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - m_useSimpleAccumulation, - dofKey, - subRegion, - fluid, - solid, - localMatrix, - localRhs ); + if( m_isThermal ) + { + thermalCompositionalMultiphaseBaseKernels:: + AccumulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + dofKey, + subRegion, + fluid, + solid, + localMatrix, + localRhs ); + } + else + { + isothermalCompositionalMultiphaseBaseKernels:: + AccumulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + m_useTotalMassEquation, + m_useSimpleAccumulation, + dofKey, + subRegion, + fluid, + solid, + localMatrix, + localRhs ); + } } } ); } ); } -void CompositionalMultiphaseBase::assembleZFormulationAccumulation( DomainPartition & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const -{ - GEOS_MARK_FUNCTION; - - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel const & mesh, - arrayView1d< string const > const & regionNames ) - { - mesh.getElemManager().forElementSubRegions( regionNames, - [&]( localIndex const, - ElementSubRegionBase const & subRegion ) - { - string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); - string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); - string const & solidName = subRegion.getReference< string >( viewKeyStruct::solidNamesString() ); - - MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); - CoupledSolidBase const & solid = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName ); - - // isothermal for now - isothermalCompositionalMultiphaseBaseKernels:: - AccumulationZFormulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - m_useTotalMassEquation, - m_useSimpleAccumulation, - dofKey, - subRegion, - fluid, - solid, - localMatrix, - localRhs ); - } ); - } ); -} - void CompositionalMultiphaseBase::applyBoundaryConditions( real64 const time_n, real64 const dt, DomainPartition & domain, @@ -2926,12 +2870,13 @@ void CompositionalMultiphaseBase::saveConvergedState( ElementSubRegionBase & sub arrayView2d< real64, compflow::USD_COMP > const & compFrac_n = subRegion.template getField< fields::flow::globalCompFraction_n >(); compFrac_n.setValues< parallelDevicePolicy<> >( compFrac ); - if( m_isFixedStressPoromechanicsUpdate ) - { - arrayView2d< real64, compflow::USD_COMP > const & compFrac_k = - subRegion.template getField< fields::flow::globalCompFraction_k >(); - compFrac_k.setValues< parallelDevicePolicy<> >( compFrac ); - } + // may be useful later for sequential poromechanics implementation + //if( m_isFixedStressPoromechanicsUpdate ) + //{ + // arrayView2d< real64, compflow::USD_COMP > const & compFrac_k = + // subRegion.template getField< fields::flow::globalCompFraction_k >(); + // compFrac_k.setValues< parallelDevicePolicy<> >( compFrac ); + //} } else { @@ -2948,8 +2893,6 @@ void CompositionalMultiphaseBase::saveConvergedState( ElementSubRegionBase & sub } } - - arrayView2d< real64 const, compflow::USD_COMP > const & compAmount = subRegion.template getField< fields::flow::compAmount >(); arrayView2d< real64, compflow::USD_COMP > const & compAmount_n = diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index 0503eaad4c1..174e2c856dc 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -140,12 +140,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase */ void updateCompAmount( ElementSubRegionBase & subRegion ) const; - /** - * @brief Update components mass/moles if Z formulation is used - * @param subRegion the subregion storing the required fields - */ - void updateCompAmountZFormulation( ElementSubRegionBase & subRegion ) const; - /** * @brief Update energy * @param subRegion the subregion storing the required fields @@ -197,7 +191,7 @@ class CompositionalMultiphaseBase : public FlowSolverBase { return m_useMass ? units::Unit::Mass : units::Unit::Mole; } /** - * @brief assembles the accumulation and volume balance terms for all cells + * @brief assembles the accumulation other local terms for all cells * @param time_n previous time value * @param dt time step * @param domain the physical domain object @@ -205,10 +199,10 @@ class CompositionalMultiphaseBase : public FlowSolverBase * @param localMatrix the system matrix * @param localRhs the system right-hand side vector */ - void assembleAccumulationAndVolumeBalanceTerms( DomainPartition & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const; + void assembleLocalTerms( DomainPartition & domain, + DofManager const & dofManager, + CRSMatrixView< real64, globalIndex const > const & localMatrix, + arrayView1d< real64 > const & localRhs ) const; /** * @brief assembles the flux terms for all cells @@ -241,35 +235,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) const = 0; - /** - * @brief assembles the accumulation term (Z formulation) for all cells - * @param time_n previous time value - * @param dt time step - * @param domain the physical domain object - * @param dofManager degree-of-freedom manager associated with the linear system - * @param localMatrix the system matrix - * @param localRhs the system right-hand side vector - */ - void assembleZFormulationAccumulation( DomainPartition & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const; - - /** - * @brief assembles the flux terms (Z formulation) for all cells - * @param time_n previous time value - * @param dt time step - * @param domain the physical domain object - * @param dofManager degree-of-freedom manager associated with the linear system - * @param matrix the system matrix - * @param rhs the system right-hand side vector - */ - virtual void - assembleZFormulationFluxTerms( real64 const dt, - DomainPartition const & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const = 0; /**@}*/ diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp index d3ff3841652..3f520747ae8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp @@ -80,13 +80,14 @@ DECLARE_FIELD( globalCompFraction_n, NO_WRITE, "Global component fraction at the previous converged time step" ); -DECLARE_FIELD( globalCompFraction_k, - "globalCompFraction_k", - array2dLayoutComp, - 0, - NOPLOT, - NO_WRITE, - "Global component fraction updates at the previous sequential iteration" ); +// may be needed later for sequential poromechanics implementation +//DECLARE_FIELD( globalCompFraction_k, +// "globalCompFraction_k", +// array2dLayoutComp, +// 0, +// NOPLOT, +// NO_WRITE, +// "Global component fraction updates at the previous sequential iteration" ); DECLARE_FIELD( faceGlobalCompFraction, "faceGlobalCompFraction", diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index 84fed924935..e5636f6920b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -111,9 +111,18 @@ void CompositionalMultiphaseFVM::postInputInitialization() { CompositionalMultiphaseBase::postInputInitialization(); - if( m_scalingType == ScalingType::Local && m_nonlinearSolverParameters.m_lineSearchAction != NonlinearSolverParameters::LineSearchAction::None ) + if( m_scalingType == ScalingType::Local && + m_nonlinearSolverParameters.m_lineSearchAction != NonlinearSolverParameters::LineSearchAction::None ) { - GEOS_ERROR( GEOS_FMT( "{}: line search is not supported for {} = {}", getName(), viewKeyStruct::scalingTypeString(), EnumStrings< ScalingType >::toString( ScalingType::Local )) ); + GEOS_ERROR( GEOS_FMT( "{}: line search is not supported for {} = {}", + getName(), viewKeyStruct::scalingTypeString(), + EnumStrings< ScalingType >::toString( ScalingType::Local )) ); + } + + if( m_useZFormulation && m_dbcParams.useDBC ) // useZFormulation is not compatible with DBC + { + GEOS_ERROR( GEOS_FMT( "{}: '{}' is not compatible with {}", + getDataContext(), viewKeyStruct::useZFormulationFlagString(), viewKeyStruct::useDBCString() ) ); } } @@ -184,16 +193,20 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); // Convective flux - if( m_isThermal ) + + if( m_useZFormulation ) { - thermalCompositionalMultiphaseFVMKernels:: - FluxComputeKernelFactory:: + // isothermal only for now + isothermalCompositionalMultiphaseFVMKernels:: + FluxComputeZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, dofManager.rankOffset(), elemDofKey, m_hasCapPressure, m_useTotalMassEquation, + m_useNewGravity, + fluxApprox.upwindingParams(), getName(), mesh.getElemManager(), stencilWrapper, @@ -203,9 +216,9 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, } else { - if( m_dbcParams.useDBC ) + if( m_isThermal ) { - dissipationCompositionalMultiphaseFVMKernels:: + thermalCompositionalMultiphaseFVMKernels:: FluxComputeKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, m_numPhases, @@ -218,74 +231,95 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, stencilWrapper, dt, localMatrix.toViewConstSizes(), - localRhs.toView(), - m_dbcParams.omega, - getNonlinearSolverParameters().m_numNewtonIterations, - m_dbcParams.continuation, - m_dbcParams.miscible, - m_dbcParams.kappamin, - m_dbcParams.contMultiplier ); + localRhs.toView() ); } else { - isothermalCompositionalMultiphaseFVMKernels:: - FluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasCapPressure, - m_useTotalMassEquation, - m_useNewGravity, - fluxApprox.upwindingParams(), - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + if( m_dbcParams.useDBC ) + { + dissipationCompositionalMultiphaseFVMKernels:: + FluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasCapPressure, + m_useTotalMassEquation, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView(), + m_dbcParams.omega, + getNonlinearSolverParameters().m_numNewtonIterations, + m_dbcParams.continuation, + m_dbcParams.miscible, + m_dbcParams.kappamin, + m_dbcParams.contMultiplier ); + } + else + { + isothermalCompositionalMultiphaseFVMKernels:: + FluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasCapPressure, + m_useTotalMassEquation, + m_useNewGravity, + fluxApprox.upwindingParams(), + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + } } - } - // Diffusive and dispersive flux - if( m_hasDiffusion || m_hasDispersion ) - { + // Diffusive and dispersive flux - if( m_isThermal ) + if( m_hasDiffusion || m_hasDispersion ) { - thermalCompositionalMultiphaseFVMKernels:: - DiffusionDispersionFluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasDiffusion, - m_hasDispersion, - m_useTotalMassEquation, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); - } - else - { - isothermalCompositionalMultiphaseFVMKernels:: - DiffusionDispersionFluxComputeKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasDiffusion, - m_hasDispersion, - m_useTotalMassEquation, - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); + + if( m_isThermal ) + { + thermalCompositionalMultiphaseFVMKernels:: + DiffusionDispersionFluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasDiffusion, + m_hasDispersion, + m_useTotalMassEquation, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + } + else + { + isothermalCompositionalMultiphaseFVMKernels:: + DiffusionDispersionFluxComputeKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dofManager.rankOffset(), + elemDofKey, + m_hasDiffusion, + m_hasDispersion, + m_useTotalMassEquation, + getName(), + mesh.getElemManager(), + stencilWrapper, + dt, + localMatrix.toViewConstSizes(), + localRhs.toView() ); + } } } @@ -293,54 +327,6 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt, } ); } -void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt, - DomainPartition const & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const -{ - GEOS_MARK_FUNCTION; - - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel const & mesh, - arrayView1d< string const > const & ) - { - NumericalMethodsManager const & numericalMethodManager = domain.getNumericalMethodManager(); - FiniteVolumeManager const & fvManager = numericalMethodManager.getFiniteVolumeManager(); - FluxApproximationBase const & fluxApprox = fvManager.getFluxApproximation( m_discretizationName ); - - string const & elemDofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); - - fluxApprox.forAllStencils( mesh, [&] ( auto & stencil ) - { - typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper(); - - GEOS_ERROR_IF( m_isThermal, GEOS_FMT( - "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); - GEOS_ERROR_IF( m_hasDiffusion || m_hasDispersion, GEOS_FMT( - "{}: Z Formulation is currently not available for Diffusion or Dispersion", getDataContext() ) ); - - // isothermal only for now - isothermalCompositionalMultiphaseFVMKernels:: - FluxComputeZFormulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dofManager.rankOffset(), - elemDofKey, - m_hasCapPressure, - m_useTotalMassEquation, - m_useNewGravity, - fluxApprox.upwindingParams(), - getName(), - mesh.getElemManager(), - stencilWrapper, - dt, - localMatrix.toViewConstSizes(), - localRhs.toView() ); - } ); - } ); -} - void CompositionalMultiphaseFVM::assembleStabilizedFluxTerms( real64 const dt, DomainPartition const & domain, DofManager const & dofManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp index 7e77160184e..2798752e693 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp @@ -143,14 +143,6 @@ class CompositionalMultiphaseFVM : public CompositionalMultiphaseBase CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) const override; - virtual void - assembleZFormulationFluxTerms( real64 const dt, - DomainPartition const & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const override; - - virtual void updatePhaseMobility( ObjectManagerBase & dataGroup ) const override; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index a4e379681e7..909997e7d6b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -419,17 +419,6 @@ void CompositionalMultiphaseHybridFVM::assembleFluxTerms( real64 const dt, } ); } -void CompositionalMultiphaseHybridFVM::assembleZFormulationFluxTerms( real64 const dt, - DomainPartition const & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const -{ - // z formulation not implemented - GEOS_UNUSED_VAR( dt, domain, dofManager, localMatrix, localRhs ); - GEOS_ERROR( "Z formulation not yet available for this flow solver" ); -} - void CompositionalMultiphaseHybridFVM::assembleStabilizedFluxTerms( real64 const dt, DomainPartition const & domain, DofManager const & dofManager, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp index bb85c071ae7..5fa78d20cef 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp @@ -139,13 +139,6 @@ class CompositionalMultiphaseHybridFVM : public CompositionalMultiphaseBase CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ) const override; - virtual void - assembleZFormulationFluxTerms( real64 const dt, - DomainPartition const & domain, - DofManager const & dofManager, - CRSMatrixView< real64, globalIndex const > const & localMatrix, - arrayView1d< real64 > const & localRhs ) const override; - virtual void assembleStabilizedFluxTerms( real64 const dt, DomainPartition const & domain, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp index 8d28b7bfcdc..07c38cd2726 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp @@ -272,6 +272,10 @@ void ReactiveCompositionalMultiphaseOBL::registerDataOnMesh( Group & meshBodies subRegion.registerField< bcGlobalCompFraction >( solverName ). reference().resizeDimension< 1 >( m_numComponents ); + // we need to register this fiels in any case (if there is a single component or not) + // to be able to pass the view to OBLOperatorsKernel + subRegion.registerField< globalCompFraction_n >( solverName ). + reference().resizeDimension< 1 >( m_numComponents ); // in principle, referencePorosity could be used directly from solid model, // but was duplicated to remove dependency on solid subRegion.registerField< referencePorosity >( solverName ); From 46914472230172041783b2c3b08da68725a4fbf9 Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 20 Dec 2024 14:40:21 -0600 Subject: [PATCH 46/47] minot clean up --- .../fluidFlow/CompositionalMultiphaseBase.cpp | 2 +- .../fluidFlow/CompositionalMultiphaseFVM.cpp | 41 +++++-------------- .../fluidFlow/CompositionalMultiphaseFVM.hpp | 2 +- .../CompositionalMultiphaseHybridFVM.cpp | 11 ----- .../CompositionalMultiphaseHybridFVM.hpp | 5 --- 5 files changed, 12 insertions(+), 49 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index 1c7ba200bdd..df99c5df9d1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -993,7 +993,7 @@ void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh, } ); // check if comp fractions need to be corrected to avoid zero diags etc - if( m_useZFormulation ) + if( m_useZFormulation && m_allowCompDensChopping ) { DomainPartition & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" ); chopNegativeCompFractions( domain ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index e5636f6920b..cc3062f1712 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -672,8 +672,6 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolutionZFormulation( DomainP DofManager const & dofManager, arrayView1d< real64 const > const & localSolution ) { - GEOS_MARK_FUNCTION; - string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() ); real64 scalingFactor = 1.0; real64 maxDeltaPres = 0.0, maxDeltaCompFrac = 0.0, maxDeltaTemp = 0.0; @@ -954,8 +952,6 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana // if component density chopping is allowed, some component densities may be negative after the update // these negative component densities are set to zero in this function - // TODO: implement chopNegativeZ - if( m_allowCompDensChopping ) { if( m_useZFormulation ) @@ -968,15 +964,8 @@ void CompositionalMultiphaseFVM::applySystemSolution( DofManager const & dofMana MeshLevel & mesh, arrayView1d< string const > const & regionNames ) { - std::vector< string > fields{ fields::flow::pressure::key() }; - if( m_useZFormulation ) - { - fields.emplace_back( fields::flow::globalCompFraction::key() ); - } - else - { - fields.emplace_back( fields::flow::globalCompDensity::key() ); - } + std::vector< string > fields{ fields::flow::pressure::key(), + m_useZFormulation ? fields::flow::globalCompFraction::key() : fields::flow::globalCompDensity::key() }; if( m_isThermal ) { fields.emplace_back( fields::flow::temperature::key() ); @@ -1001,22 +990,14 @@ void CompositionalMultiphaseFVM::updatePhaseMobility( ObjectManagerBase & dataGr if( m_useZFormulation ) { - if( m_isThermal ) - { - // For now: isothermal only - GEOS_ERROR_IF( m_isThermal, GEOS_FMT( - "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); - } - else - { - isothermalCompositionalMultiphaseFVMKernels:: - PhaseMobilityZFormulationKernelFactory:: - createAndLaunch< parallelDevicePolicy<> >( m_numComponents, - m_numPhases, - dataGroup, - fluid, - relperm ); - } + // For now: isothermal only + isothermalCompositionalMultiphaseFVMKernels:: + PhaseMobilityZFormulationKernelFactory:: + createAndLaunch< parallelDevicePolicy<> >( m_numComponents, + m_numPhases, + dataGroup, + fluid, + relperm ); } else { @@ -1261,8 +1242,6 @@ void CompositionalMultiphaseFVM::applyFaceDirichletBC( real64 const time_n, if( m_useZFormulation ) { - GEOS_ERROR_IF( m_isThermal, GEOS_FMT( - "{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) ); isothermalCompositionalMultiphaseFVMKernels:: DirichletFluxComputeZFormulationKernelFactory:: createAndLaunch< parallelDevicePolicy<> >( m_numComponents, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp index 2798752e693..f1437bd45f3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.hpp @@ -109,7 +109,7 @@ class CompositionalMultiphaseFVM : public CompositionalMultiphaseBase DofManager const & dofManager, arrayView1d< real64 const > const & localSolution ) override; - virtual real64 + real64 scalingForSystemSolutionZFormulation( DomainPartition & domain, DofManager const & dofManager, arrayView1d< real64 const > const & localSolution ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp index 909997e7d6b..922b8fbf010 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.cpp @@ -509,17 +509,6 @@ real64 CompositionalMultiphaseHybridFVM::scalingForSystemSolution( DomainPartiti return LvArray::math::max( MpiWrapper::min( scalingFactor ), m_minScalingFactor ); } -real64 CompositionalMultiphaseHybridFVM::scalingForSystemSolutionZFormulation( DomainPartition & domain, - DofManager const & dofManager, - arrayView1d< real64 const > const & localSolution ) -{ - GEOS_MARK_FUNCTION; - // z formulation not implemented - GEOS_UNUSED_VAR( domain, dofManager, localSolution ); - GEOS_ERROR( "Z formulation not yet available for this flow solver" ); - return 0; -} - bool CompositionalMultiphaseHybridFVM::checkSystemSolution( DomainPartition & domain, DofManager const & dofManager, arrayView1d< real64 const > const & localSolution, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp index 5fa78d20cef..d133610a7b1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseHybridFVM.hpp @@ -111,11 +111,6 @@ class CompositionalMultiphaseHybridFVM : public CompositionalMultiphaseBase DofManager const & dofManager, arrayView1d< real64 const > const & localSolution ) override; - virtual real64 - scalingForSystemSolutionZFormulation( DomainPartition & domain, - DofManager const & dofManager, - arrayView1d< real64 const > const & localSolution ); - virtual bool checkSystemSolution( DomainPartition & domain, DofManager const & dofManager, From f58b4821f49be1129422a88e958889560e13485d Mon Sep 17 00:00:00 2001 From: Pavel Tomin Date: Fri, 20 Dec 2024 14:46:59 -0600 Subject: [PATCH 47/47] build fix --- .../physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp index cc3062f1712..52cc925d7d7 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseFVM.cpp @@ -686,10 +686,10 @@ real64 CompositionalMultiphaseFVM::scalingForSystemSolutionZFormulation( DomainP ElementSubRegionBase & subRegion ) { arrayView1d< real64 const > const pressure = subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const temperature = subRegion.getField< fields::flow::temperature >(); + //arrayView1d< real64 const > const temperature = subRegion.getField< fields::flow::temperature >(); arrayView2d< real64 const, compflow::USD_COMP > const compFrac = subRegion.getField< fields::flow::globalCompFraction >(); arrayView1d< real64 > pressureScalingFactor = subRegion.getField< fields::flow::pressureScalingFactor >(); - arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); + //arrayView1d< real64 > temperatureScalingFactor = subRegion.getField< fields::flow::temperatureScalingFactor >(); arrayView1d< real64 > compFracScalingFactor = subRegion.getField< fields::flow::globalCompFractionScalingFactor >(); auto const subRegionData = isothermalCompositionalMultiphaseBaseKernels:: @@ -762,7 +762,9 @@ bool CompositionalMultiphaseFVM::checkSystemSolution( DomainPartition & domain, // TO DO: Implement the solution check for Z Formulation if( m_useZFormulation ) + { return true; + } else { string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() );