From c5fd858c143456c7e9fd1924c9da461a5781796c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 23 Jan 2019 22:52:35 +0100 Subject: [PATCH] STYLE: avoid floating point comparison with uint8_t in DSMCCloud --- .../clouds/Templates/DSMCCloud/DSMCCloud.C | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/lagrangian/DSMC/clouds/Templates/DSMCCloud/DSMCCloud.C b/src/lagrangian/DSMC/clouds/Templates/DSMCCloud/DSMCCloud.C index 8cc78a0967..2919957cd0 100644 --- a/src/lagrangian/DSMC/clouds/Templates/DSMCCloud/DSMCCloud.C +++ b/src/lagrangian/DSMC/clouds/Templates/DSMCCloud/DSMCCloud.C @@ -997,35 +997,32 @@ Foam::scalar Foam::DSMCCloud::equipartitionInternalEnergy direction iDof ) { - scalar Ei = 0.0; - - if (iDof < SMALL) + if (iDof == 0) { - return Ei; + return 0; } - else if (iDof < 2.0 + SMALL && iDof > 2.0 - SMALL) + else if (iDof == 2) { // Special case for iDof = 2, i.e. diatomics; - Ei = - -log(rndGen_.sample01()) - *physicoChemical::k.value()*temperature; + return + ( + -log(rndGen_.sample01()) + *physicoChemical::k.value()*temperature + ); } - else + + + const scalar a = 0.5*iDof - 1; + scalar energyRatio = 0; + scalar P = -1; + + do { - scalar a = 0.5*iDof - 1; - scalar energyRatio; - scalar P = -1; + energyRatio = 10*rndGen_.sample01(); + P = pow((energyRatio/a), a)*exp(a - energyRatio); + } while (P < rndGen_.sample01()); - do - { - energyRatio = 10*rndGen_.sample01(); - P = pow((energyRatio/a), a)*exp(a - energyRatio); - } while (P < rndGen_.sample01()); - - Ei = energyRatio*physicoChemical::k.value()*temperature; - } - - return Ei; + return energyRatio*physicoChemical::k.value()*temperature; }