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

Smart clib cabinets / add Solution to clib API #1448

Merged
merged 31 commits into from Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f695ea6
[test-problems] Fix clib-test.c
ischoegl Mar 2, 2023
5eede14
[clib] Implement SharedCabinet using shared_ptr list
ischoegl Mar 1, 2023
54a9360
[clib] Implement methods using SolutionCabinet
ischoegl Mar 1, 2023
a315281
[Transport] Deprecate legacy factory constructors
ischoegl Mar 1, 2023
c11f6b4
[clib] Switch TransportCabinet to smart pointers
ischoegl Mar 1, 2023
3d3501f
[Kinetics] Change smart pointer type for newKinetics
ischoegl Mar 1, 2023
ebb8e26
[clib] Switch KineticsCabinet to smart pointers
ischoegl Mar 1, 2023
7065269
[Thermo] Add factory methods returning shared_ptr
ischoegl Mar 1, 2023
6f40d73
[clib] Switch ThermoCabinet to smart pointers
ischoegl Mar 1, 2023
5b97aef
[clib] Add Reactor::insert to clib
ischoegl Mar 2, 2023
3907a15
[Kinetics] Update factory constructors
ischoegl Mar 2, 2023
fc5719c
[Kinetics] Deprecate non-default constructors
ischoegl Mar 3, 2023
e0604cd
[Kinetics] Used shared pointers in Kinetics::addPhase
ischoegl Mar 3, 2023
7c46ca3
[oneD] Enable Kinetics/Transport setters for smart pointers
ischoegl Mar 2, 2023
be944d5
[clib] Construct ctonedim from smart pointers
ischoegl Mar 2, 2023
17c1c6c
[clib] Shorten solution_ prefix to soln_
ischoegl Mar 4, 2023
dbdff61
[Thermo] Shorten newThermoBase to newThermo
ischoegl Mar 5, 2023
19ccef0
[clib] Adopt review comments
ischoegl Mar 5, 2023
5c3b07a
[fortran] Switch to smart clib cabinets
ischoegl Mar 1, 2023
ec05d85
[unittests] Remove legacy factory methods
ischoegl Mar 1, 2023
c7c2f0a
[test-problems] Replace legacy factory methods
ischoegl Mar 1, 2023
8039649
[Python] Update API
ischoegl Mar 2, 2023
f0e7833
[unittest] Implement gtest for 'test-clib'
ischoegl Mar 1, 2023
2929b0c
[unittests] Implement gtest for 'test-oneD'
ischoegl Mar 5, 2023
dfc6cce
[.NET] Add solution to sourcegen configuration
ischoegl Mar 1, 2023
2976be9
Rename Kinetics::addPhase to Kinetics::addThermo
ischoegl Mar 5, 2023
259c6da
[clib] Add reverse lookup table to SharedCabinet
ischoegl Mar 5, 2023
c5bf0db
[clib] Prevent memory leaks in lookup table
ischoegl Mar 6, 2023
07e9210
Clarify deprecation warnings
ischoegl Mar 6, 2023
7935229
[clib] Fix exception handling
ischoegl Mar 6, 2023
90b19b4
Prevent infinite recursion in Solution callbacks
speth Mar 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/cantera/base/Interface.h
Expand Up @@ -52,7 +52,7 @@ class Interface : public Solution

//! Create and initialize a new Interface from an input file
/*!
* This constructor wraps newPhase() and newKinetics()
* This constructor wraps newThermo() and newKinetics()
*
* @param infile name of the input file
* @param name name of the surface phase in the file.
Expand All @@ -68,7 +68,7 @@ shared_ptr<Interface> newInterface(const std::string& infile,

//! Create and initialize a new Interface from an input file
/*!
* This constructor wraps newPhase() and newKinetics()
* This constructor wraps newThermo() and newKinetics()
*
* @param infile name of the input file
* @param name name of the phase in the file. If this is the empty string, the first
Expand All @@ -82,7 +82,7 @@ shared_ptr<Interface> newInterface(const std::string& infile,

//! Create and initialize a new Interface from AnyMap objects
/*!
* This constructor wraps newPhase() and newKinetics()
* This constructor wraps newThermo() and newKinetics()
*
* @param phaseNode the node containing the phase definition (that is, thermo model,
* list of species, and initial state)
Expand Down
14 changes: 7 additions & 7 deletions include/cantera/base/Solution.h
Expand Up @@ -49,9 +49,9 @@ class Solution : public std::enable_shared_from_this<Solution>
virtual void setTransport(shared_ptr<Transport> transport);

//! Set the Transport object by name
//! @param model name of transport model
//! @param model name of transport model; if omitted, the default model is used
//! @since New in Cantera 3.0
void setTransportModel(const std::string& model);
void setTransportModel(const std::string& model="");

//! Accessor for the ThermoPhase pointer
shared_ptr<ThermoPhase> thermo() {
Expand Down Expand Up @@ -148,7 +148,7 @@ class Solution : public std::enable_shared_from_this<Solution>

//! Create and initialize a new Solution from an input file
/*!
* This constructor wraps newPhase(), newKinetics() and newTransportMgr() routines
* This constructor wraps newThermo(), newKinetics() and newTransport() routines
* for initialization.
*
* @param infile name of the input file
Expand All @@ -166,8 +166,8 @@ shared_ptr<Solution> newSolution(const std::string& infile, const std::string& n

//! Create and initialize a new Solution manager from an input file
/*!
* This constructor wraps newPhase(), newKinetics() and
* newTransportMgr() routines for initialization.
* This constructor wraps newThermo(), newKinetics() and newTransport() routines
* for initialization.
*
* @param infile name of the input file
* @param name name of the phase in the file.
Expand All @@ -184,8 +184,8 @@ shared_ptr<Solution> newSolution(const std::string& infile,

//! Create and initialize a new Solution manager from AnyMap objects
/*!
* This constructor wraps newPhase(), newKinetics() and
* newTransportMgr() routines for initialization.
* This constructor wraps newThermo(), newKinetics() and newTransport() routines
* for initialization.
*
* @param phaseNode the node containing the phase definition (that is, thermo model,
* list of species, and initial state)
Expand Down
16 changes: 16 additions & 0 deletions include/cantera/clib/ct.h
Expand Up @@ -16,6 +16,21 @@ extern "C" {

CANTERA_CAPI int ct_appdelete();

CANTERA_CAPI int soln_newSolution(const char* infile,
const char* name,
const char* transport);
CANTERA_CAPI int soln_newInterface(const char* infile,
const char* name,
int na,
const int* adjacent);
CANTERA_CAPI int soln_del(int n); //!< note that linked objects are deleted as well
CANTERA_CAPI int soln_name(int n, int buflen, char* buf);
CANTERA_CAPI int soln_thermo(int n);
CANTERA_CAPI int soln_kinetics(int n);
CANTERA_CAPI int soln_transport(int n);
CANTERA_CAPI size_t soln_nAdjacent(int n);
CANTERA_CAPI int soln_adjacent(int n, int a);

CANTERA_CAPI int thermo_newFromFile(const char* filename, const char* phasename);
CANTERA_CAPI int thermo_del(int n);
CANTERA_CAPI size_t thermo_nElements(int n);
Expand Down Expand Up @@ -166,6 +181,7 @@ extern "C" {
CANTERA_CAPI int ct_suppress_thermo_warnings(int suppress);
CANTERA_CAPI int ct_use_legacy_rate_constants(int legacy);
CANTERA_CAPI int ct_clearStorage();
CANTERA_CAPI int ct_resetStorage();

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions include/cantera/clib/ctreactor.h
Expand Up @@ -21,6 +21,7 @@ extern "C" {
CANTERA_CAPI int reactor_setEnergy(int i, int eflag);
CANTERA_CAPI int reactor_setThermoMgr(int i, int n);
CANTERA_CAPI int reactor_setKineticsMgr(int i, int n);
CANTERA_CAPI int reactor_insert(int i, int n);
CANTERA_CAPI double reactor_mass(int i);
CANTERA_CAPI double reactor_volume(int i);
CANTERA_CAPI double reactor_density(int i);
Expand Down
5 changes: 4 additions & 1 deletion include/cantera/kinetics/BulkKinetics.h
Expand Up @@ -20,7 +20,10 @@ namespace Cantera
class BulkKinetics : public Kinetics
{
public:
BulkKinetics(ThermoPhase* thermo = 0);
BulkKinetics();

//! @deprecated To be removed after Cantera 3.0; code base only uses default.
BulkKinetics(ThermoPhase* thermo);

virtual void resizeReactions();

Expand Down
8 changes: 4 additions & 4 deletions include/cantera/kinetics/GasKinetics.h
Expand Up @@ -28,10 +28,10 @@ class GasKinetics : public BulkKinetics
//! @{

//! Constructor.
/*!
* @param thermo Pointer to the gas ThermoPhase (optional)
*/
GasKinetics(ThermoPhase* thermo = 0);
GasKinetics();

//! @deprecated To be removed after Cantera 3.0; code base only uses default.
GasKinetics(ThermoPhase* thermo);

virtual std::string kineticsType() const {
return "Gas";
Expand Down
13 changes: 10 additions & 3 deletions include/cantera/kinetics/InterfaceKinetics.h
Expand Up @@ -56,15 +56,19 @@ class ImplicitSurfChem;
class InterfaceKinetics : public Kinetics
{
public:
//! Constructor
InterfaceKinetics();

//! Constructor
/*!
* @param thermo The optional parameter may be used to initialize the object
* @param thermo The parameter may be used to initialize the object
* with one ThermoPhase object.
* HKM Note -> Since the interface kinetics object will
* probably require multiple ThermoPhase objects, this is
* probably not a good idea to have this parameter.
* @deprecated To be removed after Cantera 3.0; code base only uses default.
*/
InterfaceKinetics(ThermoPhase* thermo = 0);
InterfaceKinetics(ThermoPhase* thermo);

virtual ~InterfaceKinetics();

Expand Down Expand Up @@ -126,7 +130,7 @@ class InterfaceKinetics : public Kinetics
//! @name Reaction Mechanism Construction
//! @{

//! Add a phase to the kinetics manager object.
//! Add a thermo phase to the kinetics manager object.
/*!
* This must be done before the function init() is called or
* before any reactions are input.
Expand All @@ -138,6 +142,9 @@ class InterfaceKinetics : public Kinetics
*
* @param thermo Reference to the ThermoPhase to be added.
*/
virtual void addThermo(shared_ptr<ThermoPhase> thermo);

//! @see InterfaceKinetics::addThermo(shared_ptr<ThermoPhase>)
virtual void addPhase(ThermoPhase& thermo);

virtual void init();
Expand Down
16 changes: 16 additions & 0 deletions include/cantera/kinetics/Kinetics.h
Expand Up @@ -219,6 +219,12 @@ class Kinetics
return m_rxnphase;
}

/**
* Return pointer to phase where the reactions occur.
* @since New in Cantera 3.0
*/
shared_ptr<ThermoPhase> reactionPhase() const;

/**
* This method returns a reference to the nth ThermoPhase object defined
* in this kinetics mechanism. It is typically used so that member
Expand Down Expand Up @@ -1098,7 +1104,13 @@ class Kinetics
* kinetics manager object as the value.
*
* @param thermo Reference to the ThermoPhase to be added.
* @since New in Cantera 3.0. Replaces addPhase.
*/
virtual void addThermo(shared_ptr<ThermoPhase> thermo);

//! @see Kinetics::addThermo(shared_ptr<ThermoPhase>)
//! @deprecated To be removed after Cantera 3.0. Replaced by addThermo
//! pointer.
virtual void addPhase(ThermoPhase& thermo);

/**
Expand Down Expand Up @@ -1320,6 +1332,10 @@ class Kinetics
*/
std::vector<ThermoPhase*> m_thermo;

//! vector of shared pointers, @see m_thermo
//! @todo replace m_thermo with shared version after Cantera 3.0
vector<shared_ptr<ThermoPhase>> m_sharedThermo;

/**
* m_start is a vector of integers specifying the beginning position for the
* species vector for the n'th phase in the kinetics class.
Expand Down
15 changes: 15 additions & 0 deletions include/cantera/kinetics/KineticsFactory.h
Expand Up @@ -38,6 +38,7 @@ class KineticsFactory : public Factory<Kinetics>

/**
* Create a new kinetics manager.
* @deprecated To be removed after Cantera 3.0; superseded by newKinetics.
*/
Kinetics* newKineticsMgr(const string& model);

Expand All @@ -58,6 +59,13 @@ shared_ptr<Kinetics> newKinetics(const string& model);
* @param rootNode The root node of the file containing the phase definition,
* which will be treated as the default source for reactions
*/
shared_ptr<Kinetics> newKinetics(const vector<shared_ptr<ThermoPhase>>& phases,
const AnyMap& phaseNode,
const AnyMap& rootNode=AnyMap());

//! @copydoc KineticsFactory::newKinetics(const vector<shared_ptr<ThermoPhase>>&, const AnyMap&, const AnyMap&)
//! @deprecated To be removed after Cantera 3.0;
//! superseded by newKinetics() returning shared_ptr
unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
const AnyMap& phaseNode,
const AnyMap& rootNode=AnyMap());
Expand All @@ -73,6 +81,13 @@ unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
* @param phase_name The name of the reacting phase in the input file (that is, the
* name of the first phase in the `phases` vector)
*/
shared_ptr<Kinetics> newKinetics(const vector<shared_ptr<ThermoPhase>>& phases,
const string& filename,
const string& phase_name);

//! @copydoc KineticsFactory::newKinetics(const vector<shared_ptr<ThermoPhase>>&, const string&, const string&)
//! @deprecated To be removed after Cantera 3.0;
//! superseded by newKinetics() returning shared_ptr
unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
const std::string& filename,
const std::string& phase_name);
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/oneD/Boundary1D.h
Expand Up @@ -298,6 +298,9 @@ class ReactingSurf1D : public Boundary1D
ReactingSurf1D();
ReactingSurf1D(shared_ptr<Solution> solution, const std::string& id="");

virtual void setKinetics(shared_ptr<Kinetics> kin);

//! @deprecated To be removed after Cantera 3.0; replaced by setKinetics
void setKineticsMgr(InterfaceKinetics* kin);

void enableCoverageEquations(bool docov) {
Expand Down
26 changes: 26 additions & 0 deletions include/cantera/oneD/Domain1D.h
Expand Up @@ -28,6 +28,8 @@ class MultiJac;
class OneDim;
class Refiner;
class AnyMap;
class Kinetics;
class Transport;
class Solution;
class SolutionArray;

Expand Down Expand Up @@ -65,6 +67,24 @@ class Domain1D
return (m_type >= cConnectorType);
}

//! Set the solution manager.
//! @since New in Cantera 3.0.
void setSolution(shared_ptr<Solution> sol) {
m_solution = sol;
}

//! Set the kinetics manager.
//! @since New in Cantera 3.0.
virtual void setKinetics(shared_ptr<Kinetics> kin) {
throw NotImplementedError("Domain1D::setKinetics");
}

//! Set transport model to existing instance
//! @since New in Cantera 3.0.
virtual void setTransport(shared_ptr<Transport> trans) {
throw NotImplementedError("Domain1D::setTransport");
}

//! The container holding this domain.
const OneDim& container() const {
return *m_container;
Expand Down Expand Up @@ -398,12 +418,18 @@ class Domain1D
*/
void linkLeft(Domain1D* left) {
m_left = left;
if (!m_solution && left && left->solution()) {
m_solution = left->solution();
}
locate();
}

//! Set the right neighbor to domain 'right.'
void linkRight(Domain1D* right) {
m_right = right;
if (!m_solution && right && right->solution()) {
m_solution = right->solution();
}
}

//! Append domain 'right' to this one, and update all links.
Expand Down
16 changes: 9 additions & 7 deletions include/cantera/oneD/StFlow.h
Expand Up @@ -52,9 +52,7 @@ class StFlow : public Domain1D
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) {
}
StFlow(shared_ptr<ThermoPhase> th, size_t nsp = 1, size_t points = 1);

//! Create a new flow domain.
//! @param sol Solution object used to evaluate all thermodynamic, kinetic, and
Expand Down Expand Up @@ -88,12 +86,16 @@ class StFlow : public Domain1D
*/
void setThermo(IdealGasPhase& th);

//! Set the kinetics manager. The kinetics manager must
void setKinetics(Kinetics& kin) {
m_kin = &kin;
}
virtual void setKinetics(shared_ptr<Kinetics> kin);

//! Set the kinetics manager.
//! @deprecated To be removed after Cantera 3.0; replaced by Domain1D::setKinetics
void setKinetics(Kinetics& kin);

virtual void setTransport(shared_ptr<Transport> trans);

//! Set transport model to existing instance
//! @deprecated To be removed after Cantera 3.0; replaced by Domain1D::setKinetics
void setTransport(Transport& trans);

//! Set the transport model
Expand Down