Skip to content

Commit 2b2aeaf

Browse files
authored
Generic Chain Reaction for Kinetic Reaction Verification (#13)
* cleaned up momas and added medium test case * added 3 species full kinetic serial chain reaction * added an option variable for user-defined kinetic rate calculation method * modified computeReactionRatesTest and added a new test for chain reaction * added a kinetic reaction test to call quotient reaction rate compute
1 parent 7f370aa commit 2b2aeaf

14 files changed

+293
-33
lines changed

src/reactions/exampleSystems/BulkGeneric.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ simpleKineticTestRateParams =
6363
// reverse rate constants
6464
{ 1.0, 0.5 },
6565
// flag of mobile secondary species
66-
{ 1, 1 }
66+
{ 1, 1 },
67+
// Use the forward and reverse to calculate the kinetic reaction rates
68+
0
6769
};
6870

6971
using simpleTestType = reactionsSystems::MixedReactionsParameters< double, int, int, 5, 2, 2 >;
@@ -84,7 +86,9 @@ simpleTestRateParams =
8486
// reverse rate constants
8587
{ 1.0, 0.5 },
8688
// flag of mobile secondary species
87-
{ 1, 1 }
89+
{ 1, 1 },
90+
// Use the forward and reverse to calculate the kinetic reaction rates
91+
0
8892
};
8993

9094
// *****UNCRUSTIFY-ON******
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* ------------------------------------------------------------------------------------------------------------
3+
* SPDX-License-Identifier: (BSD-3-Clause)
4+
*
5+
* Copyright (c) 2025- Lawrence Livermore National Security LLC
6+
* All rights reserved
7+
*
8+
* See top level LICENSE files for details.
9+
* ------------------------------------------------------------------------------------------------------------
10+
*/
11+
12+
#pragma once
13+
14+
#include "../reactionsSystems/Parameters.hpp"
15+
16+
namespace hpcReact
17+
{
18+
namespace ChainGeneric
19+
{
20+
// *****UNCRUSTIFY-OFF******
21+
22+
using serialAllKineticType = reactionsSystems::MixedReactionsParameters< double, int, int, 3, 3, 0 >;
23+
24+
constexpr serialAllKineticType serialAllKineticParams =
25+
{
26+
// Stoichiometric matrix [3 rows × 3 columns]
27+
// Columns 0–3 are primary species: {C1, C2, C3 }
28+
{
29+
// C1 C2 C3
30+
{ -1, 1, 0 }, // C1 = C2
31+
{ 0, -1, 1 }, // C2 = C3
32+
{ 0, 0, -1 }, // C3 =
33+
},
34+
35+
// Equilibrium constants K
36+
{
37+
0, // C1 = C2
38+
0, // C2 = C3
39+
0 // C3
40+
},
41+
42+
// Forward rate constants
43+
{
44+
0.05, // C1 = C2
45+
0.03, // C2 = C3
46+
0.02, // C3
47+
},
48+
49+
// Reverse rate constants
50+
{
51+
0.0, // C1 = C2
52+
0.0, // C2 = C3
53+
0.0 // C3
54+
},
55+
56+
// Flag of mobile secondary species
57+
{
58+
1, // C1 = C2
59+
1, // C2 = C3
60+
1 // C3
61+
},
62+
63+
0 // Use the forward and reverse to calculate the kinetic reaction rates
64+
};
65+
66+
// *****UNCRUSTIFY-ON******
67+
} // namespace ChainGeneric
68+
} // namespace hpcReact

src/reactions/exampleSystems/unitTests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set( testSourceFiles
44
testKineticReactions.cpp
55
testMomasEasyCase.cpp
66
testMomasMediumCase.cpp
7+
testGenericChainReactions.cpp
78
)
89

910
set( dependencyList hpcReact gtest )
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* ------------------------------------------------------------------------------------------------------------
3+
* SPDX-License-Identifier: (BSD-3-Clause)
4+
*
5+
* Copyright (c) 2025- Lawrence Livermore National Security LLC
6+
* All rights reserved
7+
*
8+
* See top level LICENSE files for details.
9+
* ------------------------------------------------------------------------------------------------------------
10+
*/
11+
12+
#include "reactions/unitTestUtilities/kineticReactionsTestUtilities.hpp"
13+
#include "../ChainGeneric.hpp"
14+
15+
16+
using namespace hpcReact;
17+
using namespace hpcReact::unitTest_utilities;
18+
19+
//******************************************************************************
20+
TEST( testChainGenericKineticReactions, computeReactionRatesTest_chainReactionParams )
21+
{
22+
using namespace hpcReact::ChainGeneric;
23+
24+
double const initialSpeciesConcentration[] =
25+
{
26+
1.0, // C1
27+
1e-8, // C2
28+
1e-8 // C3
29+
};
30+
double const surfaceArea[] =
31+
{
32+
0.0, // C1 -> C2
33+
0.0, // C2 -> C3
34+
0.0 // C3 ->
35+
};
36+
37+
double const expectedReactionRates[] =
38+
{
39+
0.05, // C1 -> C2
40+
3e-10, // C2 -> C3
41+
2e-10 // C3 ->
42+
};
43+
double const expectedReactionRatesDerivatives[][3] =
44+
{ { 0.05, 0.0, 0.0 },
45+
{ 0.0, 0.03, 0.0 },
46+
{ 0.0, 0.0, 0.02 } };
47+
computeReactionRatesTest< double, false >( serialAllKineticParams.kineticReactionsParameters(),
48+
initialSpeciesConcentration,
49+
surfaceArea, // No use. Just to pass something here
50+
expectedReactionRates,
51+
expectedReactionRatesDerivatives );
52+
computeReactionRatesTest< double, true >( serialAllKineticParams.kineticReactionsParameters(),
53+
initialSpeciesConcentration,
54+
surfaceArea, // No use. Just to pass something here
55+
expectedReactionRates,
56+
expectedReactionRatesDerivatives );
57+
}
58+
59+
int main( int argc, char * * argv )
60+
{
61+
::testing::InitGoogleTest( &argc, argv );
62+
int const result = RUN_ALL_TESTS();
63+
return result;
64+
}

src/reactions/exampleSystems/unitTests/testKineticReactions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ using namespace hpcReact::unitTest_utilities;
2424
TEST( testKineticReactions, computeReactionRatesTest_simpleKineticTestRateParams )
2525
{
2626
double const initialSpeciesConcentration[] = { 1.0, 1.0e-16, 0.5, 1.0, 1.0e-16 };
27+
double const surfaceArea[] = { 0.0, 0.0 };
2728
double const expectedReactionRates[] = { 1.0, 0.25 };
2829
double const expectedReactionRatesDerivatives[][5] =
2930
{ { 2.0, -0.5, 0.0, 0.0, 0.0 },
3031
{ 0.0, 0.0, 0.5, 0.25, 0.0 } };
3132
computeReactionRatesTest< double, false >( bulkGeneric::simpleKineticTestRateParams.kineticReactionsParameters(),
3233
initialSpeciesConcentration,
34+
surfaceArea, // No use. Just to pass something here
3335
expectedReactionRates,
3436
expectedReactionRatesDerivatives );
3537
computeReactionRatesTest< double, true >( bulkGeneric::simpleKineticTestRateParams.kineticReactionsParameters(),
3638
initialSpeciesConcentration,
39+
surfaceArea, // No use. Just to pass something here
3740
expectedReactionRates,
3841
expectedReactionRatesDerivatives );
3942
}

src/reactions/geochemistry/Carbonate.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ using carbonateSystemAllKineticType = reactionsSystems::MixedReactionsParame
113113
using carbonateSystemAllEquilibriumType = reactionsSystems::MixedReactionsParameters< double, int, int, 17, 10, 10 >;
114114
using carbonateSystemType = reactionsSystems::MixedReactionsParameters< double, int, int, 16, 10, 9 >;
115115

116-
constexpr carbonateSystemAllKineticType carbonateSystemAllKinetic( carbonate::stoichMatrix, carbonate::equilibriumConstants, carbonate::forwardRates, carbonate::reverseRates, carbonate::mobileSpeciesFlag );
116+
constexpr carbonateSystemAllKineticType carbonateSystemAllKinetic( carbonate::stoichMatrix, carbonate::equilibriumConstants, carbonate::forwardRates, carbonate::reverseRates, carbonate::mobileSpeciesFlag, 0 );
117117
constexpr carbonateSystemAllEquilibriumType carbonateSystemAllEquilibrium( carbonate::stoichMatrix, carbonate::equilibriumConstants, carbonate::forwardRates, carbonate::reverseRates, carbonate::mobileSpeciesFlag );
118118
constexpr carbonateSystemType carbonateSystem( carbonate::stoichMatrixNosolid, carbonate::equilibriumConstants, carbonate::forwardRates, carbonate::reverseRates, carbonate::mobileSpeciesFlag );
119119

src/reactions/geochemistry/unitTests/testGeochemicalKineticReactions.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ TEST( testKineticReactions, computeReactionRatesTest_carbonateSystemAllKinetic )
4343
1.09 // Na+1
4444
};
4545

46+
double const surfaceArea[10] = { 0.0, // OH- + H+ = H2O
47+
0.0, // CO2 + H2O = H+ + HCO3-
48+
0.0, // CO3-2 + H+ = HCO3-
49+
0.0, // CaHCO3+ = Ca+2 + HCO3-
50+
0.0, // CaSO4 = Ca+2 + SO4-2
51+
0.0, // CaCl+ = Ca+2 + Cl-
52+
0.0, // CaCl2 = Ca+2 + 2Cl-
53+
0.0, // MgSO4 = Mg+2 + SO4-2
54+
0.0, // NaSO4- = Na+ + SO4-2
55+
0.0, // CaCO3 + H+ = Ca+2 + HCO3- (kinetic)
56+
};
57+
4658
double const expectedReactionRates[10] = { -0.001424736, // OH- + H+ = H2O
4759
-12610.7392, // CO2 + H2O = H+ + HCO3-
4860
-0.175591624, // CO3-2 + H+ = HCO3-
@@ -71,15 +83,58 @@ TEST( testKineticReactions, computeReactionRatesTest_carbonateSystemAllKinetic )
7183

7284
computeReactionRatesTest< double, false >( carbonateSystemAllKinetic.kineticReactionsParameters(),
7385
initialSpeciesConcentration,
86+
surfaceArea, // No use. Just to pass something here
7487
expectedReactionRates,
7588
expectedReactionRatesDerivatives );
7689
computeReactionRatesTest< double, true >( carbonateSystemAllKinetic.kineticReactionsParameters(),
7790
initialSpeciesConcentration,
91+
surfaceArea, // No use. Just to pass something here
7892
expectedReactionRates,
7993
expectedReactionRatesDerivatives );
8094
}
8195

96+
TEST( testKineticReactions, computeReactionRatesQuotientTest_carbonateSystem )
97+
{
98+
double const initialSpeciesConcentration[16] =
99+
{
100+
1.0e-16, // OH-
101+
1.0e-16, // CO2
102+
1.0e-16, // CO3-2
103+
1.0e-16, // CaHCO3+
104+
1.0e-16, // CaSO4
105+
1.0e-16, // CaCl+
106+
1.0e-16, // CaCl2
107+
1.0e-16, // MgSO4
108+
1.0e-16, // NaSO4-
109+
3.76e-1, // H+
110+
3.76e-1, // HCO3-
111+
3.87e-2, // Ca+2
112+
3.21e-2, // SO4-2
113+
1.89, // Cl-
114+
1.65e-2, // Mg+2
115+
1.09 // Na+1
116+
};
117+
118+
double const surfaceArea[1] = { 1e6 }; // CaCO3 + H+ = Ca+2 + HCO3- (kinetic)
119+
120+
double const expectedReactionRates[1] = { 1.5488389999999999 }; // CaCO3 + H+ = Ca+2 + HCO3- (kinetic)
121+
122+
double const expectedReactionRatesDerivatives[1][16] =
123+
{
124+
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.0877659574468075e-03, -3.0877659574468075e-03, -2.9999999999999997e-02, 0, 0, 0, 0 }
125+
};
82126

127+
computeReactionRatesTest< double, false >( carbonateSystem.kineticReactionsParameters(),
128+
initialSpeciesConcentration,
129+
surfaceArea,
130+
expectedReactionRates,
131+
expectedReactionRatesDerivatives );
132+
computeReactionRatesTest< double, true >( carbonateSystem.kineticReactionsParameters(),
133+
initialSpeciesConcentration,
134+
surfaceArea,
135+
expectedReactionRates,
136+
expectedReactionRatesDerivatives );
137+
}
83138

84139
//******************************************************************************
85140

src/reactions/massActions/MassActions.hpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ void calculateLogSecondarySpeciesConcentration( PARAMS_DATA const & params,
7272
ARRAY_1D_TO_CONST const & logPrimarySpeciesConcentrations,
7373
ARRAY_1D & logSecondarySpeciesConcentrations )
7474
{
75+
if constexpr( PARAMS_DATA::numSecondarySpecies() <= 0 )
76+
{
77+
return;
78+
}
79+
7580
massActions_impl::calculateLogSecondarySpeciesConcentration< REAL_TYPE,
7681
INT_TYPE,
7782
INDEX_TYPE >( params,
@@ -173,15 +178,22 @@ void calculateAggregatePrimaryConcentrationsWrtLogC( PARAMS_DATA const & params,
173178
{
174179
static constexpr int numSecondarySpecies = PARAMS_DATA::numSecondarySpecies();
175180

176-
REAL_TYPE logSecondarySpeciesConcentrations[numSecondarySpecies] = {0};
181+
if constexpr( numSecondarySpecies > 0 )
182+
{
183+
REAL_TYPE logSecondarySpeciesConcentrations[numSecondarySpecies] = {0};
177184

178-
calculateAggregatePrimaryConcentrationsWrtLogC< REAL_TYPE,
179-
INT_TYPE,
180-
INDEX_TYPE >( params,
181-
logPrimarySpeciesConcentrations,
182-
logSecondarySpeciesConcentrations,
183-
aggregatePrimarySpeciesConcentrations,
184-
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations );
185+
calculateAggregatePrimaryConcentrationsWrtLogC< REAL_TYPE,
186+
INT_TYPE,
187+
INDEX_TYPE >( params,
188+
logPrimarySpeciesConcentrations,
189+
logSecondarySpeciesConcentrations,
190+
aggregatePrimarySpeciesConcentrations,
191+
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations );
192+
}
193+
else
194+
{
195+
GEOS_UNUSED_VAR( logPrimarySpeciesConcentrations, aggregatePrimarySpeciesConcentrations, dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations );
196+
}
185197

186198
}
187199

src/reactions/reactionsSystems/EquilibriumReactionsAggregatePrimaryConcentration_impl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ EquilibriumReactions< REAL_TYPE,
113113
ARRAY_1D_TO_CONST const & logPrimarySpeciesConcentration0,
114114
ARRAY_1D & logPrimarySpeciesConcentration )
115115
{
116+
if constexpr( PARAMS_DATA::numSecondarySpecies() <= 0 )
117+
{
118+
return;
119+
}
120+
116121
HPCREACT_UNUSED_VAR( temperature );
117122
static constexpr int numPrimarySpecies = PARAMS_DATA::numPrimarySpecies();
118123

src/reactions/reactionsSystems/KineticReactions.hpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include "common/macros.hpp"
1515

16+
#include <stdexcept>
17+
1618
/** @file KineticReactions.hpp
1719
* @brief Header file for the KineticReactions class.
1820
* @author HPC-REACT Team
@@ -130,12 +132,23 @@ class KineticReactions
130132
ARRAY_1D & reactionRates,
131133
ARRAY_2D & reactionRatesDerivatives )
132134
{
133-
computeReactionRatesQuotient_impl< PARAMS_DATA, true >( temperature,
134-
params,
135-
speciesConcentration,
136-
surfaceArea,
137-
reactionRates,
138-
reactionRatesDerivatives );
135+
if( params.reactionRatesUpdateOption() == 0 )
136+
{
137+
computeReactionRates_impl< PARAMS_DATA, true >( temperature,
138+
params,
139+
speciesConcentration,
140+
reactionRates,
141+
reactionRatesDerivatives );
142+
}
143+
else if( params.reactionRatesUpdateOption() == 1 )
144+
{
145+
computeReactionRatesQuotient_impl< PARAMS_DATA, true >( temperature,
146+
params,
147+
speciesConcentration,
148+
surfaceArea,
149+
reactionRates,
150+
reactionRatesDerivatives );
151+
}
139152
}
140153

141154

0 commit comments

Comments
 (0)