@@ -256,15 +256,13 @@ HPCREACT_HOST_DEVICE inline void
256256KineticReactions< REAL_TYPE,
257257 INT_TYPE,
258258 INDEX_TYPE,
259- LOGE_CONCENTRATION
260- >::timeStep(
261- RealType const dt,
262- RealType const & temperature,
263- PARAMS_DATA const & params,
264- ARRAY_1D_TO_CONST const & speciesConcentration_n,
265- ARRAY_1D & speciesConcentration,
266- ARRAY_1D & speciesRates,
267- ARRAY_2D & speciesRatesDerivatives )
259+ LOGE_CONCENTRATION >::timeStep( RealType const dt,
260+ RealType const & temperature,
261+ PARAMS_DATA const & params,
262+ ARRAY_1D_TO_CONST const & speciesConcentration_n,
263+ ARRAY_1D & speciesConcentration,
264+ ARRAY_1D & speciesRates,
265+ ARRAY_2D & speciesRatesDerivatives )
268266{
269267// constexpr int numReactions = PARAMS_DATA::numReactions;
270268 constexpr int numSpecies = PARAMS_DATA::numSpecies;
@@ -285,32 +283,82 @@ KineticReactions< REAL_TYPE,
285283
286284 double residual[numSpecies] = { 0.0 };
287285 double deltaPrimarySpeciesConcentration[numSpecies] = { 0.0 };
286+
287+ // form residual and Jacobian
288288 for ( int i = 0 ; i < numSpecies; ++i )
289289 {
290- residual[i] = -(speciesConcentration[i] - speciesConcentration_n[i] - dt * speciesRates[i]);
290+
291+
292+ RealType nonLogC;
293+ RealType nonLogC_n;
294+ if constexpr ( LOGE_CONCENTRATION )
295+ {
296+ nonLogC = exp ( speciesConcentration[i] );
297+ nonLogC_n = exp ( speciesConcentration_n[i] );
298+ }
299+ else
300+ {
301+ nonLogC = speciesConcentration[i];
302+ nonLogC_n = speciesConcentration_n[i];
303+ }
304+ residual[i] = -(nonLogC - nonLogC_n - dt * speciesRates[i]);
305+
306+
291307 for ( int j = 0 ; j < numSpecies; ++j )
292308 {
293309 speciesRatesDerivatives ( i, j ) = - dt * speciesRatesDerivatives ( i, j );
294310 }
295- speciesRatesDerivatives ( i, i ) += 1.0 ;
311+ if constexpr ( LOGE_CONCENTRATION )
312+ {
313+ speciesRatesDerivatives ( i, i ) += nonLogC;
314+ }
315+ else
316+ {
317+ speciesRatesDerivatives ( i, i ) += 1.0 ;
318+ }
296319 }
297320
321+
322+
298323 residualNorm = 0.0 ;
299324 for ( int j = 0 ; j < numSpecies; ++j )
300325 {
301326 residualNorm += residual[j] * residual[j];
302327 }
303328 residualNorm = sqrt ( residualNorm );
304- if ( residualNorm < 1.0e-8 )
329+ if ( residualNorm < 1.0e-14 )
305330 {
306331 break ;
307332 }
308333
334+
335+ // printf( "residual = { ");
336+ // for( int i = 0; i < numSpecies; ++i )
337+ // {
338+ // printf( " %g, ", residual[i] );
339+ // }
340+ // printf( "}\n" );
341+
342+ // printf( "Jacobian = { \n" );
343+ // for( int i = 0; i < numSpecies; ++i )
344+ // {
345+ // printf( " { ");
346+ // for( int j = 0; j < numSpecies; ++j )
347+ // {
348+ // printf( " %g ", speciesRatesDerivatives( i, j ) );
349+ // // printf( " %g ", speciesRatesDerivatives( i, j ) / exp(speciesConcentration[j]) );
350+ // if( j < numSpecies-1 ) { printf( ", " ); }
351+ // }
352+ // printf( "}, \n" );
353+ // }
354+ // printf( "}\n" );
355+
309356 solveNxN_pivoted<double ,numSpecies>( speciesRatesDerivatives.data , residual, deltaPrimarySpeciesConcentration );
310357
311358 for ( int i = 0 ; i < numSpecies; ++i )
312359 {
313- speciesConcentration[i] += deltaPrimarySpeciesConcentration[i];
360+ // printf( "species %2d: concentration = %e, residual = %e, delta = %e \n", i, speciesConcentration[i], residual[i], deltaPrimarySpeciesConcentration[i] );
361+ speciesConcentration[i] = speciesConcentration[i] + deltaPrimarySpeciesConcentration[i];
314362 }
315363
316364 }
0 commit comments