From db33fb8145885b59ff93202d6164408527e923e3 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 5 Dec 2008 02:30:23 +0000 Subject: [PATCH] Bug fixes for assignment operators. --- Cantera/src/thermo/PDSS.cpp | 25 ++++++- Cantera/src/thermo/PDSS.h | 11 +-- Cantera/src/thermo/PDSS_ConstVol.cpp | 3 + Cantera/src/thermo/PDSS_HKFT.cpp | 91 ++++++++++++++++++++---- Cantera/src/thermo/PDSS_HKFT.h | 19 +++++ Cantera/src/thermo/PDSS_IdealGas.cpp | 4 ++ Cantera/src/thermo/PDSS_Water.cpp | 5 +- Cantera/src/thermo/VPStandardStateTP.cpp | 3 +- 8 files changed, 137 insertions(+), 24 deletions(-) diff --git a/Cantera/src/thermo/PDSS.cpp b/Cantera/src/thermo/PDSS.cpp index baeab7a1f..93ddbb618 100644 --- a/Cantera/src/thermo/PDSS.cpp +++ b/Cantera/src/thermo/PDSS.cpp @@ -123,16 +123,37 @@ namespace Cantera { */ PDSS& PDSS::operator=(const PDSS&b) { if (&b == this) return *this; + m_pdssType = b.m_pdssType; m_temp = b.m_temp; m_pres = b.m_pres; m_p0 = b.m_p0; m_minTemp = b.m_minTemp; m_maxTemp = b.m_maxTemp; - m_tp = b.m_tp; - m_vpssmgr_ptr = b.m_vpssmgr_ptr; + + // Pointers which are zero, are properly assigned in the + // function, initAllPtrs(). which must be called after the + // assignment operation. + + m_tp = 0; + m_vpssmgr_ptr = 0; m_mw = b.m_mw; m_spindex = b.m_spindex; + m_spthermo = 0; + m_cp0_R_ptr = 0; + m_h0_RT_ptr = 0; + m_s0_R_ptr = 0; + m_g0_RT_ptr = 0; + m_V0_ptr = 0; + m_cpss_R_ptr = 0; + m_hss_RT_ptr = 0; + m_sss_R_ptr = 0; + m_gss_RT_ptr = 0; + m_Vss_ptr = 0; + + // Here we just fill these in so that local copies within the VPSS object work. + m_tp = b.m_tp; + m_vpssmgr_ptr = b.m_vpssmgr_ptr; m_spthermo = b.m_spthermo; m_cp0_R_ptr = b.m_cp0_R_ptr; m_h0_RT_ptr = b.m_h0_RT_ptr; diff --git a/Cantera/src/thermo/PDSS.h b/Cantera/src/thermo/PDSS.h index 583b1e8ac..bb368766d 100644 --- a/Cantera/src/thermo/PDSS.h +++ b/Cantera/src/thermo/PDSS.h @@ -594,13 +594,14 @@ namespace Cantera { */ virtual void initThermoXML(const XML_Node& phaseNode, std::string& id); - + private: //! Initialize all of the internal shallow pointers that can be initialized /*! - * This routine isn't virtual + * This routine isn't virtual. It's only applicable for the current class */ void initPtrs(); + public: //! Initialize or Reinitialize all shallow pointers in the object /*! * This command is called to reinitialize all shallow pointers in the @@ -616,8 +617,8 @@ namespace Cantera { * that will handle the calculation of the reference * state thermodynamic coefficients. */ - void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, - SpeciesThermo* spthermo_ptr); + virtual void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, + SpeciesThermo* spthermo_ptr); //@} @@ -675,7 +676,7 @@ namespace Cantera { //! Reference state enthalpy divided by RT. /*! * Storage for the thermo properties is provided by - * VPSSMgr. + * VPSSMgr. This object owns a shallow pointer. * Calculated at the current value of T and m_p0 */ doublereal *m_h0_RT_ptr; diff --git a/Cantera/src/thermo/PDSS_ConstVol.cpp b/Cantera/src/thermo/PDSS_ConstVol.cpp index 0acb66e34..c5a9acc7c 100644 --- a/Cantera/src/thermo/PDSS_ConstVol.cpp +++ b/Cantera/src/thermo/PDSS_ConstVol.cpp @@ -69,6 +69,9 @@ namespace Cantera { PDSS_ConstVol& PDSS_ConstVol::operator=(const PDSS_ConstVol&b) { if (&b == this) return *this; PDSS::operator=(b); + + m_constMolarVolume = b.m_constMolarVolume; + return *this; } diff --git a/Cantera/src/thermo/PDSS_HKFT.cpp b/Cantera/src/thermo/PDSS_HKFT.cpp index 999cfdecb..484507c95 100644 --- a/Cantera/src/thermo/PDSS_HKFT.cpp +++ b/Cantera/src/thermo/PDSS_HKFT.cpp @@ -18,8 +18,6 @@ namespace Cantera { * Basic list of constructors and duplicators */ - - PDSS_HKFT::PDSS_HKFT(VPStandardStateTP *tp, int spindex) : PDSS(tp, spindex), m_waterSS(0), @@ -113,8 +111,32 @@ namespace Cantera { } PDSS_HKFT::PDSS_HKFT(const PDSS_HKFT &b) : - PDSS(b) + PDSS(b), + m_waterSS(0), + m_pres(OneAtm), + m_densWaterSS(-1.0), + m_waterProps(0), + m_born_coeff_j(-1.0), + m_r_e_j(-1.0), + m_deltaG_formation_tr_pr(0.0), + m_deltaH_formation_tr_pr(0.0), + m_Mu0_tr_pr(0.0), + m_Entrop_tr_pr(0.0), + m_a1(0.0), + m_a2(0.0), + m_a3(0.0), + m_a4(0.0), + m_c1(0.0), + m_c2(0.0), + m_omega_pr_tr(0.0), + m_Y_pr_tr(0.0), + m_Z_pr_tr(0.0), + m_presR_bar(0.0), + m_domega_jdT_prtr(0.0), + m_charge_j(0.0) { + m_pdssType = cPDSS_MOLAL_HKFT; + m_presR_bar = OneAtm * 1.0E-5; /* * Use the assignment operator to do the brunt * of the work for the copy construtor. @@ -125,13 +147,45 @@ namespace Cantera { /** * Assignment operator */ - PDSS_HKFT& PDSS_HKFT::operator=(const PDSS_HKFT&b) { + PDSS_HKFT& PDSS_HKFT::operator=(const PDSS_HKFT& b) { if (&b == this) return *this; - m_tp = b.m_tp; - m_spindex = b.m_spindex; - m_temp = b.m_temp; - m_pres = b.m_pres; - m_mw = b.m_mw; + /* + * Call the base class operator + */ + PDSS::operator=(b); + + //! Need to call initAllPtrs AFTER, to get the correct m_waterSS + m_waterSS = 0; + m_pres = b.m_pres; + m_densWaterSS = b.m_densWaterSS; + //! Need to call initAllPtrs AFTER, to get the correct m_waterProps + if (m_waterProps) { + delete m_waterProps; + } + m_waterProps = 0; + m_born_coeff_j = b.m_born_coeff_j; + m_r_e_j = b.m_r_e_j; + m_deltaG_formation_tr_pr = b.m_deltaG_formation_tr_pr; + m_deltaH_formation_tr_pr = b.m_deltaH_formation_tr_pr; + m_Mu0_tr_pr = b.m_Mu0_tr_pr; + m_Entrop_tr_pr = b.m_Entrop_tr_pr; + m_a1 = b.m_a1; + m_a2 = b.m_a2; + m_a3 = b.m_a3; + m_a4 = b.m_a4; + m_c1 = b.m_c1; + m_c2 = b.m_c2; + m_omega_pr_tr = b.m_omega_pr_tr; + m_Y_pr_tr = b.m_Y_pr_tr; + m_Z_pr_tr = b.m_Z_pr_tr; + m_presR_bar = b.m_presR_bar; + m_domega_jdT_prtr = b.m_domega_jdT_prtr; + m_charge_j = b.m_charge_j; + + // Here we just fill these in so that local copies within the VPSS object work. + m_waterSS = b.m_waterSS; + m_waterProps = new WaterProps(m_waterSS); + return *this; } @@ -470,9 +524,7 @@ namespace Cantera { m_domega_jdT_prtr = - nu * (m_charge_j * m_charge_j / (r_e_j * r_e_j) * dr_e_jdT) - + nu * m_charge_j / (3.082 + gval) / (3.082 + gval) * dgvaldT; - - + + nu * m_charge_j / (3.082 + gval) / (3.082 + gval) * dgvaldT; } @@ -480,6 +532,17 @@ namespace Cantera { PDSS::initThermoXML(phaseNode, id); } + void PDSS_HKFT::initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, + SpeciesThermo* spthermo_ptr) { + + PDSS::initAllPtrs(vptp_ptr, vpssmgr_ptr, spthermo_ptr); + m_waterSS = (PDSS_Water *) m_tp->providePDSS(0); + if (m_waterProps) { + delete m_waterProps; + } + m_waterProps = new WaterProps(m_waterSS); + } + void PDSS_HKFT::constructPDSSXML(VPStandardStateTP *tp, int spindex, const XML_Node& speciesNode, const XML_Node& phaseNode, bool spInstalled) { @@ -602,8 +665,8 @@ namespace Cantera { } - std::string id = ""; - initThermoXML(phaseNode, id); + // std::string id = ""; + //initThermoXML(phaseNode, id); } void PDSS_HKFT::constructPDSSFile(VPStandardStateTP *tp, int spindex, diff --git a/Cantera/src/thermo/PDSS_HKFT.h b/Cantera/src/thermo/PDSS_HKFT.h index df32af0e8..3e71049c2 100644 --- a/Cantera/src/thermo/PDSS_HKFT.h +++ b/Cantera/src/thermo/PDSS_HKFT.h @@ -414,6 +414,24 @@ namespace Cantera { */ virtual void initThermoXML(const XML_Node& phaseNode, std::string& id); + //! Initialize or Reinitialize all shallow pointers in the object + /*! + * This command is called to reinitialize all shallow pointers in the + * object. It's needed for the duplicator capability + * + * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object + * This object must have already been malloced. + * + * @param vpssmgr_ptr Pointer to the variable pressure standard state + * calculator for this phase + * + * @param spthermo_ptr Pointer to the optional SpeciesThermo object + * that will handle the calculation of the reference + * state thermodynamic coefficients. + */ + virtual void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, + SpeciesThermo* spthermo_ptr); + //@} @@ -534,6 +552,7 @@ namespace Cantera { //! Water standard state calculator /*! * derived from the equation of state for water. + * This object doesn't own the object. Just a shallow pointer. */ PDSS_Water *m_waterSS; diff --git a/Cantera/src/thermo/PDSS_IdealGas.cpp b/Cantera/src/thermo/PDSS_IdealGas.cpp index 0dc1c60fd..558305b12 100644 --- a/Cantera/src/thermo/PDSS_IdealGas.cpp +++ b/Cantera/src/thermo/PDSS_IdealGas.cpp @@ -74,6 +74,10 @@ namespace Cantera { PDSS_IdealGas& PDSS_IdealGas::operator=(const PDSS_IdealGas&b) { if (&b == this) return *this; PDSS::operator=(b); + + m_tmin = b.m_tmin; + m_tmax = b.m_tmax; + return *this; } diff --git a/Cantera/src/thermo/PDSS_Water.cpp b/Cantera/src/thermo/PDSS_Water.cpp index ec703bf7d..54dff4432 100644 --- a/Cantera/src/thermo/PDSS_Water.cpp +++ b/Cantera/src/thermo/PDSS_Water.cpp @@ -140,6 +140,7 @@ namespace Cantera { SW_Offset = b.SW_Offset; m_verbose = b.m_verbose; m_allowGasPhase = b.m_allowGasPhase; + return *this; } @@ -158,7 +159,7 @@ namespace Cantera { * Initialization of a Debye-Huckel phase using an * xml file. * - * This routine is a precursor to initThermo(XML_Node*) + * This routine is a precursor to constructSet * routine, which does most of the work. * * @param infile XML file containing the description of the @@ -179,7 +180,7 @@ namespace Cantera { * Initialization of a Debye-Huckel phase using an * xml file. * - * This routine is a precursor to initThermo(XML_Node*) + * This routine is a precursor to constructPDSSXML(XML_Node*) * routine, which does most of the work. * * @param infile XML file containing the description of the diff --git a/Cantera/src/thermo/VPStandardStateTP.cpp b/Cantera/src/thermo/VPStandardStateTP.cpp index 164eb3f12..6518b9c19 100644 --- a/Cantera/src/thermo/VPStandardStateTP.cpp +++ b/Cantera/src/thermo/VPStandardStateTP.cpp @@ -414,8 +414,9 @@ namespace Cantera { m_VPSS_ptr->initThermo(); for (int k = 0; k < m_kk; k++) { PDSS *kPDSS = m_PDSS_storage[k]; + AssertTrace(kPDSS != 0); if (kPDSS) { - kPDSS->initThermo(); + kPDSS->initThermoXML(phaseNode, id); } } m_VPSS_ptr->initThermoXML(phaseNode, id);