Skip to content

Commit 6551b87

Browse files
author
Francois Hamon
authored
Implement CO2Brine model on GPU (#1325)
* implemented CO2Brine with new tables and without autodiff * implemented Sergey's suggestion * remove outdated rst to make sure all CI tests pass * addressed Thomas' comments * addressed Sergey's and Thomas' comments * addressed Thomas' comments * implemented Sergey's suggestion; addressed Thomas' comments * with constructor in cpp * addressed review comments * updated integratedTests submodule
1 parent 512a162 commit 6551b87

54 files changed

Lines changed: 4271 additions & 2722 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integratedTests

src/coreComponents/constitutive/CMakeLists.txt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ set( constitutive_headers
1515
contact/Coulomb.hpp
1616
fluid/DeadOilFluid.hpp
1717
fluid/MultiPhaseMultiComponentFluid.hpp
18-
fluid/PVTFunctions/BrineCO2DensityFunction.hpp
19-
fluid/PVTFunctions/BrineViscosityFunction.hpp
20-
fluid/PVTFunctions/CO2SolubilityFunction.hpp
21-
fluid/PVTFunctions/FenghourCO2ViscosityFunction.hpp
18+
fluid/PVTFunctions/BrineCO2Density.hpp
19+
fluid/PVTFunctions/BrineViscosity.hpp
20+
fluid/PVTFunctions/CO2Solubility.hpp
21+
fluid/PVTFunctions/FenghourCO2Viscosity.hpp
2222
fluid/PVTFunctions/FlashModelBase.hpp
2323
fluid/PVTFunctions/PVTFunctionBase.hpp
24-
fluid/PVTFunctions/SpanWagnerCO2DensityFunction.hpp
25-
fluid/PVTFunctions/UtilityFunctions.hpp
24+
fluid/PVTFunctions/SpanWagnerCO2Density.hpp
25+
fluid/PVTFunctions/PVTFunctionHelpers.hpp
2626
fluid/SingleFluidBase.hpp
2727
fluid/singleFluidSelector.hpp
2828
fluid/MultiFluidBase.hpp
@@ -75,13 +75,12 @@ set( constitutive_sources
7575
contact/Coulomb.cpp
7676
fluid/DeadOilFluid.cpp
7777
fluid/CompressibleSinglePhaseFluid.cpp
78-
fluid/MultiPhaseMultiComponentFluid.cpp
79-
fluid/PVTFunctions/BrineCO2DensityFunction.cpp
80-
fluid/PVTFunctions/BrineViscosityFunction.cpp
81-
fluid/PVTFunctions/CO2SolubilityFunction.cpp
82-
fluid/PVTFunctions/FenghourCO2ViscosityFunction.cpp
83-
fluid/PVTFunctions/SpanWagnerCO2DensityFunction.cpp
84-
fluid/PVTFunctions/UtilityFunctions.cpp
78+
fluid/MultiPhaseMultiComponentFluid.cpp
79+
fluid/PVTFunctions/BrineCO2Density.cpp
80+
fluid/PVTFunctions/BrineViscosity.cpp
81+
fluid/PVTFunctions/CO2Solubility.cpp
82+
fluid/PVTFunctions/FenghourCO2Viscosity.cpp
83+
fluid/PVTFunctions/SpanWagnerCO2Density.cpp
8584
fluid/SingleFluidBase.cpp
8685
fluid/MultiFluidBase.cpp
8786
fluid/CompressibleSinglePhaseFluid.cpp

src/coreComponents/constitutive/docs/CO2Brine.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ where :math:`m` is the user-defined salinity.
189189
Parameters
190190
=========================
191191

192-
The model is represented by ``<MultiPhaseMultiComponentFluid>`` node in the input.
192+
The model is represented by ``<CO2BrineFluid>`` node in the input.
193193

194194
The following attributes are supported:
195195

196-
.. include:: ../../../coreComponents/fileIO/schema/docs/MultiPhaseMultiComponentFluid.rst
196+
.. include:: ../../../coreComponents/fileIO/schema/docs/CO2BrineFluid.rst
197197

198198
Supported phase names are:
199199

@@ -219,7 +219,7 @@ Example
219219
.. code-block:: xml
220220
221221
<Constitutive>
222-
<MultiPhaseMultiComponentFluid
222+
<CO2BrineFluid
223223
name="fluid"
224224
phaseNames="{ gas, water }"
225225
componentNames="{ co2, water }"

src/coreComponents/constitutive/fluid/BlackOilFluid.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class BlackOilFluid : public MultiFluidPVTPackageWrapper
3232
{
3333
public:
3434

35+
using exec_policy = serialPolicy;
36+
3537
BlackOilFluid( string const & name, Group * const parent );
3638

3739
virtual ~BlackOilFluid() override;

src/coreComponents/constitutive/fluid/CompositionalMultiphaseFluid.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class CompositionalMultiphaseFluid : public MultiFluidPVTPackageWrapper
3030
{
3131
public:
3232

33+
using exec_policy = serialPolicy;
34+
3335
CompositionalMultiphaseFluid( string const & name, Group * const parent );
3436

3537
virtual ~CompositionalMultiphaseFluid() override;

src/coreComponents/constitutive/fluid/DeadOilFluid.hpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace constitutive
3030

3131
/**
3232
* @brief Kernel wrapper class for DeadOilFluild
33-
* This kernel can be called on the GPU (after adding GEOSX_HOST_DEVICE flags in this class and in MultiFluidBase)
33+
* This kernel can be called on the GPU
3434
*/
3535
class DeadOilFluidUpdate final : public MultiFluidBaseUpdate
3636
{
@@ -122,7 +122,7 @@ class DeadOilFluidUpdate final : public MultiFluidBaseUpdate
122122
/// Deleted move assignment operator
123123
DeadOilFluidUpdate & operator=( DeadOilFluidUpdate && ) = delete;
124124

125-
//GEOSX_HOST_DEVICE
125+
GEOSX_HOST_DEVICE
126126
GEOSX_FORCE_INLINE
127127
virtual void compute( real64 const pressure,
128128
real64 const temperature,
@@ -134,7 +134,7 @@ class DeadOilFluidUpdate final : public MultiFluidBaseUpdate
134134
arraySlice2d< real64 > const & phaseCompFraction,
135135
real64 & totalDensity ) const override;
136136

137-
//GEOSX_HOST_DEVICE
137+
GEOSX_HOST_DEVICE
138138
GEOSX_FORCE_INLINE
139139
virtual void compute( real64 const pressure,
140140
real64 const temperature,
@@ -164,7 +164,7 @@ class DeadOilFluidUpdate final : public MultiFluidBaseUpdate
164164
real64 & dTotalDensity_dTemperature,
165165
arraySlice1d< real64 > const & dTotalDensity_dGlobalCompFraction ) const override;
166166

167-
//GEOSX_HOST_DEVICE
167+
GEOSX_HOST_DEVICE
168168
GEOSX_FORCE_INLINE
169169
virtual void update( localIndex const k,
170170
localIndex const q,
@@ -203,24 +203,24 @@ class DeadOilFluidUpdate final : public MultiFluidBaseUpdate
203203

204204
private:
205205

206-
//GEOSX_HOST_DEVICE
206+
GEOSX_HOST_DEVICE
207207
GEOSX_FORCE_INLINE
208208
void computeDensities( real64 pressure,
209209
arraySlice1d< real64 > const & phaseMassDens ) const;
210210

211-
//GEOSX_HOST_DEVICE
211+
GEOSX_HOST_DEVICE
212212
GEOSX_FORCE_INLINE
213213
void computeDensities( real64 pressure,
214214
arraySlice1d< real64 > const & phaseMassDens,
215215
arraySlice1d< real64 > const & dPhaseMassDens_dPres,
216216
arraySlice2d< real64 > const & dPhaseMassDens_dGlobalCompFrac ) const;
217217

218-
//GEOSX_HOST_DEVICE
218+
GEOSX_HOST_DEVICE
219219
GEOSX_FORCE_INLINE
220220
void computeViscosities( real64 pressure,
221221
arraySlice1d< real64 > const & phaseVisc ) const;
222222

223-
//GEOSX_HOST_DEVICE
223+
GEOSX_HOST_DEVICE
224224
GEOSX_FORCE_INLINE
225225
void computeViscosities( real64 pressure,
226226
arraySlice1d< real64 > const & phaseVisc,
@@ -260,6 +260,8 @@ class DeadOilFluid : public MultiFluidBase
260260
{
261261
public:
262262

263+
using exec_policy = parallelDevicePolicy<>;
264+
263265
struct PhaseType
264266
{
265267
static constexpr integer OIL = 0;
@@ -432,7 +434,7 @@ class DeadOilFluid : public MultiFluidBase
432434

433435
};
434436

435-
//GEOSX_HOST_DEVICE
437+
GEOSX_HOST_DEVICE
436438
GEOSX_FORCE_INLINE
437439
void DeadOilFluidUpdate::computeDensities( real64 pressure,
438440
arraySlice1d< real64 > const & phaseMassDens ) const
@@ -467,7 +469,7 @@ void DeadOilFluidUpdate::computeDensities( real64 pressure,
467469
}
468470
}
469471

470-
//GEOSX_HOST_DEVICE
472+
GEOSX_HOST_DEVICE
471473
GEOSX_FORCE_INLINE
472474
void DeadOilFluidUpdate::computeDensities( real64 pressure,
473475
arraySlice1d< real64 > const & phaseMassDens,
@@ -516,7 +518,7 @@ void DeadOilFluidUpdate::computeDensities( real64 pressure,
516518
}
517519
}
518520

519-
//GEOSX_HOST_DEVICE
521+
GEOSX_HOST_DEVICE
520522
GEOSX_FORCE_INLINE
521523
void DeadOilFluidUpdate::computeViscosities( real64 pressure,
522524
arraySlice1d< real64, 0 > const & phaseVisc ) const
@@ -547,7 +549,7 @@ void DeadOilFluidUpdate::computeViscosities( real64 pressure,
547549
}
548550
}
549551

550-
//GEOSX_HOST_DEVICE
552+
GEOSX_HOST_DEVICE
551553
GEOSX_FORCE_INLINE
552554
void DeadOilFluidUpdate::computeViscosities( real64 pressure,
553555
arraySlice1d< real64 > const & phaseVisc,
@@ -583,7 +585,7 @@ void DeadOilFluidUpdate::computeViscosities( real64 pressure,
583585
}
584586
}
585587

586-
//GEOSX_HOST_DEVICE
588+
GEOSX_HOST_DEVICE
587589
GEOSX_FORCE_INLINE
588590
void DeadOilFluidUpdate::compute( real64 pressure,
589591
real64 temperature,
@@ -632,7 +634,7 @@ void DeadOilFluidUpdate::compute( real64 pressure,
632634
totalDens = 1.0 / totalDens;
633635
}
634636

635-
//GEOSX_HOST_DEVICE
637+
GEOSX_HOST_DEVICE
636638
GEOSX_FORCE_INLINE
637639
void DeadOilFluidUpdate::compute( real64 pressure,
638640
real64 temperature,
@@ -660,7 +662,7 @@ void DeadOilFluidUpdate::compute( real64 pressure,
660662
real64 & totalDensity,
661663
real64 & dTotalDensity_dPressure,
662664
real64 & dTotalDensity_dTemperature,
663-
arraySlice1d< real64, 0 > const & dTotalDensity_dGlobalCompFraction ) const
665+
arraySlice1d< real64 > const & dTotalDensity_dGlobalCompFraction ) const
664666
{
665667
GEOSX_UNUSED_VAR( temperature );
666668
GEOSX_UNUSED_VAR( dPhaseFraction_dTemperature );
@@ -702,7 +704,7 @@ void DeadOilFluidUpdate::compute( real64 pressure,
702704
dPhaseFraction_dPressure[ip] = 0.0;
703705
for( localIndex ic = 0; ic < nComps; ++ic )
704706
{
705-
dPhaseFraction_dGlobalCompFraction[ip][ic] = (ip == ic) ? 1-composition[ip] : -composition[ip];
707+
dPhaseFraction_dGlobalCompFraction[ip][ic] = (ip == ic) ? 1.0 : 0.0;
706708

707709
phaseCompFraction[ip][ic] = (ip == ic) ? 1.0 : 0.0;
708710
dPhaseCompFraction_dPressure[ip][ic] = 0.0;

src/coreComponents/constitutive/fluid/MultiFluidBase.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class MultiFluidBaseUpdate
163163

164164
private:
165165

166+
GEOSX_HOST_DEVICE
166167
virtual void compute( real64 const pressure,
167168
real64 const temperature,
168169
arraySlice1d< real64 const > const & composition,
@@ -173,6 +174,7 @@ class MultiFluidBaseUpdate
173174
arraySlice2d< real64 > const & phaseCompFraction,
174175
real64 & totalDensity ) const = 0;
175176

177+
GEOSX_HOST_DEVICE
176178
virtual void compute( real64 const pressure,
177179
real64 const temperature,
178180
arraySlice1d< real64 const > const & composition,
@@ -201,12 +203,12 @@ class MultiFluidBaseUpdate
201203
real64 & dTotalDensity_dTemperature,
202204
arraySlice1d< real64 > const & dTotalDensity_dGlobalCompFraction ) const = 0;
203205

206+
GEOSX_HOST_DEVICE
204207
virtual void update( localIndex const k,
205208
localIndex const q,
206209
real64 const pressure,
207210
real64 const temperature,
208211
arraySlice1d< real64 const > const & composition ) const = 0;
209-
210212
};
211213

212214
class MultiFluidBase : public ConstitutiveBase

src/coreComponents/constitutive/fluid/MultiFluidPVTPackageWrapper.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ MultiFluidPVTPackageWrapper::deliverClone( string const & name,
8181
return clone;
8282
}
8383

84+
GEOSX_HOST_DEVICE
8485
void MultiFluidPVTPackageWrapperUpdate::compute( real64 pressure,
8586
real64 temperature,
8687
arraySlice1d< real64 const > const & composition,
@@ -91,6 +92,9 @@ void MultiFluidPVTPackageWrapperUpdate::compute( real64 pressure,
9192
arraySlice2d< real64 > const & phaseCompFrac,
9293
real64 & totalDens ) const
9394
{
95+
#if defined(__CUDA_ARCH__)
96+
GEOSX_ERROR( "This function cannot be used on GPU" );
97+
#else
9498
localIndex const NC = m_componentMolarWeight.size();
9599
localIndex const NP = m_phaseTypes.size();
96100

@@ -195,8 +199,10 @@ void MultiFluidPVTPackageWrapperUpdate::compute( real64 pressure,
195199
// 5.2. Invert the previous quantity to get actual density
196200
totalDens = 1.0 / totalDens;
197201
}
202+
#endif
198203
}
199204

205+
GEOSX_HOST_DEVICE
200206
void MultiFluidPVTPackageWrapperUpdate::compute( real64 pressure,
201207
real64 temperature,
202208
arraySlice1d< real64 const > const & composition,
@@ -225,6 +231,9 @@ void MultiFluidPVTPackageWrapperUpdate::compute( real64 pressure,
225231
real64 & dTotalDensity_dTemperature,
226232
arraySlice1d< real64 > const & dTotalDensity_dGlobalCompFraction ) const
227233
{
234+
#if defined(__CUDA_ARCH__)
235+
GEOSX_ERROR( "This function cannot be used on GPU" );
236+
#else
228237
// 0. make shortcut structs to avoid long names (TODO maybe remove)
229238
CompositionalVarContainer< 1 > phaseFrac{
230239
phaseFraction,
@@ -268,11 +277,6 @@ void MultiFluidPVTPackageWrapperUpdate::compute( real64 pressure,
268277
dTotalDensity_dGlobalCompFraction
269278
};
270279

271-
#if defined(__CUDACC__)
272-
// For some reason nvcc thinks these aren't used.
273-
GEOSX_UNUSED_VAR( phaseFrac, phaseDens, phaseMassDens, phaseVisc, phaseCompFrac, totalDens );
274-
#endif
275-
276280
localIndex constexpr maxNumComp = MultiFluidBase::MAX_NUM_COMPONENTS;
277281
localIndex const NC = numComponents();
278282
localIndex const NP = numPhases();
@@ -489,6 +493,7 @@ void MultiFluidPVTPackageWrapperUpdate::compute( real64 pressure,
489493
totalDens.dComp[jc] *= minusDens2;
490494
}
491495
}
496+
#endif
492497
}
493498

494499
} //namespace constitutive

src/coreComponents/constitutive/fluid/MultiFluidPVTPackageWrapper.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class MultiFluidPVTPackageWrapperUpdate final : public MultiFluidBaseUpdate
117117
/// Deleted move assignment operator
118118
MultiFluidPVTPackageWrapperUpdate & operator=( MultiFluidPVTPackageWrapperUpdate && ) = delete;
119119

120+
GEOSX_HOST_DEVICE
120121
virtual void compute( real64 const pressure,
121122
real64 const temperature,
122123
arraySlice1d< real64 const > const & composition,
@@ -127,6 +128,7 @@ class MultiFluidPVTPackageWrapperUpdate final : public MultiFluidBaseUpdate
127128
arraySlice2d< real64 > const & phaseCompFraction,
128129
real64 & totalDensity ) const override;
129130

131+
GEOSX_HOST_DEVICE
130132
virtual void compute( real64 const pressure,
131133
real64 const temperature,
132134
arraySlice1d< real64 const > const & composition,
@@ -155,6 +157,7 @@ class MultiFluidPVTPackageWrapperUpdate final : public MultiFluidBaseUpdate
155157
real64 & dTotalDensity_dTemperature,
156158
arraySlice1d< real64 > const & dTotalDensity_dGlobalCompFraction ) const override;
157159

160+
GEOSX_HOST_DEVICE
158161
GEOSX_FORCE_INLINE
159162
virtual void update( localIndex const k,
160163
localIndex const q,

0 commit comments

Comments
 (0)