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

Create SolutionBase object in C++ #696

Merged
merged 17 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions include/cantera/base/Solution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//! @file Solution.h

// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.

#ifndef CT_SOLUTION_H
#define CT_SOLUTION_H

#include "cantera/base/ctexceptions.h"

namespace Cantera
{

class ThermoPhase;
class Kinetics;
class Transport;

//! A container class holding managers for all pieces defining a phase
class Solution : public std::enable_shared_from_this<Solution>
{
private:
Solution();

public:
~Solution() {}
Solution(const Solution&) = delete;
Solution& operator=(const Solution&) = delete;

static shared_ptr<Solution> create() {
return shared_ptr<Solution>( new Solution );
}

//! Return the name of this Solution object
std::string name() const;

//! Set the name of this Solution object
void setName(const std::string& name);

//! Set the ThermoPhase object
void setThermoPhase(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;
}
ischoegl marked this conversation as resolved.
Show resolved Hide resolved

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

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

protected:
shared_ptr<ThermoPhase> m_thermo; //!< ThermoPhase manager
shared_ptr<Kinetics> m_kinetics; //!< Kinetics manager
shared_ptr<Transport> m_transport; //!< Transport manager
};

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

class Solution;

/**
* @defgroup chemkinetics Chemical Kinetics
*/
Expand Down Expand Up @@ -814,6 +816,11 @@ class Kinetics
void selectPhase(const doublereal* data, const thermo_t* phase,
doublereal* phase_data);

//! Set root Solution holding all phase information
virtual void setRoot(std::shared_ptr<Solution> root) {
m_root = root;
}

protected:
//! Cache for saved calculations within each Kinetics object.
ValueCache m_cache;
Expand Down Expand Up @@ -935,6 +942,9 @@ class Kinetics

//! @see skipUndeclaredThirdBodies()
bool m_skipUndeclaredThirdBodies;

//! reference to Solution
std::weak_ptr<Solution> m_root;
};

}
Expand Down
51 changes: 29 additions & 22 deletions include/cantera/thermo/Phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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 Expand Up @@ -66,15 +68,11 @@ namespace Cantera
* operate on a state vector, which is in general of length (2 + nSpecies()).
* The first two entries of the state vector are temperature and density.
*
* A species name may be referred to via three methods:
*
* - "speciesName"
* - "PhaseId:speciesName"
* - "phaseName:speciesName"
* .
*
* The first two methods of naming may not yield a unique species within
* complicated assemblies of %Cantera Phases.
* A species name is referred to via speciesName(), which is unique within a
* given phase. Note that within multiphase mixtures (MultiPhase()), both a
* phase name/index as well as species name are required to access information
* about a species in a particular phase. For surfaces, the species names are
* unique among the phases.
*
* @todo
* - Make the concept of saving state vectors more general, so that it can
Expand Down Expand Up @@ -122,30 +120,31 @@ class Phase
*/
void setXMLdata(XML_Node& xmlPhase);

/*! @name Name and ID
* Class Phase contains two strings that identify a phase. The ID is the
* value of the ID attribute of the XML phase node that is used to
* initialize a phase when it is read. The name field is also initialized
* to the value of the ID attribute of the XML phase node.
/*! @name Name
* Class Phase uses the string name to identify a phase. The name is the
* value of the corresponding key in the phase map (in YAML), name (in
* CTI), or id (in XML) that is used to initialize a phase when it is read.
*
* However, the name field may be changed to another value during the
* course of a calculation. For example, if a phase is located in two
* places, but has the same constitutive input, the IDs of the two phases
* will be the same, but the names of the two phases may be different.
*
* It is an error to have two phases in a single problem with the same name
* and ID (or the name from one phase being the same as the id of
* another phase). Thus, it is expected that there is a 1-1 correspondence
* between names and unique phases within a Cantera problem.
* course of a calculation. For example, if duplicates of a phase object
* are instantiated and used in multiple places (e.g. a ReactorNet), they
* will have the same constitutive input, i.e. the names of the phases will
* be the same. Note that this is not a problem for Cantera internally;
* however, a user may want to rename phase objects in order to clarify.
*/
//!@{

//! Return the string id for the phase.
/*!
* @deprecated To be removed after Cantera 2.5.
*/
std::string id() const;

//! Set the string id for the phase.
/*!
* @param id String id of the phase
*
* @deprecated To be removed after Cantera 2.5.
*/
void setID(const std::string& id);

Expand Down Expand Up @@ -758,6 +757,11 @@ class Phase
m_caseSensitiveSpecies = cflag;
}

//! Set root Solution holding all phase information
virtual void setRoot(std::shared_ptr<Solution> root) {
m_root = root;
}

protected:
//! Cached for saved calculations within each ThermoPhase.
/*!
Expand Down Expand Up @@ -870,6 +874,9 @@ class Phase

//! Entropy at 298.15 K and 1 bar of stable state pure elements (J kmol-1)
vector_fp m_entropy298;

//! reference to Solution
std::weak_ptr<Solution> m_root;
};

}
Expand Down
10 changes: 10 additions & 0 deletions include/cantera/transport/TransportBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ 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 Expand Up @@ -654,6 +656,11 @@ class Transport
*/
virtual void setThermo(thermo_t& thermo);

//! Set root Solution holding all phase information
virtual void setRoot(std::shared_ptr<Solution> root) {
m_root = root;
}

protected:
//! Enable the transport object for use.
/*!
Expand All @@ -680,6 +687,9 @@ class Transport
//! Velocity basis from which diffusion velocities are computed.
//! Defaults to the mass averaged basis = -2
int m_velocityBasis;

//! reference to Solution
std::weak_ptr<Solution> m_root;
};

}
Expand Down
19 changes: 15 additions & 4 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,26 @@ cdef extern from "cantera/thermo/Species.h" namespace "Cantera":
cdef shared_ptr[CxxSpecies] CxxNewSpecies "newSpecies" (CxxAnyMap&) except +translate_exception
cdef vector[shared_ptr[CxxSpecies]] CxxGetSpecies "getSpecies" (CxxAnyValue&) except +translate_exception


cdef extern from "cantera/base/Solution.h" namespace "Cantera":
cdef cppclass CxxSolution "Cantera::Solution":
CxxSolution()
string name()
void setName(string)
void setThermoPhase(shared_ptr[CxxThermoPhase])
void setKinetics(shared_ptr[CxxKinetics])
void setTransport(shared_ptr[CxxTransport])

cdef shared_ptr[CxxSolution] CxxNewSolution "Cantera::Solution::create" ()


cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
cdef cppclass CxxThermoPhase "Cantera::ThermoPhase":
CxxThermoPhase()

# miscellaneous
string type()
string report(cbool, double) except +translate_exception
string name()
void setName(string)
string id()
void setID(string)
double minTemp() except +translate_exception
double maxTemp() except +translate_exception
double refPressure() except +translate_exception
Expand Down Expand Up @@ -928,6 +937,8 @@ cdef class GasTransportData:
cdef _assign(self, shared_ptr[CxxTransportData] other)

cdef class _SolutionBase:
cdef shared_ptr[CxxSolution] _base
cdef CxxSolution* base
cdef shared_ptr[CxxThermoPhase] _thermo
cdef CxxThermoPhase* thermo
cdef shared_ptr[CxxKinetics] _kinetics
Expand Down
Loading