Skip to content

Commit b0a8aed

Browse files
committed
cleanup of massActions...and change definition of K in the momas example
1 parent b172c96 commit b0a8aed

File tree

3 files changed

+32
-40
lines changed

3 files changed

+32
-40
lines changed

src/reactions/geochemistry/Momas.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ constexpr CArrayWrapper<double, 7, 12> stoichMatrix =
3838

3939
constexpr CArrayWrapper<double, 7> equilibriumConstants =
4040
{
41-
1.0e-12, // C1 = -X2
42-
1.0, // C2 = X2 + X3
43-
1.0, // C3 = X2 + X4
44-
0.1, // C4 = -4X2 + X3 + 3X4
45-
1.0e35, // C5 = 4X2 + 3X3 + X4
46-
1.0e6, // CS1 = 3X2 + X3 + S
47-
1.0e-1 // CS2 = -3X2 + X4 + 2S
41+
1.0e12, // C1 + X2 = ??
42+
1.0, // C2 = X2 + X3
43+
1.0, // C3 = X2 + X4
44+
1.0e1, // C4 + 4X2 = X3 + 3X4
45+
1.0e-35, // C5 = 4X2 + 3X3 + X4
46+
1.0e-6, // CS1 = 3X2 + X3 + S
47+
1.0e1 // CS2 + 3X2 = + X4 + 2S
4848
};
4949

5050
constexpr CArrayWrapper<double, 7> forwardRates =

src/reactions/massActions/MassActions.hpp

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -172,42 +172,17 @@ void calculateAggregatePrimaryConcentrationsWrtLogC( PARAMS_DATA const & params,
172172
ARRAY_2D & dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations )
173173
{
174174
constexpr int numSecondarySpecies = PARAMS_DATA::numSecondarySpecies();
175-
constexpr int numPrimarySpecies = PARAMS_DATA::numPrimarySpecies();
176175

177176
REAL_TYPE logSecondarySpeciesConcentrations[numSecondarySpecies] = {0};
178177

179-
for( INDEX_TYPE i = 0; i < numPrimarySpecies; ++i )
180-
{
181-
for( INDEX_TYPE j = 0; j < numPrimarySpecies; ++j )
182-
{
183-
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations[i][j] = 0.0;
184-
}
185-
}
186-
187-
calculateLogSecondarySpeciesConcentration< REAL_TYPE,
188-
INT_TYPE,
189-
INDEX_TYPE >( params,
190-
logPrimarySpeciesConcentrations,
191-
logSecondarySpeciesConcentrations );
178+
calculateAggregatePrimaryConcentrationsWrtLogC< REAL_TYPE,
179+
INT_TYPE,
180+
INDEX_TYPE>( params,
181+
logPrimarySpeciesConcentrations,
182+
logSecondarySpeciesConcentrations,
183+
aggregatePrimarySpeciesConcentrations,
184+
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations );
192185

193-
for( int i = 0; i < numPrimarySpecies; ++i )
194-
{
195-
REAL_TYPE const speciesConcentration_i = exp( logPrimarySpeciesConcentrations[i] );
196-
aggregatePrimarySpeciesConcentrations[i] = speciesConcentration_i;
197-
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations( i, i ) = speciesConcentration_i;
198-
for( int j = 0; j < numSecondarySpecies; ++j )
199-
{
200-
REAL_TYPE const secondarySpeciesConcentrations_j = exp( logSecondarySpeciesConcentrations[j] );
201-
aggregatePrimarySpeciesConcentrations[i] += params.stoichiometricMatrix( j, i+numSecondarySpecies ) * secondarySpeciesConcentrations_j;
202-
for( int k=0; k<numPrimarySpecies; ++k )
203-
{
204-
REAL_TYPE const dSecondarySpeciesConcentrations_dLogPrimarySpeciesConcentration = params.stoichiometricMatrix( j, k+numSecondarySpecies ) * secondarySpeciesConcentrations_j;
205-
dAggregatePrimarySpeciesConcentrationsDerivatives_dLogPrimarySpeciesConcentrations( i, k ) += params.stoichiometricMatrix( j,
206-
i+numSecondarySpecies ) *
207-
dSecondarySpeciesConcentrations_dLogPrimarySpeciesConcentration;
208-
}
209-
}
210-
}
211186
}
212187

213188
template< typename REAL_TYPE,

src/reactions/reactionsSystems/EquilibriumReactionsAggregatePrimaryConcentration_impl.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ EquilibriumReactions< REAL_TYPE,
9595

9696

9797
REAL_TYPE residualNorm = 0.0;
98+
// 0: 1e-20 -0 2 -2.5e+11 1e-20 7 2 1.8 1 5
99+
printf( "iter X1 R0 X2 R1 X3 R2 X4 R3 S R4\n");
100+
printf( "---- --------------- --------------- --------------- --------------- ---------------\n");
98101
for( int k=0; k<30; ++k )
99102
{
100103
computeResidualAndJacobianAggregatePrimaryConcentrations( temperature,
@@ -110,7 +113,21 @@ EquilibriumReactions< REAL_TYPE,
110113
residualNorm += residual[i] * residual[i];
111114
}
112115
residualNorm = sqrt( residualNorm );
113-
printf( "iter, residualNorm = %2d, %16.10g \n", k, residualNorm );
116+
117+
printf( "%2d: %8.2g %8.2g %8.2g %8.2g %8.2g %8.2g %8.2g %8.2g %8.2g %8.2g \n",
118+
k,
119+
exp( logPrimarySpeciesConcentration[0] ),
120+
residual[0],
121+
exp( logPrimarySpeciesConcentration[1] ),
122+
residual[1],
123+
exp( logPrimarySpeciesConcentration[2] ),
124+
residual[2],
125+
exp( logPrimarySpeciesConcentration[3] ),
126+
residual[3],
127+
exp( logPrimarySpeciesConcentration[4] ),
128+
residual[4] );
129+
130+
//printf( "iter, residualNorm = %2d, %16.10g \n", k, residualNorm );
114131
if( residualNorm < 1.0e-12 )
115132
{
116133
printf( " converged\n" );

0 commit comments

Comments
 (0)