Skip to content

Commit 85fecab

Browse files
committed
feat: add mixed system.
1 parent 47aadc3 commit 85fecab

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#pragma once
2+
3+
#include "common/macros.hpp"
4+
5+
/** @file MixedEquilibriumKineticReactions.hpp
6+
* @brief Header file for the MixedEquilibriumKineticReactions class.
7+
* @author HPC-REACT Team
8+
* @date 2025
9+
*/
10+
11+
namespace hpcReact
12+
{
13+
namespace bulkGeneric
14+
{
15+
16+
/**
17+
* @brief Class for computing reaction rates and species rates for a given set of reactions.
18+
* @tparam REAL_TYPE The type of the real numbers used in the class.
19+
* @tparam INT_TYPE The type of the integer numbers used in the class.
20+
* @tparam INDEX_TYPE The type of the index used in the class.
21+
* @tparam LOGE_CONCENTRATION Whether to use logarithm of concentration for the calculations.
22+
* @details
23+
* This class provides the ablity to compute kinetic reactions.
24+
*/
25+
template< typename REAL_TYPE,
26+
typename INT_TYPE,
27+
typename INDEX_TYPE,
28+
bool LOGE_CONCENTRATION >
29+
class MixedEquilibriumKineticReactions
30+
{
31+
public:
32+
33+
/// Type alias for the real type used in the class.
34+
using RealType = REAL_TYPE;
35+
36+
/// Type alias for the integer type used in the class.
37+
using IntType = INT_TYPE;
38+
39+
/// Type alias for the index type used in the class.
40+
using IndexType = INDEX_TYPE;
41+
42+
using kineticReactions = KineticReactions< REAL_TYPE, INT_TYPE, INDEX_TYPE, LOGE_CONCENTRATION >;
43+
44+
template< typename PARAMS_DATA,
45+
typename ARRAY_1D_TO_CONST,
46+
typename ARRAY_1D,
47+
typename ARRAY_2D >
48+
static HPCREACT_HOST_DEVICE inline void
49+
updateMixedSystem( RealType const & temperature,
50+
PARAMS_DATA const & params,
51+
ARRAY_1D_TO_CONST const & logPrimarySpeciesConcentrations,
52+
ARRAY_1D & logSecondarySpeciesConcentrations,
53+
ARRAY_1D & aggregatePrimarySpeciesConcentrations,
54+
ARRAY_2D & dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations,
55+
ARRAY_1D & reactionRates,
56+
ARRAY_2D & reactionRatesDerivatives )
57+
{
58+
constexpr int numSpecies = PARAMS_DATA::numSpecies;
59+
constexpr int numSecondarySpecies = PARAMS_DATA::numReactions;
60+
constexpr int numPrimarySpecies = numSpecies - numSecondarySpecies;
61+
62+
// 1. Compute new aggregate species from primary species
63+
calculateAggregatePrimaryConcentrationsWrtLogC< REAL_TYPE,
64+
INT_TYPE,
65+
INDEX_TYPE >( params,
66+
logPrimarySpeciesConcentrations,
67+
logSecondarySpeciesConcentrations,
68+
aggregatePrimarySpeciesConcentrations,
69+
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations )
70+
71+
// 2. Compute the reaction rates for all kinetic reactions
72+
kineticReactions::computeReactionRates( temperature,
73+
params,
74+
speciesConcentration,
75+
reactionRates,
76+
reactionRatesDerivatives );
77+
78+
// 3. Compute aggregate species rates
79+
80+
81+
}
82+
83+
private:
84+
85+
};
86+
87+
} // namespace bulkGeneric
88+
} // namespace hpcReact
89+
90+
#include "MixedEquilibriumKineticReactions_impl.hpp"
91+
#include "common/macrosCleanup.hpp"

src/reactions/bulkGeneric/SpeciesUtilities.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,51 @@ void calculateLogSecondarySpeciesConcentrationWrtLogC( PARAMS_DATA const & param
8989
} );
9090
}
9191

92+
template< typename REAL_TYPE,
93+
typename INT_TYPE,
94+
typename INDEX_TYPE,
95+
typename PARAMS_DATA,
96+
typename ARRAY_1D_TO_CONST,
97+
typename ARRAY_1D,
98+
typename ARRAY_2D >
99+
HPCREACT_HOST_DEVICE
100+
inline
101+
void calculateAggregatePrimaryConcentrationsWrtLogC( PARAMS_DATA const & params,
102+
ARRAY_1D_TO_CONST const & logPrimarySpeciesConcentrations,
103+
ARRAY_1D & logSecondarySpeciesConcentrations,
104+
ARRAY_1D & aggregatePrimarySpeciesConcentrations,
105+
ARRAY_2D & dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations )
106+
{
107+
constexpr int numSpecies = PARAMS_DATA::numSpecies;
108+
constexpr int numSecondarySpecies = PARAMS_DATA::numReactions;
109+
constexpr int numPrimarySpecies = numSpecies - numSecondarySpecies;
110+
111+
calculateLogSecondarySpeciesConcentration< REAL_TYPE,
112+
INT_TYPE,
113+
INDEX_TYPE >( params,
114+
logPrimarySpeciesConcentrations,
115+
logSecondarySpeciesConcentrations );
116+
117+
for( int i = 0; i < numPrimarySpecies; ++i )
118+
{
119+
REAL_TYPE const speciesConcentration_i = exp( logPrimarySpeciesConcentrations[i] );
120+
aggregatePrimarySpeciesConcentrations[i] = speciesConcentration_i;
121+
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations( i, i ) = speciesConcentration_i;
122+
for( int j = 0; j < numSecondarySpecies; ++j )
123+
{
124+
REAL_TYPE const secondarySpeciesConcentrations_j = exp( logSecondarySpeciesConcentrations[j] );
125+
aggregatePrimarySpeciesConcentrations[i] += params.stoichiometricMatrix( j, i+numSecondarySpecies ) * secondarySpeciesConcentrations_j;
126+
for( int k=0; k<numPrimarySpecies; ++k )
127+
{
128+
REAL_TYPE const dSecondarySpeciesConcentrations_dLogPrimarySpeciesConcentration = params.stoichiometricMatrix( j, k+numSecondarySpecies ) * secondarySpeciesConcentrations_j;
129+
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations( i, k ) += params.stoichiometricMatrix( j,
130+
i+numSecondarySpecies ) *
131+
dSecondarySpeciesConcentrations_dLogPrimarySpeciesConcentration;
132+
}
133+
}
134+
}
135+
}
136+
92137
template< typename REAL_TYPE,
93138
typename INT_TYPE,
94139
typename INDEX_TYPE,

0 commit comments

Comments
 (0)