From a42ef08f9c64559b9062eeec92ae8552a732c171 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 1 Jun 2007 19:12:18 +0000 Subject: [PATCH] Added copy constructors and assignment operators where they were missing. Working towards getting the duplicate member functions to work. --- Cantera/src/thermo/ConstDensityThermo.cpp | 29 +++++++++++++ Cantera/src/thermo/ConstDensityThermo.h | 14 ++++++- Cantera/src/thermo/GeneralSpeciesThermo.cpp | 2 +- Cantera/src/thermo/GeneralSpeciesThermo.h | 2 +- Cantera/src/thermo/MolalityVPSSTP.cpp | 4 -- Cantera/src/thermo/NasaThermo.h | 42 +++++++++++++++++++ Cantera/src/thermo/ShomateThermo.h | 38 +++++++++++++++++ Cantera/src/thermo/SimpleThermo.h | 37 +++++++++++++++++ Cantera/src/thermo/SpeciesThermo.h | 30 ++++++++++++++ Cantera/src/thermo/SpeciesThermoMgr.h | 46 +++++++++++++++++++++ Cantera/src/thermo/ThermoPhase.cpp | 5 ++- 11 files changed, 241 insertions(+), 8 deletions(-) diff --git a/Cantera/src/thermo/ConstDensityThermo.cpp b/Cantera/src/thermo/ConstDensityThermo.cpp index e576c04ea..6126a1669 100755 --- a/Cantera/src/thermo/ConstDensityThermo.cpp +++ b/Cantera/src/thermo/ConstDensityThermo.cpp @@ -23,6 +23,35 @@ namespace Cantera { + ConstDensityThermo::ConstDensityThermo() : m_tlast(0.0) { + } + + + ConstDensityThermo::ConstDensityThermo(const ConstDensityThermo &right) + : m_tlast(0.0) { + *this = operator=(right); + } + + ConstDensityThermo& ConstDensityThermo::operator=(const ConstDensityThermo &right) { + if (&right == this) return *this; + + m_mm = right.m_mm; + m_tmin = right.m_tmin; + m_tmax = right.m_tmax; + m_p0 = right.m_p0; + m_tlast = right.m_tlast; + m_h0_RT = right.m_h0_RT; + m_cp0_R = right.m_cp0_R; + m_g0_RT = right.m_g0_RT; + m_s0_R = right.m_s0_R; + m_expg0_RT = right.m_expg0_RT; + m_pe = right.m_pe; + m_pp = right.m_pp; + + return *this; + + } + int ConstDensityThermo:: eosType() const { return cIncompressible; } diff --git a/Cantera/src/thermo/ConstDensityThermo.h b/Cantera/src/thermo/ConstDensityThermo.h index 1e32b84b4..06370097f 100755 --- a/Cantera/src/thermo/ConstDensityThermo.h +++ b/Cantera/src/thermo/ConstDensityThermo.h @@ -54,11 +54,23 @@ namespace Cantera { /*! * */ - ConstDensityThermo() : m_tlast(0.0) {} + ConstDensityThermo(); //! Destructor virtual ~ConstDensityThermo() {} + //! Copy Constructor + /*! + * @param right Object to be copied + */ + ConstDensityThermo(const ConstDensityThermo &right); + + //! Assignment Operator + /*! + * @param right Object to be copied + */ + ConstDensityThermo& operator=(const ConstDensityThermo &right); + // overloaded methods of class ThermoPhase virtual int eosType() const; diff --git a/Cantera/src/thermo/GeneralSpeciesThermo.cpp b/Cantera/src/thermo/GeneralSpeciesThermo.cpp index 1dc4e736a..b2959ea44 100644 --- a/Cantera/src/thermo/GeneralSpeciesThermo.cpp +++ b/Cantera/src/thermo/GeneralSpeciesThermo.cpp @@ -44,7 +44,7 @@ namespace Cantera { m_sp = b.m_sp; } - const GeneralSpeciesThermo& + GeneralSpeciesThermo& GeneralSpeciesThermo::operator=(const GeneralSpeciesThermo &b) { if (&b != this) { m_tlow_max = b.m_tlow_max; diff --git a/Cantera/src/thermo/GeneralSpeciesThermo.h b/Cantera/src/thermo/GeneralSpeciesThermo.h index cf8f11d8e..5cb6d4417 100644 --- a/Cantera/src/thermo/GeneralSpeciesThermo.h +++ b/Cantera/src/thermo/GeneralSpeciesThermo.h @@ -46,7 +46,7 @@ namespace Cantera { GeneralSpeciesThermo(const GeneralSpeciesThermo &); //! Assignment operator - const GeneralSpeciesThermo & operator=(const GeneralSpeciesThermo &); + GeneralSpeciesThermo & operator=(const GeneralSpeciesThermo &); //! destructor virtual ~GeneralSpeciesThermo(); diff --git a/Cantera/src/thermo/MolalityVPSSTP.cpp b/Cantera/src/thermo/MolalityVPSSTP.cpp index 284a5e205..424f41332 100644 --- a/Cantera/src/thermo/MolalityVPSSTP.cpp +++ b/Cantera/src/thermo/MolalityVPSSTP.cpp @@ -66,8 +66,6 @@ namespace Cantera { m_Mnaught(b.m_Mnaught), m_molalities(b.m_molalities) { - throw CanteraError("MolalityVPSSTP::operator=()", - "Not Implemented Fully"); *this = operator=(b); } @@ -87,8 +85,6 @@ namespace Cantera { m_Mnaught = b.m_Mnaught; m_molalities = b.m_molalities; } - throw CanteraError("MolalityVPSSTP::operator=()", - "Not Implemented Fully"); return *this; } diff --git a/Cantera/src/thermo/NasaThermo.h b/Cantera/src/thermo/NasaThermo.h index 1b3b37df8..4f4ec94b5 100755 --- a/Cantera/src/thermo/NasaThermo.h +++ b/Cantera/src/thermo/NasaThermo.h @@ -73,6 +73,48 @@ namespace Cantera { m_t.resize(6); } + //! Copy constructor + /*! + * @param right NasaThermo object to be copied. + */ + NasaThermo(const NasaThermo &right) : + ID(NASA), + m_tlow_max(0.0), + m_thigh_min(1.e30), + m_p0(-1.0), + m_ngroups(0) + { + *this = operator=(right); + } + + //! Assignment operator + /*! + * @param right NasaThermo object to be copied. + */ + NasaThermo& operator=(const NasaThermo &right) { + /* + * Check for self assignment. + */ + if (this == &right) return *this; + + m_high = right.m_high; + m_low = right.m_low; + m_index = right.m_index; + m_tmid = right.m_tmid; + m_tlow_max = right.m_tlow_max; + m_thigh_min = right.m_thigh_min; + m_tlow = right.m_tlow; + m_thigh = right.m_thigh; + m_p0 = right.m_p0; + m_ngroups = right.m_ngroups; + m_t = right.m_t; + m_group_map = right.m_group_map; + m_posInGroup_map = right.m_posInGroup_map; + m_name = right.m_name; + + return *this; + } + //! destructor virtual ~NasaThermo() {} diff --git a/Cantera/src/thermo/ShomateThermo.h b/Cantera/src/thermo/ShomateThermo.h index ceaf72f6d..3932d417a 100755 --- a/Cantera/src/thermo/ShomateThermo.h +++ b/Cantera/src/thermo/ShomateThermo.h @@ -83,6 +83,44 @@ namespace Cantera { //! destructor virtual ~ShomateThermo() {} + //! Copy Constructor + /*! + * @param right Object to be copied + */ + ShomateThermo(const ShomateThermo &right) : + ID(SHOMATE), + m_tlow_max(0.0), + m_thigh_min(1.e30), + m_p0(-1.0), + m_ngroups(0) + { + *this = operator=(right); + } + + //! Assignment Operator + /*! + * @param right Object to be copied + */ + ShomateThermo& operator=(const ShomateThermo &right) { + if (&right == this) return *this; + + m_high = right.m_high; + m_low = right.m_low; + m_index = right.m_index; + m_tmid = right.m_tmid; + m_tlow_max = right.m_tlow_max; + m_thigh_min = right.m_thigh_min; + m_tlow = right.m_tlow; + m_thigh = right.m_thigh; + m_p0 = right.m_p0; + m_ngroups = right.m_ngroups; + m_t = right.m_t; + m_group_map = right.m_group_map; + m_posInGroup_map = right.m_posInGroup_map; + + return *this; + } + //! Install a new species thermodynamic property //! parameterization for one species using Shomate polynomials //! diff --git a/Cantera/src/thermo/SimpleThermo.h b/Cantera/src/thermo/SimpleThermo.h index 0ede23ad9..41e2bf3ad 100644 --- a/Cantera/src/thermo/SimpleThermo.h +++ b/Cantera/src/thermo/SimpleThermo.h @@ -69,6 +69,43 @@ namespace Cantera { //! Destructor virtual ~SimpleThermo() {} + //! Copy constructor + SimpleThermo(const SimpleThermo &right) : + ID(SIMPLE), + m_tlow_max(0.0), + m_thigh_min(1.e30), + m_p0(-1.0), + m_nspData(0) { + /* + * Call the assignment operator + */ + *this = operator=(right); + } + + //! Assignment operator + SimpleThermo& SimpleThermo::operator=(const SimpleThermo &right) { + /* + * Check for self assignment. + */ + if (this == &right) return *this; + + m_loc = right.m_loc; + m_index = right.m_index; + m_tlow_max = right.m_tlow_max; + m_thigh_min = right.m_thigh_min; + m_tlow = right.m_tlow; + m_thigh = right.m_thigh; + m_t0 = right.m_t0; + m_logt0 = right.m_logt0; + m_h0_R = right.m_h0_R; + m_s0_R = right.m_s0_R; + m_cp0_R = right.m_cp0_R; + m_p0 = right.m_p0; + m_nspData = right.m_nspData; + + return *this; + } + //! Install a new species thermodynamic property //! parameterization for one species. /*! diff --git a/Cantera/src/thermo/SpeciesThermo.h b/Cantera/src/thermo/SpeciesThermo.h index eac95c520..e6482629a 100755 --- a/Cantera/src/thermo/SpeciesThermo.h +++ b/Cantera/src/thermo/SpeciesThermo.h @@ -148,6 +148,36 @@ namespace Cantera { //! Destructor virtual ~SpeciesThermo() {} + + //! Copy Constructor for the %SpeciesThermo object. + /*! + * @param right Reference to %SpeciesThermo object to be copied into the + * current one. + */ + SpeciesThermo(const SpeciesThermo &right) {} + + //! Assignment operator for the %SpeciesThermo object + /*! + * This is NOT a virtual function. + * + * @param right Reference to %SpeciesThermo object to be copied into the + * current one. + */ + SpeciesThermo& operator=(const SpeciesThermo &right) { + return *this; + } + + + //! Duplication routine for objects which inherit from + //! %SpeciesThermo + /*! + * This virtual routine can be used to duplicate %SpeciesThermo objects + * inherited from %SpeciesThermo even if the application only has + * a pointer to %SpeciesThermo to work with. + * ->commented out because we first need to add copy constructors + * and assignment operators to all of the derived classes. + */ + // virtual SpeciesThermo *duplMyselfAsSpeciesThermo() const = 0; //! Install a new species thermodynamic property //! parameterization for one species. diff --git a/Cantera/src/thermo/SpeciesThermoMgr.h b/Cantera/src/thermo/SpeciesThermoMgr.h index c82aef6e1..2ce0e6d1b 100755 --- a/Cantera/src/thermo/SpeciesThermoMgr.h +++ b/Cantera/src/thermo/SpeciesThermoMgr.h @@ -156,6 +156,31 @@ namespace Cantera { //! Destructor virtual ~SpeciesThermoDuo(){} + + //! copy constructor + SpeciesThermoDuo(const SpeciesThermoDuo &right) { + *this = operator=(right); + } + + //! Assignment operator + /*! + * @param right Object to be copied + */ + SpeciesThermoDuo& operator=(const SpeciesThermoDuo &right) { + if (right == *this) return *this; + + m_thermo1 = right.m_thermo1; + m_thermo2 = right.m_thermo2; + m_p0 = m_p0; + speciesToType = right.speciesToType; + + return *this; + } + + //virtual SpeciesThermo *duplMyselfAsSpeciesThermo() const { + // SpeciesThermoDuo *std = new SpeciesThermoDuo(*this); + // return (SpeciesThermo *) std; + //} /** * install a new species thermodynamic property * parameterization for one species. @@ -370,6 +395,27 @@ namespace Cantera { SpeciesThermo1() : m_pref(0.0) {} //! destructor virtual ~SpeciesThermo1(){} + + //! Copy Constructor + SpeciesThermo1(const SpeciesThermo1 &right) : + m_pref(0.0) + { + *this = operator=(right); + } + + + //! Asignment Operator + /*! + * @param right Object to be copied + */ + SpeciesThermo1 & operator=(const SpeciesThermo1 &right) { + if (right == *this) return *this; + + m_thermo = right.m_thermo; + m_pref = right.m_pref; + + return *this; + } //! Install one species into this Species Thermo Manager /*! diff --git a/Cantera/src/thermo/ThermoPhase.cpp b/Cantera/src/thermo/ThermoPhase.cpp index d04deb731..5b301aa38 100644 --- a/Cantera/src/thermo/ThermoPhase.cpp +++ b/Cantera/src/thermo/ThermoPhase.cpp @@ -87,12 +87,14 @@ namespace Cantera { delete m_spthermo; } //m_spthermo = (right.m_spthermo)->duplMyselfAsSpeciesThermo(); - throw CanteraError("ThermoPhase assignment", "not implemented"); + throw CanteraError("ThermoPhase::operator=()", "SpeciesThermo dupl not impl"); + /// Pointer to the XML tree containing the species /// data for this phase. This is used to access data needed to /// construct the transport manager and other properties /// later in the initialization process. + // We don't do a deep copy here, because we don't own this m_speciesData = right.m_speciesData; @@ -100,6 +102,7 @@ namespace Cantera { m_phi = right.m_phi; m_lambdaRRT = right.m_lambdaRRT; m_hasElementPotentials = right.m_hasElementPotentials; + m_chargeNeutralityNecessary = right.m_chargeNeutralityNecessary; return *this; }