Skip to content

Commit 74925cf

Browse files
committed
modified computeReactionRatesTest and added a new test for chain reaction
1 parent 1a38752 commit 74925cf

13 files changed

+134
-40
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******

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: 14 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,10 +83,12 @@ 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
}

src/reactions/massActions/MassActions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void calculateLogSecondarySpeciesConcentration( PARAMS_DATA const & params,
7676
{
7777
return;
7878
}
79-
79+
8080
massActions_impl::calculateLogSecondarySpeciesConcentration< REAL_TYPE,
8181
INT_TYPE,
8282
INDEX_TYPE >( params,

src/reactions/reactionsSystems/EquilibriumReactionsAggregatePrimaryConcentration_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ EquilibriumReactions< REAL_TYPE,
115115
{
116116
if constexpr( PARAMS_DATA::numSecondarySpecies() <= 0 )
117117
{
118-
return;
118+
return;
119119
}
120-
120+
121121
HPCREACT_UNUSED_VAR( temperature );
122122
constexpr int numPrimarySpecies = PARAMS_DATA::numPrimarySpecies();
123123

src/reactions/reactionsSystems/KineticReactions.hpp

Lines changed: 23 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,27 @@ 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+
}
152+
else
153+
{
154+
throw std::runtime_error( "Error: No such option implemented so far for reaction rate calculation." );
155+
}
139156
}
140157

141158

src/reactions/reactionsSystems/KineticReactions_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ KineticReactions< REAL_TYPE,
271271
RealType const productTerm_i = speciesConcentration[i] > 1e-100 ? pow( speciesConcentration[i], s_ri ) : 0.0;
272272
quotient *= productTerm_i;
273273
}
274-
274+
275275
if constexpr( CALCULATE_DERIVATIVES )
276276
{
277277
for( IntType i = 0; i < PARAMS_DATA::numSpecies(); ++i )

0 commit comments

Comments
 (0)