Skip to content

Commit 9909192

Browse files
committed
franks fixes
1 parent dbf6434 commit 9909192

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

src/common/logMath.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ struct LogExp
151151
*/
152152
template< typename T >
153153
HPCREACT_HOST_DEVICE
154-
static constexpr inline void dWrtLogScale( T & x )
154+
static constexpr inline T dWrtLogScale( T x )
155155
{
156-
if constexpr ( Base == LogBase::ten ) { x = x * ln10<T>(); }
156+
if constexpr ( Base == LogBase::ten ) { return x * ln10<T>(); }
157+
else { return x; }
157158
}
158159

159160
// ***** log function *********************************************************************************************

src/reactions/exampleSystems/unitTests/testKineticReactions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ TEST( testKineticReactions, computeSpeciesRatesTest_simpleKineticTestRateParams
4141
{
4242
double const initialSpeciesConcentration[5] = { 1.0, 1.0e-16, 0.5, 1.0, 1.0e-16 };
4343
double const expectedSpeciesRates[5] = { -2.0, 1.0, 0.75, -0.25, 0.5 };
44-
double const expectedSpeciesRatesDerivatives[5][5] = { { -4.0, 1.0, 0.0, 0.0, 0.0 },
44+
double const expectedSpeciesRatesDerivatives[5][5] =
45+
{ { -4.0, 1.0, 0.0, 0.0, 0.0 },
4546
{ 2.0, -0.5, 0.0, 0.0, 0.0 },
4647
{ 2.0, -0.5, -0.5, -0.25, 0.0 },
4748
{ 0.0, 0.0, -0.5, -0.25, 0.0 },

src/reactions/reactionsSystems/KineticReactions_impl.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ KineticReactions< REAL_TYPE,
6262
// set reaction rate to zero
6363
reactionRates[r] = 0.0;
6464
// get/calculate the forward and reverse rate constants for this reaction
65-
RealType const forwardRateConstant = params.rateConstantForward( r ); //* logmath::exp( -params.m_activationEnergy[r] / ( constants::R *
65+
RealType const forwardRateConstant = params.rateConstantForward( r ); // exp( -params.m_activationEnergy[r] / ( constants::R *
6666
// temperature ) );
6767
RealType const reverseRateConstant = params.rateConstantReverse( r );
6868

@@ -90,16 +90,18 @@ KineticReactions< REAL_TYPE,
9090

9191
if constexpr( CALCULATE_DERIVATIVES )
9292
{
93+
RealType const dFactorForward = logmath::dWrtLogScale( forwardRateConstant * logmath::exp( productConcForward ) );
94+
RealType const dFactorReverse = logmath::dWrtLogScale( -reverseRateConstant * logmath::exp( productConcReverse ) );
9395
for( IntType i = 0; i < PARAMS_DATA::numSpecies(); ++i )
9496
{
9597
RealType const s_ri = params.stoichiometricMatrix( r, i );
9698
if( s_ri < 0.0 )
9799
{
98-
reactionRatesDerivatives( r, i ) = forwardRateConstant * logmath::exp( productConcForward ) * (-s_ri);
100+
reactionRatesDerivatives( r, i ) = dFactorForward * (-s_ri);
99101
}
100102
else if( s_ri > 0.0 )
101103
{
102-
reactionRatesDerivatives( r, i ) = -reverseRateConstant * logmath::exp( productConcReverse ) * s_ri;
104+
reactionRatesDerivatives( r, i ) = dFactorReverse * s_ri;
103105
}
104106
else
105107
{
@@ -150,8 +152,8 @@ KineticReactions< REAL_TYPE,
150152
}
151153

152154
// get/calculate the forward and reverse rate constants for this reaction
153-
RealType const rateConstant = params.rateConstantForward( r ); //* logmath::exp( -params.m_activationEnergy[r] / ( constants::R *
154-
// temperature ) );
155+
RealType const rateConstant = params.rateConstantForward( r ); //* exp( -params.m_activationEnergy[r] / ( constants::R * temperature )
156+
// );
155157
RealType const equilibriumConstant = params.equilibriumConstant( r );
156158

157159

@@ -257,7 +259,7 @@ KineticReactions< REAL_TYPE,
257259

258260

259261
REAL_TYPE residualNorm = 0.0;
260-
for( int k=0; k<20; ++k ) // newton loop
262+
for( int k=0; k<20; ++k ) // newton loop
261263
{
262264
printf( "iteration %2d: \n", k );
263265

src/reactions/reactionsSystems/MixedEquilibriumKineticReactions_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ MixedEquilibriumKineticReactions< REAL_TYPE,
5656
ARRAY_1D_PRIMARY & aggregateSpeciesRates,
5757
ARRAY_2D_PRIMARY & dAggregateSpeciesRates_dLogPrimarySpeciesConcentrations )
5858
{
59-
if constexpr ( PARAMS_DATA::numEquilibriumReactions() > 0 )
59+
if constexpr( PARAMS_DATA::numEquilibriumReactions() > 0 )
6060
{
6161
// 1. Compute new aggregate species from primary species
6262
massActions::calculateTotalAndMobileAggregatePrimaryConcentrationsWrtLogC< REAL_TYPE,
@@ -168,7 +168,7 @@ MixedEquilibriumKineticReactions< REAL_TYPE,
168168
{
169169
for( IntType j = 0; j < numPrimarySpecies; ++j )
170170
{
171-
dReactionRates_dLogPrimarySpeciesConcentrations( i, j ) = logmath::dWrtLogConst< REAL_TYPE >() * reactionRatesDerivatives( i, j + numSecondarySpecies );
171+
dReactionRates_dLogPrimarySpeciesConcentrations( i, j ) = reactionRatesDerivatives( i, j + numSecondarySpecies );
172172

173173
for( IntType k = 0; k < numSecondarySpecies; ++k )
174174
{

src/reactions/reactionsSystems/Parameters.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct MixedReactionsParameters
231231
RealType const absDiff = fabs( K - ( kf / kr ) );
232232
RealType const effectiveMagnitude = max( fabs( K ), fabs( kf/kr ));
233233
RealType const tolerance = effectiveMagnitude * pow( 10, -num_digits );
234-
if( absDiff > tolerance ) // Tolerance for floating point precision
234+
if( absDiff > tolerance ) // Tolerance for floating point precision
235235
{
236236
throw std::runtime_error( "Error: Inconsistent equilibrium relation for reaction " + std::to_string( i ));
237237
}

src/reactions/unitTestUtilities/kineticReactionsTestUtilities.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void computeReactionRatesTest( PARAMS_DATA const & params,
113113
for( int i = 0; i < numSpecies; ++i )
114114
{
115115

116-
data.reactionRatesDerivatives( r, i ) = data.reactionRatesDerivatives( r, i ) * logmath::exp( -data.speciesConcentration[i] );
116+
data.reactionRatesDerivatives( r, i ) = data.reactionRatesDerivatives( r, i ) * logmath::exp( -data.speciesConcentration[i] ) / logmath::dWrtLogConst< double >();
117117
EXPECT_NEAR( data.reactionRatesDerivatives( r, i ), expectedReactionRatesDerivatives[r][i], std::max( magScale, fabs( expectedReactionRatesDerivatives[r][i] ) ) * 1.0e-8 );
118118
}
119119
}
@@ -180,7 +180,7 @@ void computeSpeciesRatesTest( PARAMS_DATA const & params,
180180
{
181181
for( int j = 0; j < numSpecies; ++j )
182182
{
183-
data.speciesRatesDerivatives( i, j ) = data.speciesRatesDerivatives( i, j ) * logmath::exp( -data.speciesConcentration[j] );
183+
data.speciesRatesDerivatives( i, j ) = data.speciesRatesDerivatives( i, j ) * logmath::exp( -data.speciesConcentration[j] ) / logmath::dWrtLogConst< double >();
184184
EXPECT_NEAR( data.speciesRatesDerivatives( i, j ), expectedSpeciesRatesDerivatives[i][j], 1.0e-8 );
185185
}
186186
}

src/uncrustify.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ sp_angle_shift = force # ignore/add/remove/force
210210
sp_permit_cpp11_shift = false # false/true
211211

212212
# Add or remove space before '(' of 'if', 'for', 'switch', 'while', etc.
213-
sp_before_sparen = force # ignore/add/remove/force
213+
sp_before_sparen = remove # ignore/add/remove/force
214214

215215
# Add or remove space inside if-condition '(' and ')'.
216216
sp_inside_sparen = force # ignore/add/remove/force

0 commit comments

Comments
 (0)