@@ -13,40 +13,6 @@ namespace massActions
1313namespace massActions_impl
1414{
1515
16- template < typename REAL_TYPE,
17- typename INT_TYPE,
18- typename INDEX_TYPE,
19- typename PARAMS_DATA,
20- typename ARRAY_1D_TO_CONST,
21- typename ARRAY_1D,
22- typename FUNC >
23- HPCREACT_HOST_DEVICE
24- inline
25- void calculateLogSecondarySpeciesConcentration ( PARAMS_DATA const & params,
26- ARRAY_1D_TO_CONST const & logPrimarySpeciesConcentrations,
27- ARRAY_1D & logSecondarySpeciesConcentrations,
28- FUNC && derivativeFunc )
29- {
30- constexpr int numSecondarySpecies = PARAMS_DATA::numSecondarySpecies ();
31- constexpr int numPrimarySpecies = PARAMS_DATA::numPrimarySpecies ();
32-
33- for (INDEX_TYPE i = 0 ; i < numSecondarySpecies; ++i)
34- {
35- logSecondarySpeciesConcentrations[i] = 0.0 ;
36- }
37-
38- for ( int j=0 ; j<numSecondarySpecies; ++j )
39- {
40- REAL_TYPE const gamma = 1 ;
41- logSecondarySpeciesConcentrations[j] = -log ( params.equilibriumConstant ( j ) ) - log ( gamma );
42- for ( int k=0 ; k<numPrimarySpecies; ++k )
43- {
44- logSecondarySpeciesConcentrations[j] += params.stoichiometricMatrix ( j, k+numSecondarySpecies ) * ( logPrimarySpeciesConcentrations[k] + log ( gamma ) );
45- derivativeFunc ( j, k, params.stoichiometricMatrix ( j, k+numSecondarySpecies ) );
46- }
47- }
48- }
49-
5016// template< typename REAL_TYPE,
5117// typename INT_TYPE,
5218// typename INDEX_TYPE,
@@ -61,45 +27,79 @@ void calculateLogSecondarySpeciesConcentration( PARAMS_DATA const & params,
6127// ARRAY_1D & logSecondarySpeciesConcentrations,
6228// FUNC && derivativeFunc )
6329// {
64- // constexpr INDEX_TYPE numSecondarySpecies = PARAMS_DATA::numSecondarySpecies();
65- // constexpr INDEX_TYPE numPrimarySpecies = PARAMS_DATA::numPrimarySpecies();
66- // constexpr INDEX_TYPE numAqueousReactions = PARAMS_DATA::numAqueousReactions();
67- // constexpr INDEX_TYPE numSurfaceReactions = PARAMS_DATA::numSurfaceReactions();
68-
69- // // Initialize
70- // for ( INDEX_TYPE i = 0; i < numSecondarySpecies; ++i )
30+ // constexpr int numSecondarySpecies = PARAMS_DATA::numSecondarySpecies();
31+ // constexpr int numPrimarySpecies = PARAMS_DATA::numPrimarySpecies();
32+
33+ // for (INDEX_TYPE i = 0; i < numSecondarySpecies; ++i)
7134// {
7235// logSecondarySpeciesConcentrations[i] = 0.0;
7336// }
7437
75- // // Aqueous reactions
76- // for ( INDEX_TYPE j = 0; j < numAqueousReactions; ++j )
38+ // for( int j=0; j<numSecondarySpecies; ++j )
7739// {
78- // logSecondarySpeciesConcentrations[j] = -log( params.equilibriumConstant(j) );
79- // for ( INDEX_TYPE k = 0; k < numPrimarySpecies; ++k )
40+ // REAL_TYPE const gamma = 1;
41+ // logSecondarySpeciesConcentrations[j] = -log( params.equilibriumConstant( j ) ) - log( gamma );
42+ // for( int k=0; k<numPrimarySpecies; ++k )
8043// {
81- // auto const coeff = params.stoichiometricMatrix( j, k + numSecondarySpecies );
82- // logSecondarySpeciesConcentrations[j] += coeff * logPrimarySpeciesConcentrations[k];
83- // derivativeFunc( j, k, coeff );
44+ // logSecondarySpeciesConcentrations[j] += params.stoichiometricMatrix( j, k+numSecondarySpecies ) * ( logPrimarySpeciesConcentrations[k] + log( gamma ) );
45+ // derivativeFunc( j, k, params.stoichiometricMatrix( j, k+numSecondarySpecies ) );
8446// }
8547// }
48+ // }
8649
87- // // Surface reactions
88- // for ( INDEX_TYPE j = 0; j < numSurfaceReactions; ++j )
89- // {
90- // INDEX_TYPE const jGlobal = j + numAqueousReactions;
91- // logSecondarySpeciesConcentrations[jGlobal] = -log( params.equilibriumConstant(jGlobal) );
92- // for ( INDEX_TYPE k = 0; k < numPrimarySpecies; ++k )
93- // {
94- // auto const coeff = params.stoichiometricMatrix( jGlobal, k + numSecondarySpecies );
95- // logSecondarySpeciesConcentrations[jGlobal] += coeff * logPrimarySpeciesConcentrations[k];
96- // derivativeFunc( jGlobal, k, coeff );
97- // }
50+ template < typename REAL_TYPE,
51+ typename INT_TYPE,
52+ typename INDEX_TYPE,
53+ typename PARAMS_DATA,
54+ typename ARRAY_1D_TO_CONST,
55+ typename ARRAY_1D,
56+ typename FUNC >
57+ HPCREACT_HOST_DEVICE
58+ inline
59+ void calculateLogSecondarySpeciesConcentration ( PARAMS_DATA const & params,
60+ ARRAY_1D_TO_CONST const & logPrimarySpeciesConcentrations,
61+ ARRAY_1D & logSecondarySpeciesConcentrations,
62+ FUNC && derivativeFunc )
63+ {
64+ constexpr INDEX_TYPE numSecondarySpecies = PARAMS_DATA::numSecondarySpecies ();
65+ constexpr INDEX_TYPE numPrimarySpecies = PARAMS_DATA::numPrimarySpecies ();
66+ constexpr INDEX_TYPE numAqueousReactions = PARAMS_DATA::numAqueousReactions ();
67+ constexpr INDEX_TYPE numSurfaceReactions = PARAMS_DATA::numSurfaceReactions ();
68+
69+ // Initialize
70+ for ( INDEX_TYPE i = 0 ; i < numSecondarySpecies; ++i )
71+ {
72+ logSecondarySpeciesConcentrations[i] = 0.0 ;
73+ }
9874
99- // // Add log(S) from last part of the array
100- // logSecondarySpeciesConcentrations[jGlobal] += params.surfaceStoichiometry(j) * logSecondarySpeciesConcentrations[ numAqueousReactions + j];
101- // }
102- // }
75+ // Aqueous reactions
76+ for ( INDEX_TYPE j = 0 ; j < numAqueousReactions; ++j )
77+ {
78+ logSecondarySpeciesConcentrations[j] = -log ( params.equilibriumConstant (j) );
79+ for ( INDEX_TYPE k = 0 ; k < numPrimarySpecies; ++k )
80+ {
81+ auto const coeff = params.stoichiometricMatrix ( j, k + numSecondarySpecies );
82+ logSecondarySpeciesConcentrations[j] += coeff * logPrimarySpeciesConcentrations[k];
83+ derivativeFunc ( j, k, coeff );
84+ }
85+ }
86+
87+ // Surface reactions
88+ for ( INDEX_TYPE j = 0 ; j < numSurfaceReactions; ++j )
89+ {
90+ INDEX_TYPE const jGlobal = j + numAqueousReactions;
91+ logSecondarySpeciesConcentrations[jGlobal] = -log ( params.equilibriumConstant (jGlobal) );
92+ for ( INDEX_TYPE k = 0 ; k < numPrimarySpecies; ++k )
93+ {
94+ auto const coeff = params.stoichiometricMatrix ( jGlobal, k + numSecondarySpecies );
95+ logSecondarySpeciesConcentrations[jGlobal] += coeff * logPrimarySpeciesConcentrations[k];
96+ derivativeFunc ( jGlobal, k, coeff );
97+ }
98+
99+ // Add log(S) from last part of the array
100+ logSecondarySpeciesConcentrations[jGlobal] += params.stoichiometricMatrix (jGlobal, jGlobal) * logSecondarySpeciesConcentrations[ jGlobal ];
101+ }
102+ }
103103
104104} // namespace
105105
0 commit comments