@@ -315,35 +315,37 @@ void PlasmaPhase::setCollisions()
315315 m_collisions.clear ();
316316 m_collisionRates.clear ();
317317 m_targetSpeciesIndices.clear ();
318+ m_electronCollisionReactionIndices.clear ();
318319
319320 if (shared_ptr<Solution> soln = m_soln.lock ()) {
320- shared_ptr<Kinetics> kin = soln->kinetics ();
321- if (!kin ) {
321+ m_kin = soln->kinetics ();
322+ if (!m_kin ) {
322323 return ;
323324 }
324325
325326 // add collision from the initial list of reactions
326- for (size_t i = 0 ; i < kin ->nReactions (); i ++) {
327- std::shared_ptr<Reaction> R = kin ->reaction (i );
327+ for (size_t j = 0 ; j < m_kin ->nReactions (); j ++) {
328+ std::shared_ptr<Reaction> R = m_kin ->reaction (j );
328329 if (R->rate ()->type () != " electron-collision-plasma" ) {
329330 continue ;
330331 }
331- addCollision (R );
332+ addCollision (j );
332333 }
333334
334335 // register callback when reaction is added later
335336 // Modifying collision reactions is not supported
336- kin ->registerReactionAddedCallback (this , [this , kin ]() {
337- size_t i = kin ->nReactions () - 1 ;
338- if (kin ->reaction (i )->type () == " electron-collision-plasma" ) {
339- addCollision (kin-> reaction (i) );
337+ m_kin ->registerReactionAddedCallback (this , [this ]() {
338+ size_t j = m_kin ->nReactions () - 1 ;
339+ if (m_kin ->reaction (j )->type () == " electron-collision-plasma" ) {
340+ addCollision (j );
340341 }
341342 });
342343 }
343344}
344345
345- void PlasmaPhase::addCollision (std::shared_ptr<Reaction> collision )
346+ void PlasmaPhase::addCollision (size_t j )
346347{
348+ std::shared_ptr<Reaction> collision = m_kin->reaction (j);
347349 size_t i = nCollisions ();
348350
349351 // setup callback to signal updating the cross-section-related
@@ -368,8 +370,11 @@ void PlasmaPhase::addCollision(std::shared_ptr<Reaction> collision)
368370 std::dynamic_pointer_cast<ElectronCollisionPlasmaRate>(collision->rate ()));
369371 m_interp_cs_ready.emplace_back (false );
370372
373+ m_electronCollisionReactionIndices.push_back (j);
374+
371375 // resize parameters
372376 m_elasticElectronEnergyLossCoefficients.resize (nCollisions ());
377+ m_netROPCollisions.resize (nCollisions ());
373378}
374379
375380bool PlasmaPhase::updateInterpolatedCrossSection (size_t i)
@@ -464,6 +469,33 @@ void PlasmaPhase::updateElasticElectronEnergyLossCoefficient(size_t i)
464469 m_electronEnergyLevels.pow (3.0 ));
465470}
466471
472+ void PlasmaPhase::updateCollisionRatesOfProgress ()
473+ {
474+ static const int cacheId = m_cache.getId ();
475+ CachedScalar last = m_cache.getScalar (cacheId);
476+
477+ // combine the distribution and energy level number
478+ int stateNum = m_distNum + m_levelNum;
479+
480+ // update only if the reaction rates coefficients have changed
481+ // which depends on the energy distribution, and energy levels
482+ if (!last.validate (stateNum)) {
483+ m_netROPCollisions =
484+ m_kin->netRatesOfProgressByIndices (m_electronCollisionReactionIndices);
485+ }
486+ }
487+
488+ double PlasmaPhase::inelasticPowerLoss ()
489+ {
490+ updateCollisionRatesOfProgress ();
491+ double powerLoss = 0.0 ;
492+ for (size_t i = 0 ; i < nCollisions (); i++) {
493+ powerLoss += m_netROPCollisions[i] * m_collisionRates[i]->energyLevels ()[0 ];
494+ }
495+ powerLoss *= Avogadro * ElectronCharge;
496+ return powerLoss;
497+ }
498+
467499double PlasmaPhase::elasticPowerLoss ()
468500{
469501 updateElasticElectronEnergyLossCoefficients ();
0 commit comments