Skip to content

Commit

Permalink
more CT_API
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jan 24, 2023
1 parent 21f71d2 commit 535dd6a
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 87 deletions.
2 changes: 1 addition & 1 deletion include/cantera/base/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Interface : public Solution
* on the phase definition.
* @returns an initialized Interface object.
*/
shared_ptr<Interface> newInterface(const std::string& infile,
CT_API shared_ptr<Interface> newInterface(const std::string& infile,
const std::string& name="", const std::vector<std::string>& adjacent={});


Expand Down
20 changes: 10 additions & 10 deletions include/cantera/base/Solution.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExternalHandle;
class Solution : public std::enable_shared_from_this<Solution>
{
protected:
Solution();
CT_API Solution();

public:
virtual ~Solution() {}
Expand All @@ -34,10 +34,10 @@ class Solution : public std::enable_shared_from_this<Solution>
}

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

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

//! Set the ThermoPhase object
virtual void setThermo(shared_ptr<ThermoPhase> thermo);
Expand All @@ -51,7 +51,7 @@ class Solution : public std::enable_shared_from_this<Solution>
//! Set the Transport object by name
//! @param model name of transport model
//! @since New in Cantera 3.0
void setTransportModel(const std::string& model);
CT_API void setTransportModel(const std::string& model);

//! Accessor for the ThermoPhase pointer
shared_ptr<ThermoPhase> thermo() {
Expand Down Expand Up @@ -87,21 +87,21 @@ class Solution : public std::enable_shared_from_this<Solution>
return m_adjacent.size();
}

AnyMap parameters(bool withInput=false) const;
CT_API AnyMap parameters(bool withInput=false) const;

//! Access input data associated with header definition
const AnyMap& header() const;
AnyMap& header();
CT_API const AnyMap& header() const;
CT_API AnyMap& header();

//! Retrieve source used for object creation; usually an input file name
const std::string source() const;
CT_API const std::string source() const;

//! Overwrite source (only required if object is not created using newSolution)
void setSource(const std::string& source);
CT_API void setSource(const std::string& source);

//! Store a handle to a wrapper for this Solution object from an external
//! language interface (for example, a Python Solution object)
void holdExternalHandle(const std::string& name, shared_ptr<ExternalHandle> handle);
CT_API void holdExternalHandle(const std::string& name, shared_ptr<ExternalHandle> handle);

//! Get the handle for a wrapper for this Solution object from an external
//! language interface.
Expand Down
20 changes: 10 additions & 10 deletions include/cantera/kinetics/Falloff.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AnyMap;
*/
struct FalloffData : public ReactionData
{
FalloffData();
CT_API FalloffData();

virtual bool update(const ThermoPhase& phase, const Kinetics& kin) override;

Expand All @@ -44,7 +44,7 @@ struct FalloffData : public ReactionData
* The method is used for the evaluation of numerical derivatives.
* @param deltaM relative third-body perturbation
*/
void perturbThirdBodies(double deltaM);
CT_API void perturbThirdBodies(double deltaM);

virtual void restore() override;

Expand Down Expand Up @@ -108,15 +108,15 @@ class FalloffRate : public ReactionRate
* @param c Vector of coefficients of the parameterization. The number and
* meaning of these coefficients is subclass-dependent.
*/
virtual void setFalloffCoeffs(const vector_fp& c);
CT_API virtual void setFalloffCoeffs(const vector_fp& c);

/**
* Retrieve coefficients of the falloff parameterization.
*
* @param c Vector of coefficients of the parameterization. The number and
* meaning of these coefficients is subclass-dependent.
*/
virtual void getFalloffCoeffs(vector_fp& c) const;
CT_API virtual void getFalloffCoeffs(vector_fp& c) const;

/**
* Update the temperature-dependent portions of the falloff function, if
Expand Down Expand Up @@ -182,7 +182,7 @@ class FalloffRate : public ReactionRate
return 0;
}

virtual void setParameters(
CT_API virtual void setParameters(
const AnyMap& node, const UnitStack& rate_units) override;

//! Get the values of the parameters for this object. *params* must be an
Expand All @@ -195,7 +195,7 @@ class FalloffRate : public ReactionRate
"To be removed after Cantera 3.0; superseded by getFalloffCoeffs.");
}

virtual void getParameters(AnyMap& node) const override;
CT_API virtual void getParameters(AnyMap& node) const override;

//! Evaluate reaction rate
//! @param shared_data data shared by all reactions of a given type
Expand Down Expand Up @@ -223,8 +223,8 @@ class FalloffRate : public ReactionRate
return pr * m_rc_high;
}

virtual void check(const std::string& equation) override;
virtual void validate(const std::string& equation, const Kinetics& kin) override;
CT_API virtual void check(const std::string& equation) override;
CT_API virtual void validate(const std::string& equation, const Kinetics& kin) override;

//! Get flag indicating whether negative A values are permitted
bool allowNegativePreExponentialFactor() const {
Expand Down Expand Up @@ -252,15 +252,15 @@ class FalloffRate : public ReactionRate
}

//! Set reaction rate in the low-pressure limit
void setLowRate(const ArrheniusRate& low);
CT_API void setLowRate(const ArrheniusRate& low);

//! Get reaction rate in the high-pressure limit
ArrheniusRate& highRate() {
return m_highRate;
}

//! Set reaction rate in the high-pressure limit
void setHighRate(const ArrheniusRate& high);
CT_API void setHighRate(const ArrheniusRate& high);

protected:
ArrheniusRate m_lowRate; //!< The reaction rate in the low-pressure limit
Expand Down
40 changes: 20 additions & 20 deletions include/cantera/kinetics/Reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ class Reaction
{
public:
Reaction() {}
Reaction(const Composition& reactants, const Composition& products,
shared_ptr<ReactionRate> rate, shared_ptr<ThirdBody> tbody=nullptr);
Reaction(const std::string& equation,
shared_ptr<ReactionRate> rate, shared_ptr<ThirdBody> tbody=nullptr);
CT_API Reaction(const Composition& reactants, const Composition& products,
shared_ptr<ReactionRate> rate, shared_ptr<ThirdBody> tbody=nullptr);
CT_API Reaction(const std::string& equation,
shared_ptr<ReactionRate> rate, shared_ptr<ThirdBody> tbody=nullptr);

//! Construct a Reaction and corresponding ReactionRate based on AnyMap (YAML)
//! input.
Reaction(const AnyMap& node, const Kinetics& kin);
CT_API Reaction(const AnyMap& node, const Kinetics& kin);

virtual ~Reaction() {}

//! The reactant side of the chemical equation for this reaction
std::string reactantString() const;
CT_API std::string reactantString() const;

//! The product side of the chemical equation for this reaction
std::string productString() const;
CT_API std::string productString() const;

//! The chemical equation for this reaction
std::string equation() const;
CT_API std::string equation() const;

//! Set the reactants and products based on the reaction equation. If a Kinetics
//! object is provided, it is used to check that all reactants and products exist.
void setEquation(const std::string& equation, const Kinetics* kin=0);
CT_API void setEquation(const std::string& equation, const Kinetics* kin=0);

//! The type of reaction, including reaction rate information
std::string type() const;
CT_API std::string type() const;

//! Calculate the units of the rate constant. These are determined by the units
//! of the standard concentration of the reactant species' phases and the phase
Expand Down Expand Up @@ -98,7 +98,7 @@ class Reaction
//! @param withInput If true, include additional input data fields associated
//! with the object, such as user-defined fields from a YAML input file, as
//! contained in the #input attribute.
AnyMap parameters(bool withInput=true) const;
CT_API AnyMap parameters(bool withInput=true) const;

//! Set up reaction based on AnyMap *node*
void setParameters(const AnyMap& node, const Kinetics& kin);
Expand Down Expand Up @@ -172,7 +172,7 @@ class Reaction
}

//! Set reaction rate pointer
void setRate(shared_ptr<ReactionRate> rate);
CT_API void setRate(shared_ptr<ReactionRate> rate);

//! Get pointer to third-body handler
shared_ptr<ThirdBody> thirdBody() {
Expand Down Expand Up @@ -214,8 +214,8 @@ class ThirdBody
{
public:
explicit ThirdBody() {};
ThirdBody(const std::string& third_body);
ThirdBody(const AnyMap& node);
CT_API ThirdBody(const std::string& third_body);
CT_API ThirdBody(const AnyMap& node);

//! @deprecated To be removed after Cantera 3.0; instantiate using string instead
ThirdBody(double default_efficiency);
Expand Down Expand Up @@ -244,7 +244,7 @@ class ThirdBody
void getParameters(AnyMap& node) const;

//! Get the third-body efficiency for species *k*
double efficiency(const std::string& k) const;
CT_API double efficiency(const std::string& k) const;

//! Suffix representing the third body collider in reaction equation, for example
//! `+ M` or `(+M)`
Expand Down Expand Up @@ -315,21 +315,21 @@ class FalloffReaction : public Reaction
/*!
* @param type string identifying type of reaction.
*/
unique_ptr<Reaction> CT_API newReaction(const std::string& type);
CT_API unique_ptr<Reaction> newReaction(const std::string& type);

//! Create a new Reaction object using the specified parameters
/*!
* @param rxn_node AnyMap node describing reaction.
* @param kin kinetics manager
*/
unique_ptr<Reaction> CT_API newReaction(const AnyMap& rxn_node,
const Kinetics& kin);
CT_API unique_ptr<Reaction> newReaction(const AnyMap& rxn_node,
const Kinetics& kin);

//! Create Reaction objects for each item (an AnyMap) in `items`. The species
//! involved in these reactions must exist in the phases associated with the
//! Kinetics object `kinetics`.
std::vector<shared_ptr<Reaction>> getReactions(const AnyValue& items,
Kinetics& kinetics);
CT_API std::vector<shared_ptr<Reaction>> getReactions(const AnyValue& items,
Kinetics& kinetics);

//! Parse reaction equation
void parseReactionEquation(Reaction& R, const std::string& equation,
Expand Down
42 changes: 8 additions & 34 deletions include/cantera/kinetics/ReactionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,15 @@ struct ReactionData
* This method allows for testing of a reaction rate expression outside of
* Kinetics reaction rate evaluators.
*/
virtual void update(double T) {
temperature = T;
logT = std::log(T);
recipT = 1./T;
}
CT_API virtual void update(double T);

//! Update data container based on temperature *T* and an *extra* parameter
/**
* Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
* This method allows for testing of a reaction rate expression outside of
* Kinetics reaction rate evaluators.
*/
virtual void update(double T, double extra) {
throw NotImplementedError("ReactionData::update",
"ReactionData type does not use extra scalar argument.");
}
CT_API virtual void update(double T, double extra);

//! Update data container based on temperature *T* and a vector parameter *extra*
/**
Expand All @@ -58,53 +51,34 @@ struct ReactionData
* @warning This method is an experimental part of the %Cantera API and
* may be changed or removed without notice.
*/
virtual void update(double T, const vector_fp& extra) {
throw NotImplementedError("ReactionData::update",
"ReactionData type does not use extra vector argument.");
}
CT_API virtual void update(double T, const vector_fp& extra);

//! Update data container based on thermodynamic phase state
/**
* This update mechanism is used by Kinetics reaction rate evaluators.
* @returns A boolean element indicating whether the `evalFromStruct` method
* needs to be called (assuming previously-calculated values were cached)
*/
virtual bool update(const ThermoPhase& phase, const Kinetics& kin) = 0;
CT_API virtual bool update(const ThermoPhase& phase, const Kinetics& kin) = 0;

//! Perturb temperature of data container
/**
* The method is used for the evaluation of numerical derivatives.
* @param deltaT relative temperature perturbation
*/
void perturbTemperature(double deltaT) {
if (m_temperature_buf > 0.) {
throw CanteraError("ReactionData::perturbTemperature",
"Cannot apply another perturbation as state is already perturbed.");
}
m_temperature_buf = temperature;
ReactionData::update(temperature * (1. + deltaT));
}
CT_API void perturbTemperature(double deltaT);

//! Restore data container after a perturbation
virtual void restore() {
// only restore if there is a valid buffered value
if (m_temperature_buf < 0.) {
return;
}
ReactionData::update(m_temperature_buf);
m_temperature_buf = -1.;
}
CT_API virtual void restore();

//! Update number of species, reactions and phases
virtual void resize(size_t nSpecies, size_t nReactions, size_t nPhases) {}
CT_API virtual void resize(size_t nSpecies, size_t nReactions, size_t nPhases);

//! Force shared data and reaction rates to be updated next time. This is called by
//! functions that change quantities affecting rate calculations that are normally
//! assumed to be constant, like the reaction rate parameters or the number of
//! reactions.
virtual void invalidateCache() {
temperature = NAN;
}
CT_API virtual void invalidateCache();

double temperature; //!< temperature
double logT; //!< logarithm of temperature
Expand Down
6 changes: 3 additions & 3 deletions include/cantera/thermo/Phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ class Phase
//! Aliases are case-sensitive.
//! @param name original species name
//! @param alias alternate name
void addSpeciesAlias(const std::string& name, const std::string& alias);
CT_API void addSpeciesAlias(const std::string& name, const std::string& alias);

//! Return a vector with isomers names matching a given composition map
//! @param compMap compositionMap of the species.
Expand All @@ -810,12 +810,12 @@ class Phase
//! Return the Species object for the named species. Changes to this object
//! do not affect the ThermoPhase object until the #modifySpecies function
//! is called.
shared_ptr<Species> species(const std::string& name) const;
CT_API shared_ptr<Species> species(const std::string& name) const;

//! Return the Species object for species whose index is *k*. Changes to
//! this object do not affect the ThermoPhase object until the
//! #modifySpecies function is called.
shared_ptr<Species> species(size_t k) const;
CT_API shared_ptr<Species> species(size_t k) const;

//! Set behavior when adding a species containing undefined elements to just
//! skip the species.
Expand Down
Loading

0 comments on commit 535dd6a

Please sign in to comment.