Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace convenience classes by C++ Solution object #735

Merged
merged 9 commits into from
Nov 8, 2019
9 changes: 9 additions & 0 deletions include/cantera/Edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef CXX_EDGE
#define CXX_EDGE

#pragma message("warning: Edge.h is deprecated and will be removed after Cantera 2.5.0.")

#include "thermo/ThermoFactory.h"
#include "kinetics/importKinetics.h"
#include "kinetics/EdgeKinetics.h"
Expand All @@ -15,13 +17,20 @@ namespace Cantera
{

//! Convenience class which inherits from both EdgePhase and EdgeKinetics
/*!
* @deprecated To be removed after Cantera 2.5.0.
* Replaceable with Solution and/or EdgePhase/EdgeKinetics.
*/
class Edge :
public EdgePhase, public EdgeKinetics
{
public:
Edge(const std::string& infile, std::string id, std::vector<ThermoPhase*> phases)
: m_ok(false), m_r(0)
{
warn_deprecated("class Metal",
"To be removed after Cantera 2.5.0. "
"Replaceable with Solution and/or EdgePhase/EdgeKinetics.");
m_r = get_XML_File(infile);
if (id == "-") {
id = "";
Expand Down
15 changes: 15 additions & 0 deletions include/cantera/IdealGasMix.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef CXX_IDEALGASMIX
#define CXX_IDEALGASMIX

#pragma message("warning: IdealGasMix.h is deprecated and will be removed after Cantera 2.5.")

#include "thermo/IdealGasPhase.h"
#include "kinetics/GasKinetics.h"
#include "kinetics/importKinetics.h"
Expand All @@ -15,6 +17,10 @@ namespace Cantera
{

//! Convenience class which inherits from both IdealGasPhase and GasKinetics
/*!
* @deprecated To be removed after Cantera 2.5.
* Replaceable with Solution and/or IdealGasPhase/GasKinetics.
*/
class IdealGasMix :
public IdealGasPhase,
public GasKinetics
Expand All @@ -25,6 +31,9 @@ class IdealGasMix :
IdealGasMix(const std::string& infile, std::string id_="") :
m_ok(false), m_r(0)
{
warn_deprecated("class IdealGasMix",
"To be removed after Cantera 2.5. "
"Replaceable with Solution and/or IdealGasPhase/GasKinetics.");
m_r = get_XML_File(infile);
m_id = id_;
if (id_ == "-") {
Expand All @@ -38,12 +47,18 @@ class IdealGasMix :

IdealGasMix(XML_Node& root,
std::string id_) : m_ok(false), m_r(&root), m_id(id_) {
warn_deprecated("class IdealGasMix",
"To be removed after Cantera 2.5. "
"Replaceable with Solution and/or IdealGasPhase/GasKinetics.");
m_ok = buildSolutionFromXML(root, id_, "phase", this, this);
}

IdealGasMix(const IdealGasMix& other) : m_ok(false),
m_r(other.m_r),
m_id(other.m_id) {
warn_deprecated("class IdealGasMix",
"To be removed after Cantera 2.5. "
"Replaceable with Solution and/or IdealGasPhase/GasKinetics.");
m_ok = buildSolutionFromXML(*m_r, m_id, "phase", this, this);
}

Expand Down
11 changes: 10 additions & 1 deletion include/cantera/IncompressibleSolid.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,35 @@
#ifndef CXX_INCOMPRESSIBLE
#define CXX_INCOMPRESSIBLE

#pragma message("warning: IncompressibleSolid.h is deprecated and will be removed after Cantera 2.5.0.")

#include "thermo/ConstDensityThermo.h"
#include "kinetics/importKinetics.h"

namespace Cantera
{

//! Wrapper for ConstDensityThermo with constructor from file
/*!
* @deprecated To be removed after Cantera 2.5.0.
* Replaceable with Solution and/or LatticePhase/IdealSolidSolnPhase.
*/
class IncompressibleSolid : public ConstDensityThermo
{
public:
IncompressibleSolid(const std::string& infile,
std::string id="") : m_ok(false), m_r(0)
{
warn_deprecated("class IncompressibleSolid",
"To be removed after Cantera 2.5.0. "
"Replaceable with Solution and/or LatticePhase/IdealSolidSolnPhase.");
m_r = get_XML_File(infile);
if (id == "-") {
id = "";
}
m_ok = buildSolutionFromXML(*m_r, id, "phase", this, 0);
if (!m_ok) throw CanteraError("IncompressibleSolid",
"buildSolutionFromXML returned false");
"buildSolutionFromXML returned false");
}

bool operator!() {
Expand Down
13 changes: 13 additions & 0 deletions include/cantera/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef CXX_INTERFACE
#define CXX_INTERFACE

#pragma message("warning: Interface.h is deprecated and will be removed after Cantera 2.5.")

#include "thermo.h"
#include "kinetics.h"
#include "cantera/thermo/SurfPhase.h"
Expand All @@ -22,6 +24,9 @@ namespace Cantera
* and InterfaceKinetics. It therefore represents a surface phase, and also acts
* as the kinetics manager to manage reactions occurring on the surface,
* possibly involving species from other phases.
*
* @deprecated To be removed after Cantera 2.5.
* Replaceable with Solution and/or SurfPhase/InterfaceKinetics.
*/
class Interface :
public SurfPhase,
Expand All @@ -42,6 +47,10 @@ class Interface :
std::vector<ThermoPhase*> otherPhases) :
m_ok(false),
m_r(0) {
warn_deprecated("class Interface",
"To be removed after Cantera 2.5. "
"Replaceable with Solution and/or SurfPhase/InterfaceKinetics.");

m_r = get_XML_File(infile);
if (id == "-") {
id = "";
Expand Down Expand Up @@ -79,11 +88,15 @@ class Interface :
//! Import an instance of class Interface from a specification in an input file.
/*!
* This is the preferred method to create an Interface instance.
*
* @deprecated To be removed after Cantera 2.5. Replaceable with Solution.
*/
inline Interface* importInterface(const std::string& infile,
const std::string& id,
std::vector<ThermoPhase*> phases)
{
warn_deprecated("importInterface", "To be removed after Cantera 2.5. "
"Replaceable with Solution.");
return new Interface(infile, id, phases);
}

Expand Down
11 changes: 10 additions & 1 deletion include/cantera/Metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,34 @@
#ifndef CXX_METAL
#define CXX_METAL

#pragma message("warning: Metal.h is deprecated and will be removed after Cantera 2.5.0.")

#include "thermo/MetalPhase.h"
#include "kinetics/importKinetics.h"

namespace Cantera
{

//! Wrapper for MetalPhase with constructor from file
/*!
* @deprecated To be removed after Cantera 2.5.0.
* Replaceable with Solution and/or MetalPhase.
*/
class Metal : public MetalPhase
{
public:
Metal(const std::string& infile, std::string id="") : m_ok(false), m_r(0)
{
warn_deprecated("class Metal",
"To be removed after Cantera 2.5.0. "
"Replaceable with Solution and/or MetalPhase.");
m_r = get_XML_File(infile);
if (id == "-") {
id = "";
}
m_ok = buildSolutionFromXML(*m_r, id, "phase", this, 0);
if (!m_ok) throw CanteraError("Metal::Metal",
"buildSolutionFromXML returned false");
"buildSolutionFromXML returned false");
}

bool operator!() {
Expand Down
38 changes: 28 additions & 10 deletions include/cantera/base/Solution.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Solution : public std::enable_shared_from_this<Solution>
Solution(const Solution&) = delete;
Solution& operator=(const Solution&) = delete;

//! Create an empty Solution object
static shared_ptr<Solution> create() {
return shared_ptr<Solution>( new Solution );
}
Expand All @@ -37,27 +38,27 @@ class Solution : public std::enable_shared_from_this<Solution>
void setName(const std::string& name);

//! Set the ThermoPhase object
void setThermoPhase(shared_ptr<ThermoPhase> thermo);
void setThermo(shared_ptr<ThermoPhase> thermo);

//! Set the Kinetics object
void setKinetics(shared_ptr<Kinetics> kinetics);

//! Set the Transport object
void setTransport(shared_ptr<Transport> transport);

//! Accessor for the ThermoPhase object
ThermoPhase& thermo() {
return *m_thermo;
//! Accessor for the ThermoPhase pointer
shared_ptr<ThermoPhase> thermo() {
return m_thermo;
}

//! Accessor for the Kinetics object
Kinetics& kinetics() {
return *m_kinetics;
//! Accessor for the Kinetics pointer
shared_ptr<Kinetics> kinetics() {
return m_kinetics;
}

//! Accessor for the Transport object
Transport& transport() {
return *m_transport;
//! Accessor for the Transport pointer
shared_ptr<Transport> transport() {
return m_transport;
}

protected:
Expand All @@ -66,5 +67,22 @@ class Solution : public std::enable_shared_from_this<Solution>
shared_ptr<Transport> m_transport; //!< Transport manager
};

//! Create and initialize a new Solution manager from an input file
/*!
* This constructor wraps newPhase(), newKinetics() and
* newTransportMgr() routines for initialization.
*
* @param infile name of the input file
* @param name name of the phase in the file.
* If this is blank, the first phase in the file is used.
* @param transport name of the transport model.
* @param adjacent vector containing adjacent solution objects.
* @returns an initialized Solution object.
*/
shared_ptr<Solution> newSolution(const std::string& infile,
const std::string& name="",
const std::string& transport="",
const std::vector<shared_ptr<Solution>>& adjacent={});

}
#endif
1 change: 1 addition & 0 deletions include/cantera/kinetics/InterfaceKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ class InterfaceKinetics : public Kinetics
//! EdgeKinetics)
size_t m_nDim;
};

}

#endif
2 changes: 0 additions & 2 deletions include/cantera/kinetics/Kinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
namespace Cantera
{

class Solution;

/**
* @defgroup chemkinetics Chemical Kinetics
*/
Expand Down
7 changes: 6 additions & 1 deletion include/cantera/oneD/StFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class StFlow : public Domain1D
//! to evaluate all thermodynamic, kinetic, and transport properties.
//! @param nsp Number of species.
//! @param points Initial number of grid points
StFlow(IdealGasPhase* ph = 0, size_t nsp = 1, size_t points = 1);
StFlow(ThermoPhase* ph = 0, size_t nsp = 1, size_t points = 1);

//! Delegating constructor
StFlow(shared_ptr<ThermoPhase> th, size_t nsp = 1, size_t points = 1) :
StFlow(th.get(), nsp, points) {
}

//! @name Problem Specification
//! @{
Expand Down
1 change: 1 addition & 0 deletions include/cantera/thermo/IdealGasPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ class IdealGasPhase: public ThermoPhase
*/
void _updateThermo() const;
};

}

#endif
3 changes: 1 addition & 2 deletions include/cantera/thermo/Phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define CT_PHASE_H

#include "cantera/base/ctexceptions.h"
#include "cantera/base/Solution.h"
#include "cantera/thermo/Elements.h"
#include "cantera/thermo/Species.h"
#include "cantera/base/ValueCache.h"
Expand All @@ -29,8 +30,6 @@ namespace Cantera
* support thermodynamic calculations (see \ref thermoprops).
*/

class Solution;

//! Class Phase is the base class for phases of matter, managing the species and
//! elements in a phase, as well as the independent variables of temperature,
//! mass density, species mass/mole fraction, and other generalized forces and
Expand Down
1 change: 1 addition & 0 deletions include/cantera/thermo/SurfPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ class SurfPhase : public ThermoPhase
*/
void _updateThermo(bool force=false) const;
};

}

#endif
2 changes: 0 additions & 2 deletions include/cantera/transport/TransportBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const VelocityBasis VB_SPECIES_2 = 2;
const VelocityBasis VB_SPECIES_3 = 3;
//@}

class Solution;

//! Base class for transport property managers.
/*!
* All classes that compute transport properties for a single phase derive from
Expand Down
5 changes: 5 additions & 0 deletions include/cantera/zeroD/Reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class Reactor : public ReactorBase
setKineticsMgr(contents);
}

void insert(shared_ptr<Solution> sol) {
setThermoMgr(*sol->thermo());
setKineticsMgr(*sol->kinetics());
}

virtual void setKineticsMgr(Kinetics& kin);

virtual void setChemistry(bool cflag = true) {
Expand Down
4 changes: 4 additions & 0 deletions include/cantera/zeroD/Reservoir.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Reservoir : public ReactorBase
void insert(ThermoPhase& contents) {
setThermoMgr(contents);
}

void insert(shared_ptr<Solution> sol) {
setThermoMgr(*sol->thermo());
}
};

}
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ cdef extern from "cantera/base/Solution.h" namespace "Cantera":
CxxSolution()
string name()
void setName(string)
void setThermoPhase(shared_ptr[CxxThermoPhase])
void setThermo(shared_ptr[CxxThermoPhase])
void setKinetics(shared_ptr[CxxKinetics])
void setTransport(shared_ptr[CxxTransport])

Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cdef class _SolutionBase:
raise ValueError("Arguments are insufficient to define a phase")

# Initialization of transport is deferred to Transport.__init__
self.base.setThermoPhase(self._thermo)
self.base.setThermo(self._thermo)
self.base.setKinetics(self._kinetics)

self._selected_species = np.ndarray(0, dtype=np.integer)
Expand Down
Loading