From 95e66cd5ff3416c39477445a35eeb3497aff88c7 Mon Sep 17 00:00:00 2001 From: Victor Brunini Date: Mon, 17 Dec 2012 16:14:14 +0000 Subject: [PATCH] Get rid of static variables in member functions. --- include/cantera/thermo/GibbsExcessVPSSTP.h | 1 + include/cantera/thermo/IonsFromNeutralVPSSTP.h | 4 ++++ include/cantera/thermo/VPSSMgr.h | 1 + include/cantera/thermo/VPStandardStateTP.h | 1 + include/cantera/transport/LiquidTransport.h | 4 ++-- src/thermo/GibbsExcessVPSSTP.cpp | 8 ++++++-- src/thermo/IonsFromNeutralVPSSTP.cpp | 17 +++++++++++++---- src/thermo/VPSSMgr.cpp | 9 +++++++++ src/thermo/VPStandardStateTP.cpp | 5 +++++ src/transport/LiquidTransport.cpp | 6 ++---- 10 files changed, 44 insertions(+), 12 deletions(-) diff --git a/include/cantera/thermo/GibbsExcessVPSSTP.h b/include/cantera/thermo/GibbsExcessVPSSTP.h index b331172e3..fc823c1a0 100644 --- a/include/cantera/thermo/GibbsExcessVPSSTP.h +++ b/include/cantera/thermo/GibbsExcessVPSSTP.h @@ -423,6 +423,7 @@ public: * Length = m_kk. units are m^3/kmol. */ virtual void getPartialMolarVolumes(doublereal* vbar) const; + virtual const vector_fp & getPartialMolarVolumes() const; //@} /// @name Properties of the Standard State of the Species in the Solution diff --git a/include/cantera/thermo/IonsFromNeutralVPSSTP.h b/include/cantera/thermo/IonsFromNeutralVPSSTP.h index bcc431118..21f09c10b 100644 --- a/include/cantera/thermo/IonsFromNeutralVPSSTP.h +++ b/include/cantera/thermo/IonsFromNeutralVPSSTP.h @@ -825,6 +825,10 @@ public: private: GibbsExcessVPSSTP *geThermo; + // Temporary vectors that I don't want to allocate every time the function is called + mutable vector_fp y; + mutable vector_fp dlnActCoeff_NeutralMolecule; + mutable vector_fp dX_NeutralMolecule; //! If true then we own the underlying neutral Molecule Phase /*! diff --git a/include/cantera/thermo/VPSSMgr.h b/include/cantera/thermo/VPSSMgr.h index 141229f25..186934fcc 100644 --- a/include/cantera/thermo/VPSSMgr.h +++ b/include/cantera/thermo/VPSSMgr.h @@ -413,6 +413,7 @@ public: * units = m^3 / kmol */ virtual void getStandardVolumes(doublereal* vol) const; + virtual const vector_fp & getStandardVolumes() const; //! Return a reference to a vector of the species standard molar volumes const vector_fp& standardVolumes() const { diff --git a/include/cantera/thermo/VPStandardStateTP.h b/include/cantera/thermo/VPStandardStateTP.h index 3574e2622..685bc8d97 100644 --- a/include/cantera/thermo/VPStandardStateTP.h +++ b/include/cantera/thermo/VPStandardStateTP.h @@ -269,6 +269,7 @@ public: * units = m^3 / kmol */ virtual void getStandardVolumes(doublereal* vol) const; + virtual const vector_fp & getStandardVolumes() const; //! Set the temperature of the phase diff --git a/include/cantera/transport/LiquidTransport.h b/include/cantera/transport/LiquidTransport.h index 0ecfa5ed5..236869958 100644 --- a/include/cantera/transport/LiquidTransport.h +++ b/include/cantera/transport/LiquidTransport.h @@ -1271,10 +1271,10 @@ private: vector_fp m_actCoeff; //! RHS to the stefan-maxwell equation -// DenseMatrix m_B; + DenseMatrix m_B; //! Matrix for the stefan maxwell equation. -// DenseMatrix m_A; + DenseMatrix m_A; //! Current Temperature -> locally stored /*! diff --git a/src/thermo/GibbsExcessVPSSTP.cpp b/src/thermo/GibbsExcessVPSSTP.cpp index 9cacb95a7..a4adb9b44 100644 --- a/src/thermo/GibbsExcessVPSSTP.cpp +++ b/src/thermo/GibbsExcessVPSSTP.cpp @@ -184,9 +184,9 @@ void GibbsExcessVPSSTP::setPressure(doublereal p) void GibbsExcessVPSSTP::calcDensity() { - static vector_fp vbar(m_kk); + vector_fp vbar = getPartialMolarVolumes(); // double *vbar = &m_pp[0]; - getPartialMolarVolumes(&vbar[0]); +// getPartialMolarVolumes(&vbar[0]); doublereal vtotal = 0.0; for (size_t i = 0; i < m_kk; i++) { @@ -294,6 +294,10 @@ void GibbsExcessVPSSTP::getPartialMolarVolumes(doublereal* vbar) const getStandardVolumes(vbar); } +const vector_fp & GibbsExcessVPSSTP::getPartialMolarVolumes() const +{ + return getStandardVolumes(); +} doublereal GibbsExcessVPSSTP::err(const std::string& msg) const diff --git a/src/thermo/IonsFromNeutralVPSSTP.cpp b/src/thermo/IonsFromNeutralVPSSTP.cpp index a608f98d4..dcb76573c 100644 --- a/src/thermo/IonsFromNeutralVPSSTP.cpp +++ b/src/thermo/IonsFromNeutralVPSSTP.cpp @@ -103,6 +103,10 @@ IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(const std::string& inputFile, } constructPhaseFile(inputFile, id); geThermo = dynamic_cast(neutralMoleculePhase_); + y.resize(numNeutralMoleculeSpecies_,0.0); + size_t numNeutMolSpec = geThermo->nSpecies(); + dlnActCoeff_NeutralMolecule.resize(numNeutMolSpec); + dX_NeutralMolecule.resize(numNeutMolSpec); } //==================================================================================================================== IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(XML_Node& phaseRoot, @@ -127,6 +131,10 @@ IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(XML_Node& phaseRoot, } constructPhaseXML(phaseRoot, id); geThermo = dynamic_cast(neutralMoleculePhase_); + y.resize(numNeutralMoleculeSpecies_,0.0); + size_t numNeutMolSpec = geThermo->nSpecies(); + dlnActCoeff_NeutralMolecule.resize(numNeutMolSpec); + dX_NeutralMolecule.resize(numNeutMolSpec); } //==================================================================================================================== @@ -216,6 +224,9 @@ operator=(const IonsFromNeutralVPSSTP& b) dlnActCoeffdlnX_diag_NeutralMolecule_ = b.dlnActCoeffdlnX_diag_NeutralMolecule_; dlnActCoeffdlnN_diag_NeutralMolecule_ = b.dlnActCoeffdlnN_diag_NeutralMolecule_; dlnActCoeffdlnN_NeutralMolecule_ = b.dlnActCoeffdlnN_NeutralMolecule_; + y = b.y; + dlnActCoeff_NeutralMolecule = b.dlnActCoeff_NeutralMolecule ; + dX_NeutralMolecule = b.dX_NeutralMolecule ; return *this; } @@ -960,8 +971,6 @@ void IonsFromNeutralVPSSTP::calcNeutralMoleculeMoleFractions() const void IonsFromNeutralVPSSTP::getNeutralMoleculeMoleGrads(const doublereal* const dx, doublereal* const dy) const { doublereal fmij; - static vector_fp y; - y.resize(numNeutralMoleculeSpecies_,0.0); doublereal sumy, sumdy; //check sum dx = 0 @@ -1491,8 +1500,8 @@ void IonsFromNeutralVPSSTP::getdlnActCoeffds(const doublereal dTds, const double } size_t numNeutMolSpec = geThermo->nSpecies(); - static vector_fp dlnActCoeff_NeutralMolecule(numNeutMolSpec); - static vector_fp dX_NeutralMolecule(numNeutMolSpec); +// static vector_fp dlnActCoeff_NeutralMolecule(numNeutMolSpec); +// static vector_fp dX_NeutralMolecule(numNeutMolSpec); getNeutralMoleculeMoleGrads(DATA_PTR(dXds),DATA_PTR(dX_NeutralMolecule)); diff --git a/src/thermo/VPSSMgr.cpp b/src/thermo/VPSSMgr.cpp index a84e0ebb0..0e5607fdc 100644 --- a/src/thermo/VPSSMgr.cpp +++ b/src/thermo/VPSSMgr.cpp @@ -228,6 +228,15 @@ VPSSMgr::getStandardVolumes(doublereal* vol) const err("getStandardVolumes"); } } +const vector_fp & +VPSSMgr::getStandardVolumes() const +{ + if (m_useTmpStandardStateStorage) { + return m_Vss; + } else { + err("getStandardVolumes"); + } +} /*****************************************************************/ void diff --git a/src/thermo/VPStandardStateTP.cpp b/src/thermo/VPStandardStateTP.cpp index f1fd58e0a..a01f2956a 100644 --- a/src/thermo/VPStandardStateTP.cpp +++ b/src/thermo/VPStandardStateTP.cpp @@ -272,6 +272,11 @@ void VPStandardStateTP::getStandardVolumes(doublereal* vol) const updateStandardStateThermo(); m_VPSS_ptr->getStandardVolumes(vol); } +const vector_fp & VPStandardStateTP::getStandardVolumes() const +{ + updateStandardStateThermo(); + return m_VPSS_ptr->getStandardVolumes(); +} /* * ----- Thermodynamic Values for the Species Reference States ---- diff --git a/src/transport/LiquidTransport.cpp b/src/transport/LiquidTransport.cpp index 4d7c4af32..ef50596bd 100644 --- a/src/transport/LiquidTransport.cpp +++ b/src/transport/LiquidTransport.cpp @@ -163,8 +163,8 @@ LiquidTransport& LiquidTransport::operator=(const LiquidTransport& right) m_actCoeff = right.m_actCoeff; m_Grad_lnAC = right.m_Grad_lnAC; m_chargeSpecies = right.m_chargeSpecies; -// m_B = right.m_B; -// m_A = right.m_A; + m_B = right.m_B; + m_A = right.m_A; m_temp = right.m_temp; m_press = right.m_press; m_flux = right.m_flux; @@ -1584,8 +1584,6 @@ void LiquidTransport::update_Grad_lnAC() void LiquidTransport::stefan_maxwell_solve() { doublereal tmp; - static DenseMatrix m_A(m_nsp, m_nsp, 0.0); - static DenseMatrix m_B(m_nsp, m_nDim, 0.0); m_B.resize(m_nsp, m_nDim, 0.0); m_A.resize(m_nsp, m_nsp, 0.0);