From 99965b01c4fd56cf8c72d2d3e012b53e55d02a68 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 25 Feb 2015 10:54:50 +0000 Subject: [PATCH] constTransport: Handle the case of nMoles = 0 in += and -= operators Resolves bug-report http://openfoam.org/mantisbt/view.php?id=1348 --- .../specie/transport/const/constTransportI.H | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/thermophysicalModels/specie/transport/const/constTransportI.H b/src/thermophysicalModels/specie/transport/const/constTransportI.H index 9dd3a2c08..2a73a4a18 100644 --- a/src/thermophysicalModels/specie/transport/const/constTransportI.H +++ b/src/thermophysicalModels/specie/transport/const/constTransportI.H @@ -153,11 +153,14 @@ inline void Foam::constTransport::operator+= Thermo::operator+=(st); - molr1 /= this->nMoles(); - scalar molr2 = st.nMoles()/this->nMoles(); + if (mag(molr1) + mag(st.nMoles()) > SMALL) + { + molr1 /= this->nMoles(); + scalar molr2 = st.nMoles()/this->nMoles(); - mu_ = molr1*mu_ + molr2*st.mu_; - rPr_ = 1.0/(molr1/rPr_ + molr2/st.rPr_); + mu_ = molr1*mu_ + molr2*st.mu_; + rPr_ = 1.0/(molr1/rPr_ + molr2/st.rPr_); + } } @@ -171,11 +174,14 @@ inline void Foam::constTransport::operator-= Thermo::operator-=(st); - molr1 /= this->nMoles(); - scalar molr2 = st.nMoles()/this->nMoles(); + if (mag(molr1) + mag(st.nMoles()) > SMALL) + { + molr1 /= this->nMoles(); + scalar molr2 = st.nMoles()/this->nMoles(); - mu_ = molr1*mu_ - molr2*st.mu_; - rPr_ = 1.0/(molr1/rPr_ - molr2/st.rPr_); + mu_ = molr1*mu_ - molr2*st.mu_; + rPr_ = 1.0/(molr1/rPr_ - molr2/st.rPr_); + } }