-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
Question: equivalent of composite Python classes in C++ #695
Comments
I've thought about this before, and while it would have some convenience, I feel like it would be extremely ugly -- there are over 300 methods to wrap among the I'm not sure I see what the problem is with serialization that requires this feature. I think all that is required is that the method which generates a complete phase definition needs to have the |
There may be other ways to instantiate, but at least from Python there are only 3 classes: At the moment, the information is held together by objects that have sets of |
Case in point: consider gas2 = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',
species=species, reactions=reactions) It may be useful to write the mechanism back to yaml without having to 'glue' the file together in python? |
So you're thinking of a structure that just exposes the related class Solution {
public:
Solution(const std::string& infile, const std::string& phasename); // and other constructors
std::string name() const;
unique_ptr<ThermoPhase> thermo;
unique_ptr<Kinetics> kinetics;
unique_ptr<Transport> transport;
}; A similar structure for I'm not quite clear what you would expect the |
Almost, but I wouldn't even bother with loading the file there (I'd still use the existing approach. EDIT: I guess that is debatable as your thought may clarify things quite a bit). Also, apologies that my function signatures are likely incorrect (not using smart pointers much). I'm mostly Python ... class Composite {
public:
Composite(unique_ptr<ThermoPhase> thermo,
unique_ptr<Kinetics> kinetics,
unique_ptr<Transport> transport,
const std::string& name="(none)"); // and other constructors
std::string name() const;
void setName(const std::string& name);
virtual std::string type() const;
unique_ptr<ThermoPhase> thermo;
unique_ptr<Kinetics> kinetics;
unique_ptr<Transport> transport;
};
class Solution : public Composite {
virtual std::string type() const {
return "Solution";
}
};
class Interface : public Composite {
virtual std::string type() const {
return "Interface";
}
};
class DustyGas : public Composite {
virtual std::string type() const {
return "DustyGas";
}
}; PS: An alternative would be not set anything in the constructor and write setters for the managers instead. It really depends on how the PPS: the only thing I'd add in |
And obviously I forgot the signature for a function |
Oh, I see - you're after a way of writing a function that can instantiate a YAML phase entry without knowing whether it is for a If the only polymorphic behavior is the return value of |
Yes, that pretty much is what I had in mind. You’re correct that polymorphism may not be required at all. I’d have to code things up ... things have a tendency to clear up in this process ... |
Looks like the name of |
Cantera version
2.5.0a3
Expected Behavior
It would be useful to have C++ equivalents of composite classes that are defined in Python (i.e.
Solution
,Interface
, etc.). A replication of those classes would clarify origin and structure of thermo/kinetics/transport managers that are instantiated from the Python composite class (the same holds true for Matlab).This does not mean the replication of double/triple inheritance within C++. Rather, the C++ classes would receive pointers to previously allocated managers, as well as hold type information (which is currently lost in C++) and a uniquely assignable name.
The motivation is that a common root for composite objects appears to be necessary for serialization within the C++ layer. A direct mapping of Python to C++ objects would also clarify the overall structure of cantera.
Actual Behavior
There is no replication of composite classes within C++
Steps to reproduce
N/A
The text was updated successfully, but these errors were encountered: