From 82018533dbdd8220096ff90c97f8bfbbc8916107 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 24 Jan 2023 09:59:42 -0500 Subject: [PATCH] WIP: Exporting symbols needed by Cython --- ext/SConscript | 5 +- include/cantera/base/AnyMap.h | 113 +++++++++--------- include/cantera/base/AnyMap.inl.h | 4 +- include/cantera/base/Solution.h | 6 +- include/cantera/base/Units.h | 16 +-- include/cantera/base/ctexceptions.h | 8 +- include/cantera/base/global.h | 56 ++++----- include/cantera/base/stringUtils.h | 2 +- include/cantera/kinetics/InterfaceKinetics.h | 12 +- include/cantera/kinetics/Kinetics.h | 32 ++--- include/cantera/kinetics/Reaction.h | 4 +- include/cantera/kinetics/ReactionRate.h | 4 +- .../cantera/kinetics/ReactionRateFactory.h | 6 +- include/cantera/numerics/Func1.h | 22 ++-- include/cantera/oneD/Boundary1D.h | 44 +++---- include/cantera/oneD/Domain1D.h | 30 ++--- include/cantera/oneD/IonFlow.h | 8 +- include/cantera/oneD/OneDim.h | 11 +- include/cantera/oneD/Sim1D.h | 62 +++++----- include/cantera/oneD/StFlow.h | 20 ++-- include/cantera/thermo/Elements.h | 22 ++-- include/cantera/thermo/Phase.h | 106 ++++++++-------- include/cantera/thermo/ThermoFactory.h | 31 ++--- include/cantera/thermo/ThermoPhase.h | 34 +++--- include/cantera/zeroD/ReactorFactory.h | 2 +- interfaces/cython/SConscript | 7 +- interfaces/cython/cantera/reaction.pxd | 12 +- site_scons/buildutils.py | 2 +- src/thermo/ThermoFactory.cpp | 27 +++++ 29 files changed, 365 insertions(+), 343 deletions(-) diff --git a/ext/SConscript b/ext/SConscript index eb1073e9980..6060a6606e7 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -40,8 +40,9 @@ if not env['system_fmt']: license_files["fmtlib"] = File("#ext/fmt/LICENSE.rst") localenv = prep_default(env) localenv.Prepend(CPPPATH=Dir('#ext/fmt/include')) - libraryTargets.extend( - localenv.SharedObject(multi_glob(localenv, 'fmt/src', 'cc'))) + localenv.Append(CPPDEFINES={"FMT_EXPORT": None}) + env['fmt_targets'] = localenv.SharedObject(multi_glob(localenv, 'fmt/src', 'cc')) + libraryTargets.extend(env['fmt_targets']) for name in ('format.h', 'ostream.h', 'printf.h', 'core.h', 'format-inl.h'): ext_copies.extend( copyenv.Command("#include/cantera/ext/fmt/" + name, diff --git a/include/cantera/base/AnyMap.h b/include/cantera/base/AnyMap.h index 7bb8cb7a381..af9b49200a3 100644 --- a/include/cantera/base/AnyMap.h +++ b/include/cantera/base/AnyMap.h @@ -33,7 +33,7 @@ namespace Cantera //! objects. class AnyBase { public: - AnyBase(); + CT_API AnyBase(); virtual ~AnyBase() {}; //! For values which are derived from an input file, set the line and column @@ -84,19 +84,19 @@ class AnyMap; class AnyValue : public AnyBase { public: - AnyValue(); - ~AnyValue(); - AnyValue(AnyValue const& other); - AnyValue(AnyValue&& other); - AnyValue& operator=(AnyValue const& other); - AnyValue& operator=(AnyValue&& other); + CT_API AnyValue(); + CT_API ~AnyValue(); + CT_API AnyValue(AnyValue const& other); + CT_API AnyValue(AnyValue&& other); + CT_API AnyValue& operator=(AnyValue const& other); + CT_API AnyValue& operator=(AnyValue&& other); - bool operator==(const AnyValue& other) const; - bool operator!=(const AnyValue& other) const; + CT_API bool operator==(const AnyValue& other) const; + CT_API bool operator!=(const AnyValue& other) const; //! If this AnyValue is an AnyMap, return the value stored in `key`. - AnyValue& operator[](const std::string& key); - const AnyValue& operator[](const std::string& key) const; + CT_API AnyValue& operator[](const std::string& key); + CT_API const AnyValue& operator[](const std::string& key) const; //! Returns `true` if this AnyValue is an AnyMap and that map contains //! a key with the given name. @@ -120,10 +120,10 @@ class AnyValue : public AnyBase const std::type_info& type() const; //! Returns a string specifying the type of the held value. - std::string type_str() const; + CT_API std::string type_str() const; //! Return boolean indicating whether AnyValue is empty. - bool empty() const; + CT_API bool empty() const; //! Returns `true` if the held value is of the specified type. template @@ -131,16 +131,16 @@ class AnyValue : public AnyBase //! Returns `true` if the held value is a scalar type (such as `double`, `long //! int`, `string`, or `bool`). - bool isScalar() const; + CT_API bool isScalar() const; explicit AnyValue(const std::string& value); explicit AnyValue(const char* value); - AnyValue& operator=(const std::string& value); - AnyValue& operator=(const char* value); + CT_API AnyValue& operator=(const std::string& value); + CT_API AnyValue& operator=(const char* value); //! Return the held value, if it is a string const std::string& asString() const; - bool operator==(const std::string& other) const; - bool operator!=(const std::string& other) const; + CT_API bool operator==(const std::string& other) const; + CT_API bool operator!=(const std::string& other) const; friend bool operator==(const std::string& lhs, const AnyValue& rhs); friend bool operator!=(const std::string& lhs, const AnyValue& rhs); @@ -172,33 +172,33 @@ class AnyValue : public AnyBase //! @} end group quantity conversions explicit AnyValue(double value); - AnyValue& operator=(double value); + CT_API AnyValue& operator=(double value); //! Return the held value as a `double`, if it is a `double` or a `long //! int`. double& asDouble(); const double& asDouble() const; - bool operator==(const double& other) const; - bool operator!=(const double& other) const; + CT_API bool operator==(const double& other) const; + CT_API bool operator!=(const double& other) const; friend bool operator==(const double& lhs, const AnyValue& rhs); friend bool operator!=(const double& lhs, const AnyValue& rhs); explicit AnyValue(bool value); - AnyValue& operator=(bool value); + CT_API AnyValue& operator=(bool value); //! Return the held value, if it is a `bool`. bool& asBool(); const bool& asBool() const; explicit AnyValue(long int value); explicit AnyValue(int value); - AnyValue& operator=(long int value); - AnyValue& operator=(int value); + CT_API AnyValue& operator=(long int value); + CT_API AnyValue& operator=(int value); //! Return the held value, if it is a `long int`. long int& asInt(); const long int& asInt() const; - bool operator==(const long int& other) const; - bool operator!=(const long int& other) const; - bool operator==(const int& other) const; - bool operator!=(const int& other) const; + CT_API bool operator==(const long int& other) const; + CT_API bool operator!=(const long int& other) const; + CT_API bool operator==(const int& other) const; + CT_API bool operator!=(const int& other) const; friend bool operator==(const long int& lhs, const AnyValue& rhs); friend bool operator!=(const long int& lhs, const AnyValue& rhs); friend bool operator==(const int& lhs, const AnyValue& rhs); @@ -216,8 +216,8 @@ class AnyValue : public AnyBase std::vector& asVector(size_t nMin=npos, size_t nMax=npos); explicit AnyValue(const AnyMap& value); - AnyValue& operator=(const AnyMap& value); - AnyValue& operator=(AnyMap&& value); + CT_API AnyValue& operator=(const AnyMap& value); + CT_API AnyValue& operator=(AnyMap&& value); template AnyValue& operator=(const std::unordered_map items); @@ -329,6 +329,11 @@ const std::vector& AnyValue::asVector(size_t nMin, size_t nMax) template<> std::vector& AnyValue::asVector(size_t nMin, size_t nMax); +CT_API bool operator==(const std::string& lhs, const AnyValue& rhs); +CT_API bool operator==(const double& lhs, const AnyValue& rhs); +CT_API bool operator==(const long int& lhs, const AnyValue& rhs); +CT_API bool operator==(const int& lhs, const AnyValue& rhs); + //! A map of string keys to values whose type can vary at runtime /*! * Values in an AnyMap are held by instances of AnyValue. Instances of AnyMap @@ -399,7 +404,7 @@ std::vector& AnyValue::asVector(size_t nMin, size_t nMax); class AnyMap : public AnyBase { public: - AnyMap(); + CT_API AnyMap(); //! Create an AnyMap from a YAML file. /*! @@ -407,17 +412,17 @@ class AnyMap : public AnyBase * first, followed by the current working directory and the Cantera include * path. */ - static AnyMap fromYamlFile(const std::string& name, + CT_API static AnyMap fromYamlFile(const std::string& name, const std::string& parent_name=""); //! Create an AnyMap from a string containing a YAML document - static AnyMap fromYamlString(const std::string& yaml); + CT_API static AnyMap fromYamlString(const std::string& yaml); std::string toYamlString() const; //! Get the value of the item stored in `key`. - AnyValue& operator[](const std::string& key); - const AnyValue& operator[](const std::string& key) const; + CT_API AnyValue& operator[](const std::string& key); + CT_API const AnyValue& operator[](const std::string& key) const; //! Used to create a new item which will be populated from a YAML input //! string, where the item with `key` occurs at the specified line and @@ -429,20 +434,20 @@ class AnyMap : public AnyBase const AnyValue& at(const std::string& key) const; //! Return boolean indicating whether AnyMap is empty. - bool empty() const; + CT_API bool empty() const; //! Returns `true` if the map contains an item named `key`. - bool hasKey(const std::string& key) const; + CT_API bool hasKey(const std::string& key) const; //! Erase the value held by `key`. void erase(const std::string& key); //! Erase all items in the mapping - void clear(); + CT_API void clear(); //! Add items from `other` to this AnyMap. If keys in `other` also exist in //! this AnyMap, the `keepExisting` option determines which item is used. - void update(const AnyMap& other, bool keepExisting=true); + CT_API void update(const AnyMap& other, bool keepExisting=true); //! Return a string listing the keys in this AnyMap, for use in error //! messages, for example @@ -463,17 +468,17 @@ class AnyMap : public AnyBase void propagateMetadata(shared_ptr& file); //! If `key` exists, return it as a `bool`, otherwise return `default_`. - bool getBool(const std::string& key, bool default_) const; + CT_API bool getBool(const std::string& key, bool default_) const; //! If `key` exists, return it as a `long int`, otherwise return `default_`. - long int getInt(const std::string& key, long int default_) const; + CT_API long int getInt(const std::string& key, long int default_) const; //! If `key` exists, return it as a `double`, otherwise return `default_`. - double getDouble(const std::string& key, double default_) const; + CT_API double getDouble(const std::string& key, double default_) const; //! If `key` exists, return it as a `string`, otherwise return `default_`. - const std::string& getString(const std::string& key, - const std::string& default_) const; + CT_API const std::string& getString(const std::string& key, + const std::string& default_) const; //! Convert the item stored by the given `key` to the units specified in //! `units`. If the stored value is a double, convert it using the default @@ -549,9 +554,9 @@ class AnyMap : public AnyBase class OrderedProxy { public: OrderedProxy() {} - OrderedProxy(const AnyMap& data); - OrderedIterator begin() const; - OrderedIterator end() const; + CT_API OrderedProxy(const AnyMap& data); + CT_API OrderedIterator begin() const; + CT_API OrderedIterator end() const; typedef std::vector, @@ -596,8 +601,8 @@ class AnyMap : public AnyBase return m_data.size(); }; - bool operator==(const AnyMap& other) const; - bool operator!=(const AnyMap& other) const; + CT_API bool operator==(const AnyMap& other) const; + CT_API bool operator!=(const AnyMap& other) const; //! Return the default units that should be used to convert stored values const UnitSystem& units() const { return *m_units; } @@ -618,10 +623,10 @@ class AnyMap : public AnyBase * @warning This function is an experimental part of the %Cantera API and * may be changed or removed without notice. */ - void applyUnits(); + CT_API void applyUnits(); //! See applyUnits() - void applyUnits(shared_ptr& units); + CT_API void applyUnits(shared_ptr& units); //! Set the unit system for this AnyMap. The applyUnits() method should be //! called on the root AnyMap object after all desired calls to setUnits() @@ -740,9 +745,9 @@ class InputFileError : public CanteraError return "InputFileError"; } protected: - static std::string formatError(const std::string& message, - int line, int column, - const shared_ptr& metadata); + CT_API static std::string formatError(const std::string& message, + int line, int column, + const shared_ptr& metadata); static std::string formatError2(const std::string& message, int line1, int column1, const shared_ptr& metadata1, int line2, int column2, const shared_ptr& metadata2); diff --git a/include/cantera/base/AnyMap.inl.h b/include/cantera/base/AnyMap.inl.h index 5354e27a759..a18ad37cd89 100644 --- a/include/cantera/base/AnyMap.inl.h +++ b/include/cantera/base/AnyMap.inl.h @@ -11,7 +11,7 @@ namespace Cantera { // re-declared to avoid needing to include global.h here -std::string demangle(const std::type_info& type); +CT_API std::string demangle(const std::type_info& type); // Definitions for AnyValue templated functions @@ -59,7 +59,7 @@ bool AnyValue::is() const { return m_value->type() == typeid(T); } -template<> bool AnyValue::is>() const; +template<> CT_API bool AnyValue::is>() const; template AnyValue &AnyValue::operator=(const std::vector &value) { diff --git a/include/cantera/base/Solution.h b/include/cantera/base/Solution.h index f1c2716e833..9fef79c90e5 100644 --- a/include/cantera/base/Solution.h +++ b/include/cantera/base/Solution.h @@ -141,7 +141,7 @@ class Solution : public std::enable_shared_from_this * on the phase definition. * @returns an initialized Solution object. */ -shared_ptr newSolution(const std::string& infile, const std::string& name, +shared_ptr CT_API newSolution(const std::string& infile, const std::string& name, const std::string& transport, const std::vector& adjacent); //! Create and initialize a new Solution manager from an input file @@ -157,7 +157,7 @@ shared_ptr newSolution(const std::string& infile, const std::string& n * phases will be instantiated based on the phase definition. * @returns an initialized Solution object. */ -shared_ptr newSolution(const std::string& infile, +shared_ptr CT_API newSolution(const std::string& infile, const std::string& name="", const std::string& transport="", const std::vector>& adjacent={}); @@ -180,7 +180,7 @@ shared_ptr newSolution(const std::string& infile, * instantiated only once. * @returns an initialized Solution object. */ -shared_ptr newSolution( +shared_ptr CT_API newSolution( const AnyMap& phaseNode, const AnyMap& rootNode=AnyMap(), const std::string& transport="", const std::vector>& adjacent={}, diff --git a/include/cantera/base/Units.h b/include/cantera/base/Units.h index f0a8b1d7223..55c82b80ba4 100644 --- a/include/cantera/base/Units.h +++ b/include/cantera/base/Units.h @@ -30,7 +30,7 @@ class Units { public: //! Create a Units object with the specified dimensions. - explicit Units(double factor=1.0, double mass=0, double length=0, + CT_API explicit Units(double factor=1.0, double mass=0, double length=0, double time=0, double temperature=0, double current=0, double quantity=0); @@ -38,7 +38,7 @@ class Units //! @param units A string representation of the units. See UnitSystem //! for a description of the formatting options. //! @param force_unity ensure that conversion factor is equal to one - explicit Units(const std::string& units, bool force_unity=false); + CT_API explicit Units(const std::string& units, bool force_unity=false); //! Returns `true` if the specified Units are dimensionally consistent bool convertible(const Units& other) const; @@ -53,7 +53,7 @@ class Units //! Provide a string representation of these Units //! @param skip_unity do not print '1' if conversion factor is equal to one - std::string str(bool skip_unity=true) const; + CT_API std::string str(bool skip_unity=true) const; //! Raise these Units to a power, changing both the conversion factor and //! the dimensions of these Units. @@ -63,7 +63,7 @@ class Units //! Return dimension of primary unit component //! ("mass", "length", "time", "temperature", "current", or "quantity") - double dimension(const std::string& primary) const; + CT_API double dimension(const std::string& primary) const; private: //! Scale the unit by the factor `k` @@ -127,7 +127,7 @@ struct UnitStack void update(const Units& units, double exponent); //! Calculate product of units-exponent stack - Units product() const; + CT_API Units product() const; std::vector> stack; //!< Stack uses vector of pairs }; @@ -161,14 +161,14 @@ class UnitSystem { public: //! Create a unit system with the specified default units - UnitSystem(std::initializer_list units); + CT_API UnitSystem(std::initializer_list units); //! Default constructor for unit system (needed as VS2019 does not //! recognize an optional argument with a default value) UnitSystem() : UnitSystem({}) {} //! Return default units used by the unit system - std::map defaults() const; + CT_API std::map defaults() const; //! Set the default units to convert from when explicit units are not //! provided. Defaults can be set for mass, length, time, quantity, energy, @@ -177,7 +177,7 @@ class UnitSystem //! //! * To use SI+kmol: `setDefaults({"kg", "m", "s", "Pa", "J", "kmol"});` //! * To use CGS+mol: `setDefaults({"cm", "g", "dyn/cm^2", "erg", "mol"});` - void setDefaults(std::initializer_list units); + CT_API void setDefaults(std::initializer_list units); //! Set the default units using a map of dimension to unit pairs. //! diff --git a/include/cantera/base/ctexceptions.h b/include/cantera/base/ctexceptions.h index 0a945aee63a..d185c49ced8 100644 --- a/include/cantera/base/ctexceptions.h +++ b/include/cantera/base/ctexceptions.h @@ -91,13 +91,13 @@ class CanteraError : public std::exception virtual ~CanteraError() throw() {}; //! Get a description of the error - const char* what() const throw(); + const char CT_API * what() const throw(); //! Method overridden by derived classes to format the error message - virtual std::string getMessage() const; + virtual std::string CT_API getMessage() const; //! Get the name of the method that threw the exception - virtual std::string getMethod() const; + virtual std::string CT_API getMethod() const; //! Method overridden by derived classes to indicate their type virtual std::string getClass() const { @@ -110,7 +110,7 @@ class CanteraError : public std::exception CanteraError() {}; //! Constructor used by derived classes that override getMessage() - explicit CanteraError(const std::string& procedure); + CT_API explicit CanteraError(const std::string& procedure); //! The name of the procedure where the exception occurred std::string procedure_; diff --git a/include/cantera/base/global.h b/include/cantera/base/global.h index 4021d8513bd..81544233c76 100644 --- a/include/cantera/base/global.h +++ b/include/cantera/base/global.h @@ -69,45 +69,45 @@ class AnyMap; */ //! @copydoc Application::findInputFile -std::string findInputFile(const std::string& name); +CT_API std::string findInputFile(const std::string& name); //! @copydoc Application::addDataDirectory -void addDirectory(const std::string& dir); +CT_API void addDirectory(const std::string& dir); //! @copydoc Application::getDataDirectories -std::string getDataDirectories(const std::string& sep); +CT_API std::string getDataDirectories(const std::string& sep); //! @} //! @copydoc Application::loadExtension -void loadExtension(const std::string& extType, const std::string& name); +CT_API void loadExtension(const std::string& extType, const std::string& name); //! Load extensions providing user-defined models from the `extensions` section of the //! given node. @see Application::loadExtension //! //! @since New in Cantera 3.0 -void loadExtensions(const AnyMap& node); +CT_API void loadExtensions(const AnyMap& node); //! Delete and free all memory associated with the application /*! * Delete all global data. It should be called at the end of the * application if leak checking is to be done. */ -void appdelete(); +CT_API void appdelete(); //! @copydoc Application::thread_complete -void thread_complete(); +CT_API void thread_complete(); //! Returns the hash of the git commit from which Cantera was compiled, if known -std::string gitCommit(); +CT_API std::string gitCommit(); //! Returns true if Cantera was compiled in debug mode. Used for handling some cases //! where behavior tested in the test suite changes depending on whether the `NDEBUG` //! preprocessor macro is defined. -bool debugModeEnabled(); +CT_API bool debugModeEnabled(); //! Returns true if Cantera was compiled with C++ HDF5 support. //! @since New in Cantera 3.0. -bool usesHDF5(); +CT_API bool usesHDF5(); /*! * @defgroup logs Diagnostic Output @@ -125,7 +125,7 @@ bool usesHDF5(); */ //! @copydoc Application::Messages::writelog(const std::string&) -void writelog_direct(const std::string& msg); +CT_API void writelog_direct(const std::string& msg); //! Write a message to the log only if loglevel > 0 inline void debuglog(const std::string& msg, int loglevel) @@ -172,13 +172,13 @@ void writelogf(const char* fmt, const Args& ... args) { } //! Write an end of line character to the screen and flush output -void writelogendl(); +CT_API void writelogendl(); -void writeline(char repeat, size_t count, - bool endl_after=true, bool endl_before=false); +CT_API void writeline(char repeat, size_t count, + bool endl_after=true, bool endl_before=false); //! helper function passing deprecation warning to global handler -void _warn_deprecated(const std::string& method, const std::string& extra=""); +CT_API void _warn_deprecated(const std::string& method, const std::string& extra=""); //! Print a deprecation warning raised from *method*. /*! @@ -198,11 +198,11 @@ void warn_deprecated(const std::string& method, const std::string& msg, } //! @copydoc Application::suppress_deprecation_warnings -void suppress_deprecation_warnings(); +CT_API void suppress_deprecation_warnings(); //! helper function passing generic warning to global handler -void _warn(const std::string& warning, - const std::string& method, const std::string& extra); +CT_API void _warn(const std::string& warning, + const std::string& method, const std::string& extra); //! Print a generic warning raised from *method*. /*! @@ -239,31 +239,31 @@ void warn_user(const std::string& method, const std::string& msg, } //! @copydoc Application::make_deprecation_warnings_fatal -void make_deprecation_warnings_fatal(); +CT_API void make_deprecation_warnings_fatal(); //! @copydoc Application::make_warnings_fatal -void make_warnings_fatal(); +CT_API void make_warnings_fatal(); //! @copydoc Application::suppress_thermo_warnings -void suppress_thermo_warnings(bool suppress=true); +CT_API void suppress_thermo_warnings(bool suppress=true); //! @copydoc Application::thermo_warnings_suppressed -bool thermo_warnings_suppressed(); +CT_API bool thermo_warnings_suppressed(); //! @copydoc Application::suppress_warnings -void suppress_warnings(); +CT_API void suppress_warnings(); //! @copydoc Application::warnings_suppressed -bool warnings_suppressed(); +CT_API bool warnings_suppressed(); //! @copydoc Application::use_legacy_rate_constants -void use_legacy_rate_constants(bool legacy=true); +CT_API void use_legacy_rate_constants(bool legacy=true); //! @copydoc Application::legacy_rate_constants_used -bool legacy_rate_constants_used(); +CT_API bool legacy_rate_constants_used(); //! @copydoc Application::Messages::setLogger -void setLogger(Logger* logwriter); +CT_API void setLogger(Logger* logwriter); //! Clip *value* such that lower <= value <= upper template @@ -280,7 +280,7 @@ template int sign(T x) { //! Convert a type name to a human readable string, using `boost::core::demangle` if //! available. Also has a set of short names for some common types. //! @note Mainly for internal use by AnyMap and Delegator -std::string demangle(const std::type_info& type); +CT_API std::string demangle(const std::type_info& type); } diff --git a/include/cantera/base/stringUtils.h b/include/cantera/base/stringUtils.h index eb343eeeb16..1cd7a6a92a9 100644 --- a/include/cantera/base/stringUtils.h +++ b/include/cantera/base/stringUtils.h @@ -53,7 +53,7 @@ std::string stripnonprint(const std::string& s); * empty or unspecified, all values are allowed. * @return map of names to values */ -compositionMap parseCompString(const std::string& ss, +CT_API compositionMap parseCompString(const std::string& ss, const std::vector& names=std::vector()); //! Translate a string into one doublereal value diff --git a/include/cantera/kinetics/InterfaceKinetics.h b/include/cantera/kinetics/InterfaceKinetics.h index f29ebe273ef..f3642e1bc99 100644 --- a/include/cantera/kinetics/InterfaceKinetics.h +++ b/include/cantera/kinetics/InterfaceKinetics.h @@ -191,9 +191,9 @@ class InterfaceKinetics : public Kinetics * @param maxErrTestFails the maximum permissible number of error test failures * If not supplied, uses the default value in CVODES (7). */ - void advanceCoverages(doublereal tstep, double rtol=1.e-7, - double atol=1.e-14, double maxStepSize=0, - size_t maxSteps=20000, size_t maxErrTestFails=7); + CT_API void advanceCoverages(double tstep, double rtol=1.e-7, double atol=1.e-14, + double maxStepSize=0, size_t maxSteps=20000, + size_t maxErrTestFails=7); //! Solve for the pseudo steady-state of the surface problem /*! @@ -213,8 +213,8 @@ class InterfaceKinetics : public Kinetics * in the initial transient algorithm, before the equation * system is solved directly. */ - void solvePseudoSteadyStateProblem(int ifuncOverride = -1, - doublereal timeScaleOverride = 1.0); + CT_API void solvePseudoSteadyStateProblem(int ifuncOverride=-1, + double timeScaleOverride=1.0); void setIOFlag(int ioFlag); @@ -296,7 +296,7 @@ class InterfaceKinetics : public Kinetics * specified by the Phase Id. (Units: A/m^2 for a surface reaction, * A/m for an edge reaction). */ - double interfaceCurrent(const size_t iphase); + CT_API double interfaceCurrent(const size_t iphase); protected: //! Temporary work vector of length m_kk diff --git a/include/cantera/kinetics/Kinetics.h b/include/cantera/kinetics/Kinetics.h index 973ad162127..628a864863e 100644 --- a/include/cantera/kinetics/Kinetics.h +++ b/include/cantera/kinetics/Kinetics.h @@ -275,7 +275,7 @@ class Kinetics * * @param k species index */ - std::string kineticsSpeciesName(size_t k) const; + CT_API std::string kineticsSpeciesName(size_t k) const; /** * This routine will look up a species number based on the input @@ -288,7 +288,7 @@ class Kinetics * * @param nm Input string name of the species */ - size_t kineticsSpeciesIndex(const std::string& nm) const; + CT_API size_t kineticsSpeciesIndex(const std::string& nm) const; /** * This routine will look up a species number based on the input @@ -817,14 +817,14 @@ class Kinetics * at constant pressure, molar concentration and mole fractions. * @param[out] dwdot Output vector of derivatives. Length: m_kk. */ - void getCreationRates_ddT(double* dwdot); + CT_API void getCreationRates_ddT(double* dwdot); /** * Calculate derivatives for species creation rates with respect to pressure * at constant temperature, molar concentration and mole fractions. * @param[out] dwdot Output vector of derivatives. Length: m_kk. */ - void getCreationRates_ddP(double* dwdot); + CT_API void getCreationRates_ddP(double* dwdot); /** * Calculate derivatives for species creation rates with respect to molar @@ -834,7 +834,7 @@ class Kinetics * @warning This method is an experimental part of the %Cantera API and * may be changed or removed without notice. */ - void getCreationRates_ddC(double* dwdot); + CT_API void getCreationRates_ddC(double* dwdot); /** * Calculate derivatives for species creation rates with respect to species @@ -847,21 +847,21 @@ class Kinetics * @warning This method is an experimental part of the %Cantera API and * may be changed or removed without notice. */ - Eigen::SparseMatrix creationRates_ddX(); + CT_API Eigen::SparseMatrix creationRates_ddX(); /** * Calculate derivatives for species destruction rates with respect to temperature * at constant pressure, molar concentration and mole fractions. * @param[out] dwdot Output vector of derivatives. Length: m_kk. */ - void getDestructionRates_ddT(double* dwdot); + CT_API void getDestructionRates_ddT(double* dwdot); /** * Calculate derivatives for species destruction rates with respect to pressure * at constant temperature, molar concentration and mole fractions. * @param[out] dwdot Output vector of derivatives. Length: m_kk. */ - void getDestructionRates_ddP(double* dwdot); + CT_API void getDestructionRates_ddP(double* dwdot); /** * Calculate derivatives for species destruction rates with respect to molar @@ -871,7 +871,7 @@ class Kinetics * @warning This method is an experimental part of the %Cantera API and * may be changed or removed without notice. */ - void getDestructionRates_ddC(double* dwdot); + CT_API void getDestructionRates_ddC(double* dwdot); /** * Calculate derivatives for species destruction rates with respect to species @@ -884,21 +884,21 @@ class Kinetics * @warning This method is an experimental part of the %Cantera API and * may be changed or removed without notice. */ - Eigen::SparseMatrix destructionRates_ddX(); + CT_API Eigen::SparseMatrix destructionRates_ddX(); /** * Calculate derivatives for species net production rates with respect to * temperature at constant pressure, molar concentration and mole fractions. * @param[out] dwdot Output vector of derivatives. Length: m_kk. */ - void getNetProductionRates_ddT(double* dwdot); + CT_API void getNetProductionRates_ddT(double* dwdot); /** * Calculate derivatives for species net production rates with respect to pressure * at constant temperature, molar concentration and mole fractions. * @param[out] dwdot Output vector of derivatives. Length: m_kk. */ - void getNetProductionRates_ddP(double* dwdot); + CT_API void getNetProductionRates_ddP(double* dwdot); /** * Calculate derivatives for species net production rates with respect to molar @@ -908,7 +908,7 @@ class Kinetics * @warning This method is an experimental part of the %Cantera API and * may be changed or removed without notice. */ - void getNetProductionRates_ddC(double* dwdot); + CT_API void getNetProductionRates_ddC(double* dwdot); /** * Calculate derivatives for species net production rates with respect to species @@ -921,7 +921,7 @@ class Kinetics * @warning This method is an experimental part of the %Cantera API and * may be changed or removed without notice. */ - Eigen::SparseMatrix netProductionRates_ddX(); + CT_API Eigen::SparseMatrix netProductionRates_ddX(); //! @} //! @name Reaction Mechanism Informational Query Routines @@ -1147,9 +1147,9 @@ class Kinetics * not affect the Kinetics object until the #modifyReaction function is * called. */ - shared_ptr reaction(size_t i); + CT_API shared_ptr reaction(size_t i); - shared_ptr reaction(size_t i) const; + CT_API shared_ptr reaction(size_t i) const; //! Determine behavior when adding a new reaction that contains species not //! defined in any of the phases associated with this kinetics manager. If diff --git a/include/cantera/kinetics/Reaction.h b/include/cantera/kinetics/Reaction.h index 1074c1cb652..58b4834c1bf 100644 --- a/include/cantera/kinetics/Reaction.h +++ b/include/cantera/kinetics/Reaction.h @@ -315,14 +315,14 @@ class FalloffReaction : public Reaction /*! * @param type string identifying type of reaction. */ -unique_ptr newReaction(const std::string& type); +unique_ptr CT_API 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 newReaction(const AnyMap& rxn_node, +unique_ptr CT_API newReaction(const AnyMap& rxn_node, const Kinetics& kin); //! Create Reaction objects for each item (an AnyMap) in `items`. The species diff --git a/include/cantera/kinetics/ReactionRate.h b/include/cantera/kinetics/ReactionRate.h index 06190592215..da7ab3e2f42 100644 --- a/include/cantera/kinetics/ReactionRate.h +++ b/include/cantera/kinetics/ReactionRate.h @@ -93,7 +93,7 @@ class ReactionRate //! Set parameters //! @param node AnyMap object containing reaction rate specification //! @param units unit definitions specific to rate information - virtual void setParameters(const AnyMap& node, const UnitStack& units) { + CT_API virtual void setParameters(const AnyMap& node, const UnitStack& units) { m_input = node; } @@ -195,7 +195,7 @@ class ReactionRate //! @param node AnyMap containing rate information //! Store the parameters of a ReactionRate needed to reconstruct an identical //! object. Does not include user-defined fields available in the #m_input map. - virtual void getParameters(AnyMap& node) const { + CT_API virtual void getParameters(AnyMap& node) const { throw NotImplementedError("ReactionRate::getParameters", "Not implemented by '{}' object.", type()); } diff --git a/include/cantera/kinetics/ReactionRateFactory.h b/include/cantera/kinetics/ReactionRateFactory.h index 594b5bb924c..183a348adc0 100644 --- a/include/cantera/kinetics/ReactionRateFactory.h +++ b/include/cantera/kinetics/ReactionRateFactory.h @@ -68,7 +68,7 @@ class ReactionRateFactory /*! * @param type string identifying type of reaction rate. */ -shared_ptr newReactionRate(const std::string& type); +shared_ptr CT_API newReactionRate(const std::string& type); //! Create a new Rate object using the specified parameters /*! @@ -76,14 +76,14 @@ shared_ptr newReactionRate(const std::string& type); * @param rate_units Vector describing unit system of the reaction rate; each element * specifies Unit and exponent applied to the unit. */ -shared_ptr newReactionRate( +shared_ptr CT_API newReactionRate( const AnyMap& rate_node, const UnitStack& rate_units); //! Create a new Rate object using the specified parameters /*! * @param rate_node AnyMap node describing reaction rate. */ -shared_ptr newReactionRate(const AnyMap& rate_node); +shared_ptr CT_API newReactionRate(const AnyMap& rate_node); } #endif diff --git a/include/cantera/numerics/Func1.h b/include/cantera/numerics/Func1.h index 0796b97d3b2..16df6b12890 100644 --- a/include/cantera/numerics/Func1.h +++ b/include/cantera/numerics/Func1.h @@ -43,7 +43,7 @@ class TimesConstant1; class Func1 { public: - Func1(); + CT_API Func1(); virtual ~Func1() {} @@ -56,22 +56,22 @@ class Func1 * This duplicates the current function, returning a reference to the newly * created function. */ - virtual Func1& duplicate() const; + CT_API virtual Func1& duplicate() const; - virtual int ID() const; + CT_API virtual int ID() const; //! Calls method eval to evaluate the function doublereal operator()(doublereal t) const; //! Evaluate the function. - virtual doublereal eval(doublereal t) const; + CT_API virtual doublereal eval(doublereal t) const; //! Creates a derivative to the current function /*! * This will create a new derivative function and return a reference to the * function. */ - virtual Func1& derivative() const; + CT_API virtual Func1& derivative() const; //! Routine to determine if two functions are the same. /*! @@ -81,10 +81,10 @@ class Func1 */ bool isIdentical(Func1& other) const; - virtual doublereal isProportional(TimesConstant1& other); - virtual doublereal isProportional(Func1& other); + CT_API virtual double isProportional(TimesConstant1& other); + CT_API virtual double isProportional(Func1& other); - virtual std::string write(const std::string& arg) const; + CT_API virtual std::string write(const std::string& arg) const; //! accessor function for the stored constant doublereal c() const; @@ -99,7 +99,7 @@ class Func1 Func1& func2() const; //! Return the order of the function, if it makes sense - virtual int order() const; + CT_API virtual int order() const; Func1& func1_dup() const; @@ -286,8 +286,8 @@ class Tabulated1 : public Func1 * @param fvals Pointer to function value array * @param method Interpolation method ('linear' or 'previous') */ - Tabulated1(size_t n, const double* tvals, const double* fvals, - const std::string& method = "linear"); + CT_API Tabulated1(size_t n, const double* tvals, const double* fvals, + const std::string& method="linear"); virtual std::string write(const std::string& arg) const; virtual int ID() const { diff --git a/include/cantera/oneD/Boundary1D.h b/include/cantera/oneD/Boundary1D.h index 33c3a8e2ec5..27c2b0bf5a0 100644 --- a/include/cantera/oneD/Boundary1D.h +++ b/include/cantera/oneD/Boundary1D.h @@ -35,7 +35,7 @@ const int RightInlet = -1; class Boundary1D : public Domain1D { public: - Boundary1D(); + CT_API Boundary1D(); virtual void init() { _init(1); @@ -104,9 +104,9 @@ class Boundary1D : public Domain1D class Inlet1D : public Boundary1D { public: - Inlet1D(); + CT_API Inlet1D(); - Inlet1D(shared_ptr solution, const std::string& id="") : Inlet1D() { + CT_API Inlet1D(shared_ptr solution, const std::string& id="") : Inlet1D() { m_solution = solution; m_id = id; } @@ -192,12 +192,12 @@ class Symm1D : public Boundary1D m_id = id; } - virtual void init(); + CT_API virtual void init(); - virtual void eval(size_t jg, double* xg, double* rg, - integer* diagg, double rdt); + CT_API virtual void eval(size_t jg, double* xg, double* rg, + integer* diagg, double rdt); - virtual shared_ptr asArray(const double* soln) const; + CT_API virtual shared_ptr asArray(const double* soln) const; virtual void restore(SolutionArray& arr, double* soln, int loglevel) {} }; @@ -218,12 +218,12 @@ class Outlet1D : public Boundary1D m_id = id; } - virtual void init(); + CT_API virtual void init(); - virtual void eval(size_t jg, double* xg, double* rg, - integer* diagg, double rdt); + CT_API virtual void eval(size_t jg, double* xg, double* rg, + integer* diagg, double rdt); - virtual shared_ptr asArray(const double* soln) const; + CT_API virtual shared_ptr asArray(const double* soln) const; virtual void restore(SolutionArray& arr, double* soln, int loglevel) {} }; @@ -235,7 +235,7 @@ class Outlet1D : public Boundary1D class OutletRes1D : public Boundary1D { public: - OutletRes1D(); + CT_API OutletRes1D(); OutletRes1D(shared_ptr solution, const std::string& id="") : OutletRes1D() @@ -286,17 +286,17 @@ class Surf1D : public Boundary1D m_id = id; } - virtual void init(); + CT_API virtual void init(); - virtual void eval(size_t jg, double* xg, double* rg, - integer* diagg, double rdt); + CT_API virtual void eval(size_t jg, double* xg, double* rg, + integer* diagg, double rdt); - virtual shared_ptr asArray(const double* soln) const; - virtual void restore(SolutionArray& arr, double* soln, int loglevel); + CT_API virtual shared_ptr asArray(const double* soln) const; + CT_API virtual void restore(SolutionArray& arr, double* soln, int loglevel); - virtual void showSolution_s(std::ostream& s, const double* x); + CT_API virtual void showSolution_s(std::ostream& s, const double* x); - virtual void showSolution(const double* x); + CT_API virtual void showSolution(const double* x); }; /** @@ -306,10 +306,10 @@ class Surf1D : public Boundary1D class ReactingSurf1D : public Boundary1D { public: - ReactingSurf1D(); - ReactingSurf1D(shared_ptr solution, const std::string& id=""); + CT_API ReactingSurf1D(); + CT_API ReactingSurf1D(shared_ptr solution, const std::string& id=""); - void setKineticsMgr(InterfaceKinetics* kin); + CT_API void setKineticsMgr(InterfaceKinetics* kin); void enableCoverageEquations(bool docov) { m_enabled = docov; diff --git a/include/cantera/oneD/Domain1D.h b/include/cantera/oneD/Domain1D.h index 7760d107356..9c735f2a4c1 100644 --- a/include/cantera/oneD/Domain1D.h +++ b/include/cantera/oneD/Domain1D.h @@ -44,9 +44,9 @@ class Domain1D * @param points Number of grid points. * @param time (unused) */ - Domain1D(size_t nv=1, size_t points=1, double time=0.0); + CT_API Domain1D(size_t nv=1, size_t points=1, double time=0.0); - virtual ~Domain1D(); + CT_API virtual ~Domain1D(); Domain1D(const Domain1D&) = delete; Domain1D& operator=(const Domain1D&) = delete; @@ -106,7 +106,7 @@ class Domain1D * at the beginning of a simulation. Base class method does nothing, but may * be overloaded. */ - virtual void init() { } + virtual void CT_API init() { } virtual void setInitialState(doublereal* xlocal = 0) {} virtual void setState(size_t point, const doublereal* state, doublereal* x) {} @@ -123,7 +123,7 @@ class Domain1D * is virtual so that subclasses can perform other actions required to * resize the domain. */ - virtual void resize(size_t nv, size_t np); + CT_API virtual void resize(size_t nv, size_t np); //! Return a reference to the grid refiner. Refiner& refiner() { @@ -175,14 +175,14 @@ class Domain1D } //! Name of the nth component. May be overloaded. - virtual std::string componentName(size_t n) const; + CT_API virtual std::string componentName(size_t n) const; void setComponentName(size_t n, const std::string& name) { m_name[n] = name; } //! index of component with name \a name. - virtual size_t componentIndex(const std::string& name) const; + CT_API virtual size_t componentIndex(const std::string& name) const; void setBounds(size_t n, doublereal lower, doublereal upper) { m_min[n] = lower; @@ -197,7 +197,7 @@ class Domain1D * default), these tolerances will be applied to all solution * components. */ - void setTransientTolerances(doublereal rtol, doublereal atol, size_t n=npos); + CT_API void setTransientTolerances(doublereal rtol, doublereal atol, size_t n=npos); //! Set tolerances for steady-state mode /*! @@ -207,7 +207,7 @@ class Domain1D * default), these tolerances will be applied to all solution * components. */ - void setSteadyTolerances(doublereal rtol, doublereal atol, size_t n=npos); + CT_API void setSteadyTolerances(doublereal rtol, doublereal atol, size_t n=npos); //! Relative tolerance of the nth component. doublereal rtol(size_t n) { @@ -296,7 +296,7 @@ class Domain1D * @param[in] rdt Reciprocal of the timestep (`rdt=0` implies steady- * state.) */ - virtual void eval(size_t j, doublereal* x, doublereal* r, + virtual void CT_API eval(size_t j, doublereal* x, doublereal* r, integer* mask, doublereal rdt=0.0) { throw NotImplementedError("Domain1D::eval"); } @@ -440,10 +440,10 @@ class Domain1D } } - virtual void showSolution_s(std::ostream& s, const doublereal* x) {} + CT_API virtual void showSolution_s(std::ostream& s, const doublereal* x) {} //! Print the solution. - virtual void showSolution(const doublereal* x); + CT_API virtual void showSolution(const doublereal* x); doublereal z(size_t jlocal) const { return m_z[jlocal]; @@ -477,10 +477,10 @@ class Domain1D * been set locally prior to installing this domain into the container to be * written to the global solution vector. */ - virtual void _getInitialSoln(doublereal* x); + CT_API virtual void _getInitialSoln(doublereal* x); //! Initial value of solution component \a n at grid point \a j. - virtual doublereal initialValue(size_t n, size_t j); + CT_API virtual doublereal initialValue(size_t n, size_t j); /** * In some cases, a domain may need to set parameters that depend on the @@ -504,10 +504,10 @@ class Domain1D protected: //! Retrieve meta data - virtual AnyMap getMeta() const; + CT_API virtual AnyMap getMeta() const; //! Retrieve meta data - virtual void setMeta(const AnyMap& meta, int loglevel); + CT_API virtual void setMeta(const AnyMap& meta, int loglevel); doublereal m_rdt; size_t m_nv; diff --git a/include/cantera/oneD/IonFlow.h b/include/cantera/oneD/IonFlow.h index 57ef4f9d9e4..a932377865e 100644 --- a/include/cantera/oneD/IonFlow.h +++ b/include/cantera/oneD/IonFlow.h @@ -31,14 +31,14 @@ namespace Cantera class IonFlow : public StFlow { public: - IonFlow(ThermoPhase* ph = 0, size_t nsp = 1, size_t points = 1); + CT_API IonFlow(ThermoPhase* ph=nullptr, size_t nsp=1, size_t points=1); //! Create a new flow domain. //! @param sol Solution object used to evaluate all thermodynamic, kinetic, and //! transport properties //! @param id name of flow domain //! @param points initial number of grid points - IonFlow(shared_ptr sol, const std::string& id="", size_t points = 1); + CT_API IonFlow(shared_ptr sol, const std::string& id="", size_t points=1); //! set the solving stage virtual void setSolvingStage(const size_t phase); @@ -48,9 +48,9 @@ class IonFlow : public StFlow virtual void _finalize(const double* x); //! set to solve electric field on a point - void solveElectricField(size_t j=npos); + CT_API void solveElectricField(size_t j=npos); //! set to fix voltage on a point - void fixElectricField(size_t j=npos); + CT_API void fixElectricField(size_t j=npos); bool doElectricField(size_t j) { return m_do_electric_field[j]; } diff --git a/include/cantera/oneD/OneDim.h b/include/cantera/oneD/OneDim.h index d659f2df7b5..d82d2637f63 100644 --- a/include/cantera/oneD/OneDim.h +++ b/include/cantera/oneD/OneDim.h @@ -184,8 +184,7 @@ class OneDim * the default value is used. * @param count Set to zero to omit this call from the statistics */ - void eval(size_t j, double* x, double* r, doublereal rdt=-1.0, - int count = 1); + CT_API void eval(size_t j, double* x, double* r, double rdt=-1.0, int count=1); //! Return a pointer to the domain global point *i* belongs to. /*! @@ -223,7 +222,7 @@ class OneDim * out The default is true. It's turned off for test * problems where we don't want to print any times */ - void writeStats(int printTime = 1); + CT_API void writeStats(int printTime=1); AnyMap serialize(const double* soln) const; @@ -250,7 +249,7 @@ class OneDim return m_nsteps_max; } - void setJacAge(int ss_age, int ts_age=-1); + CT_API void setJacAge(int ss_age, int ts_age=-1); /** * Save statistics on function and Jacobian evaluation, and reset the @@ -264,10 +263,10 @@ class OneDim * - CPU time spent evaluating functions * - number of time steps */ - void saveStats(); + CT_API void saveStats(); //! Clear saved statistics - void clearStats(); + CT_API void clearStats(); //! Return total grid size in each call to solve() const std::vector& gridSizeStats() { diff --git a/include/cantera/oneD/Sim1D.h b/include/cantera/oneD/Sim1D.h index 973becb5014..c285385a66b 100644 --- a/include/cantera/oneD/Sim1D.h +++ b/include/cantera/oneD/Sim1D.h @@ -35,7 +35,7 @@ class Sim1D : public OneDim * the pointer to the leftmost domain is domain[0], the pointer to the * domain to its right is domain[1], etc. */ - Sim1D(std::vector& domains); + CT_API Sim1D(std::vector& domains); //! @name Setting initial values //! @@ -61,7 +61,7 @@ class Sim1D : public OneDim * the leftmost grid point in the domain. * @param value the value. */ - void setValue(size_t dom, size_t comp, size_t localPoint, doublereal value); + CT_API void setValue(size_t dom, size_t comp, size_t localPoint, double value); /** * Get one entry in the solution vector. @@ -70,9 +70,9 @@ class Sim1D : public OneDim * @param localPoint grid point within the domain, beginning with 0 for * the leftmost grid point in the domain. */ - doublereal value(size_t dom, size_t comp, size_t localPoint) const; + CT_API double value(size_t dom, size_t comp, size_t localPoint) const; - doublereal workValue(size_t dom, size_t comp, size_t localPoint) const; + CT_API double workValue(size_t dom, size_t comp, size_t localPoint) const; /** * Specify a profile for one component of one domain. @@ -88,11 +88,11 @@ class Sim1D : public OneDim * the grid points will be linearly interpolated based on the (pos, * values) specification. */ - void setProfile(size_t dom, size_t comp, const vector_fp& pos, - const vector_fp& values); + CT_API void setProfile(size_t dom, size_t comp, const vector_fp& pos, + const vector_fp& values); //! Set component 'comp' of domain 'dom' to value 'v' at all points. - void setFlatProfile(size_t dom, size_t comp, doublereal v); + CT_API void setFlatProfile(size_t dom, size_t comp, double v); //! @} @@ -104,12 +104,12 @@ class Sim1D : public OneDim * Output information on current solution for all domains to stream. * @param s Output stream */ - void showSolution(std::ostream& s); + CT_API void showSolution(std::ostream& s); /** * Show logging information on current solution for all domains. */ - void showSolution(); + CT_API void showSolution(); /** * Save the current solution to a container file. @@ -119,8 +119,8 @@ class Sim1D : public OneDim * @param loglevel Level of diagnostic output * @param compression Compression level (optional; HDF only) */ - void save(const std::string& fname, const std::string& id, - const std::string& desc, int loglevel=1, int compression=0); + CT_API void save(const std::string& fname, const std::string& id, + const std::string& desc, int loglevel=1, int compression=0); /** * Save the residual of the current solution to a container file. @@ -129,8 +129,8 @@ class Sim1D : public OneDim * @param desc Description of the solution * @param loglevel Level of diagnostic output */ - void saveResidual(const std::string& fname, const std::string& id, - const std::string& desc, int loglevel=1); + CT_API void saveResidual(const std::string& fname, const std::string& id, + const std::string& desc, int loglevel=1); /** * Initialize the solution with a previously-saved solution. @@ -139,7 +139,8 @@ class Sim1D : public OneDim * @param loglevel Level of diagnostic output * @return AnyMap containing header information */ - AnyMap restore(const std::string& fname, const std::string& id, int loglevel=2); + CT_API AnyMap restore(const std::string& fname, const std::string& id, + int loglevel=2); //! @} @@ -150,9 +151,9 @@ class Sim1D : public OneDim return m_x.data(); } - void setTimeStep(double stepsize, size_t n, const int* tsteps); + CT_API void setTimeStep(double stepsize, size_t n, const int* tsteps); - void solve(int loglevel = 0, bool refine_grid = true); + CT_API void solve(int loglevel=0, bool refine_grid=true); void eval(doublereal rdt=-1.0, int count = 1) { OneDim::eval(npos, m_x.data(), m_xnew.data(), rdt, count); @@ -164,46 +165,45 @@ class Sim1D : public OneDim } //! Refine the grid in all domains. - int refine(int loglevel=0); + CT_API int refine(int loglevel=0); //! Add node for fixed temperature point of freely propagating flame - int setFixedTemperature(double t); + CT_API int setFixedTemperature(double t); //! Return temperature at the point used to fix the flame location - double fixedTemperature(); + CT_API double fixedTemperature(); //! Return location of the point where temperature is fixed - double fixedTemperatureLocation(); + CT_API double fixedTemperatureLocation(); /** * Set grid refinement criteria. If dom >= 0, then the settings * apply only to the specified domain. If dom < 0, the settings * are applied to each domain. @see Refiner::setCriteria. */ - void setRefineCriteria(int dom = -1, double ratio = 10.0, - double slope = 0.8, double curve = 0.8, - double prune = -0.1); + CT_API void setRefineCriteria(int dom=-1, double ratio=10.0, double slope=0.8, + double curve=0.8, double prune=-0.1); /** * Get the grid refinement criteria. dom must be greater than * or equal to zero (that is, the domain must be specified). * @see Refiner::getCriteria */ - vector_fp getRefineCriteria(int dom); + CT_API vector_fp getRefineCriteria(int dom); /** * Set the maximum number of grid points in the domain. If dom >= 0, * then the settings apply only to the specified domain. If dom < 0, * the settings are applied to each domain. @see Refiner::setMaxPoints. */ - void setMaxGridPoints(int dom, int npoints); + CT_API void setMaxGridPoints(int dom, int npoints); /** * Get the maximum number of grid points in this domain. @see Refiner::maxPoints * * @param dom domain number, beginning with 0 for the leftmost domain. */ - size_t maxGridPoints(size_t dom); + CT_API size_t maxGridPoints(size_t dom); //! Set the minimum grid spacing in the specified domain(s). /*! @@ -211,19 +211,19 @@ class Sim1D : public OneDim * to all domains. * @param gridmin The minimum allowable grid spacing [m] */ - void setGridMin(int dom, double gridmin); + CT_API void setGridMin(int dom, double gridmin); //! Set the current solution vector to the last successful time-stepping //! solution. This can be used to examine the solver progress after a failed //! integration. - void restoreTimeSteppingSolution(); + CT_API void restoreTimeSteppingSolution(); //! Set the current solution vector and grid to the last successful steady- //! state solution. This can be used to examine the solver progress after a //! failure during grid refinement. - void restoreSteadySolution(); + CT_API void restoreSteadySolution(); - void getInitialSoln(); + CT_API void getInitialSoln(); // @deprecated To be removed after Cantera 3.0 (unused) void setSolution(const doublereal* soln) { @@ -256,7 +256,7 @@ class Sim1D : public OneDim * - \lambda^T \frac{\partial f}{\partial p} * \f] */ - void solveAdjoint(const double* b, double* lambda); + CT_API void solveAdjoint(const double* b, double* lambda); virtual void resize(); diff --git a/include/cantera/oneD/StFlow.h b/include/cantera/oneD/StFlow.h index e41276ada26..14b20cc87ad 100644 --- a/include/cantera/oneD/StFlow.h +++ b/include/cantera/oneD/StFlow.h @@ -49,19 +49,21 @@ 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(ThermoPhase* ph = 0, size_t nsp = 1, size_t points = 1); + CT_API StFlow(ThermoPhase* ph = 0, size_t nsp = 1, size_t points = 1); //! Delegating constructor - StFlow(shared_ptr th, size_t nsp = 1, size_t points = 1) : + CT_API StFlow(shared_ptr th, size_t nsp = 1, size_t points = 1) : StFlow(th.get(), nsp, points) { } + CT_API virtual ~StFlow() = default; + //! Create a new flow domain. //! @param sol Solution object used to evaluate all thermodynamic, kinetic, and //! transport properties //! @param id name of flow domain //! @param points initial number of grid points - StFlow(shared_ptr sol, const std::string& id="", size_t points=1); + CT_API StFlow(shared_ptr sol, const std::string& id="", size_t points=1); //! @name Problem Specification //! @{ @@ -92,15 +94,15 @@ class StFlow : public Domain1D } //! Set transport model to existing instance - void setTransport(Transport& trans); + CT_API void setTransport(Transport& trans); //! Set the transport model //! @since New in Cantera 3.0. - void setTransportModel(const std::string& trans); + CT_API void setTransportModel(const std::string& trans); //! Retrieve transport model //! @since New in Cantera 3.0. - std::string transportModel() const; + CT_API std::string transportModel() const; //! Enable thermal diffusion, also known as Soret diffusion. //! Requires that multicomponent transport properties be @@ -193,7 +195,7 @@ class StFlow : public Domain1D } } - void solveEnergyEqn(size_t j=npos); + CT_API void solveEnergyEqn(size_t j=npos); //! Turn radiation on / off. /*! @@ -222,7 +224,7 @@ class StFlow : public Domain1D * radiative term and writes them into the variables, which are used for the * calculation. */ - void setBoundaryEmissivities(double e_left, double e_right); + CT_API void setBoundaryEmissivities(double e_left, double e_right); //! Return emissivity at left boundary double leftEmissivity() const { return m_epsilon_left; } @@ -230,7 +232,7 @@ class StFlow : public Domain1D //! Return emissivity at right boundary double rightEmissivity() const { return m_epsilon_right; } - void fixTemperature(size_t j=npos); + CT_API void fixTemperature(size_t j=npos); bool doEnergy(size_t j) { return m_do_energy[j]; diff --git a/include/cantera/thermo/Elements.h b/include/cantera/thermo/Elements.h index f46942fd2f8..a315667ffd2 100644 --- a/include/cantera/thermo/Elements.h +++ b/include/cantera/thermo/Elements.h @@ -86,11 +86,11 @@ namespace Cantera //! Get a vector of the atomic symbols of the elements defined in Cantera. //! @since New in version 3.0 -const std::vector& elementSymbols(); +CT_API const std::vector& elementSymbols(); //! Get a vector of the names of the elements defined in Cantera. //! @since New in version 3.0 -const std::vector& elementNames(); +CT_API const std::vector& elementNames(); //! Get a map with the element and isotope symbols and names as keys and weights as //! values. @@ -112,7 +112,7 @@ const std::map& elementWeights(); * @exception CanteraError if a match for ename is not found or the * element has no stable isotopes, and therefore no standard atomic weight */ -double getElementWeight(const std::string& ename); +CT_API double getElementWeight(const std::string& ename); //! Get the atomic weight of an element. /*! @@ -128,7 +128,7 @@ double getElementWeight(const std::string& ename); * @exception CanteraError if the element has no stable isotopes, and * therefore no standard atomic weight */ -double getElementWeight(int atomicNumber); +CT_API double getElementWeight(int atomicNumber); //! Get the symbol for an element /*! @@ -139,7 +139,7 @@ double getElementWeight(int atomicNumber); * @return The symbol of the element in a string * @exception CanteraError if a match for ename is not found */ -std::string getElementSymbol(const std::string& ename); +CT_API std::string getElementSymbol(const std::string& ename); //! Get the symbol for an element /*! @@ -153,7 +153,7 @@ std::string getElementSymbol(const std::string& ename); * @exception IndexError if the passed atomic number less than 1 or * larger than the number of elements defined */ -std::string getElementSymbol(int atomicNumber); +CT_API std::string getElementSymbol(int atomicNumber); //! Get the name of an element /*! @@ -164,7 +164,7 @@ std::string getElementSymbol(int atomicNumber); * @return The name of the element, in a string * @exception CanteraError if a match for ename is not found */ -std::string getElementName(const std::string& ename); +CT_API std::string getElementName(const std::string& ename); //! Get the name of an element /*! @@ -178,7 +178,7 @@ std::string getElementName(const std::string& ename); * @exception CanteraError IndexError if the passed atomic number less than 1 or * larger than the number of elements defined */ -std::string getElementName(int atomicNumber); +CT_API std::string getElementName(int atomicNumber); //! Get the atomic number for an element /*! @@ -189,17 +189,17 @@ std::string getElementName(int atomicNumber); * @return The integer atomic number of the element * @exception CanteraError if a match for ename is not found */ -int getAtomicNumber(const std::string& ename); +CT_API int getAtomicNumber(const std::string& ename); //! Get the number of named elements defined in Cantera. //! This array excludes named isotopes //! @since Type is `size_t` in Cantera 3.0 -size_t numElementsDefined(); +CT_API size_t numElementsDefined(); //! Get the number of named isotopes defined in Cantera. //! This array excludes the named elements //! @since Type is `size_t` in Cantera 3.0 -size_t numIsotopesDefined(); +CT_API size_t numIsotopesDefined(); } // namespace diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index 5d7c64431a3..4d1e3c30d7e 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -153,20 +153,20 @@ class Phase //! Name of the element with index m. //! @param m Element index. - std::string elementName(size_t m) const; + CT_API std::string elementName(size_t m) const; //! Return the index of element named 'name'. The index is an integer //! assigned to each element in the order it was added. Returns \ref npos //! if the specified element is not found. //! @param name Name of the element - size_t elementIndex(const std::string& name) const; + CT_API size_t elementIndex(const std::string& name) const; //! Return a read-only reference to the vector of element names. const std::vector& elementNames() const; //! Atomic weight of element m. //! @param m Element index - doublereal atomicWeight(size_t m) const; + CT_API doublereal atomicWeight(size_t m) const; //! Entropy of the element in its standard state at 298 K and 1 bar. //! If no entropy value was provided when the phase was constructed, @@ -206,7 +206,7 @@ class Phase const vector_fp& atomicWeights() const; //! Number of elements. - size_t nElements() const; + CT_API size_t nElements() const; //! Check that the specified element index is in range. //! Throws an exception if m is greater than nElements()-1 @@ -220,7 +220,7 @@ class Phase //! Number of atoms of element \c m in species \c k. //! @param k species index //! @param m element index - doublereal nAtoms(size_t k, size_t m) const; + CT_API doublereal nAtoms(size_t k, size_t m) const; //! Get a vector containing the atomic composition of species k //! @param k species index @@ -235,11 +235,11 @@ class Phase //! phaseName:speciesName //! @return The index of the species. If the name is not found, //! the value \ref npos is returned. - size_t speciesIndex(const std::string& name) const; + CT_API size_t speciesIndex(const std::string& name) const; //! Name of the species with index k //! @param k index of the species - std::string speciesName(size_t k) const; + CT_API std::string speciesName(size_t k) const; //! Returns the expanded species name of a species, including the phase name //! This is guaranteed to be unique within a Cantera problem. @@ -350,28 +350,28 @@ class Phase //! Set the species mole fractions by name. //! Species not listed by name in \c xMap are set to zero. //! @param xMap map from species names to mole fraction values. - void setMoleFractionsByName(const compositionMap& xMap); + CT_API void setMoleFractionsByName(const compositionMap& xMap); //! Set the mole fractions of a group of species by name. Species which //! are not listed by name in the composition map are set to zero. //! @param x string x in the form of a composition map - void setMoleFractionsByName(const std::string& x); + CT_API void setMoleFractionsByName(const std::string& x); //! Set the species mass fractions by name. //! Species not listed by name in \c yMap are set to zero. //! @param yMap map from species names to mass fraction values. - void setMassFractionsByName(const compositionMap& yMap); + CT_API void setMassFractionsByName(const compositionMap& yMap); //! Set the species mass fractions by name. //! Species not listed by name in \c x are set to zero. //! @param x String containing a composition map - void setMassFractionsByName(const std::string& x); + CT_API void setMassFractionsByName(const std::string& x); //! Set the internally stored temperature (K), density, and mole fractions. //! @param t Temperature in kelvin //! @param dens Density (kg/m^3) //! @param x vector of species mole fractions, length m_kk - void setState_TRX(doublereal t, doublereal dens, const doublereal* x); + CT_API void setState_TRX(doublereal t, doublereal dens, const doublereal* x); //! Set the internally stored temperature (K), density, and mole fractions. //! @param t Temperature in kelvin @@ -379,13 +379,13 @@ class Phase //! @param x Composition Map containing the mole fractions. //! Species not included in the map are assumed to have //! a zero mole fraction. - void setState_TRX(doublereal t, doublereal dens, const compositionMap& x); + CT_API void setState_TRX(doublereal t, doublereal dens, const compositionMap& x); //! Set the internally stored temperature (K), density, and mass fractions. //! @param t Temperature in kelvin //! @param dens Density (kg/m^3) //! @param y vector of species mass fractions, length m_kk - void setState_TRY(doublereal t, doublereal dens, const doublereal* y); + CT_API void setState_TRY(doublereal t, doublereal dens, const doublereal* y); //! Set the internally stored temperature (K), density, and mass fractions. //! @param t Temperature in kelvin @@ -393,66 +393,66 @@ class Phase //! @param y Composition Map containing the mass fractions. //! Species not included in the map are assumed to have //! a zero mass fraction. - void setState_TRY(doublereal t, doublereal dens, const compositionMap& y); + CT_API void setState_TRY(doublereal t, doublereal dens, const compositionMap& y); //! Set the internally stored temperature (K), molar density (kmol/m^3), and //! mole fractions. //! @param t Temperature in kelvin //! @param n molar density (kmol/m^3) //! @param x vector of species mole fractions, length m_kk - void setState_TNX(doublereal t, doublereal n, const doublereal* x); + CT_API void setState_TNX(doublereal t, doublereal n, const doublereal* x); //! Set the internally stored temperature (K) and density (kg/m^3) //! @param t Temperature in kelvin //! @param rho Density (kg/m^3) - void setState_TR(doublereal t, doublereal rho); + CT_API void setState_TR(doublereal t, doublereal rho); //! Set the internally stored temperature (K) and mole fractions. //! @param t Temperature in kelvin //! @param x vector of species mole fractions, length m_kk - void setState_TX(doublereal t, doublereal* x); + CT_API void setState_TX(doublereal t, doublereal* x); //! Set the internally stored temperature (K) and mass fractions. //! @param t Temperature in kelvin //! @param y vector of species mass fractions, length m_kk - void setState_TY(doublereal t, doublereal* y); + CT_API void setState_TY(doublereal t, doublereal* y); //! Set the density (kg/m^3) and mole fractions. //! @param rho Density (kg/m^3) //! @param x vector of species mole fractions, length m_kk - void setState_RX(doublereal rho, doublereal* x); + CT_API void setState_RX(doublereal rho, doublereal* x); //! Set the density (kg/m^3) and mass fractions. //! @param rho Density (kg/m^3) //! @param y vector of species mass fractions, length m_kk - void setState_RY(doublereal rho, doublereal* y); + CT_API void setState_RY(doublereal rho, doublereal* y); //! @} end group set thermo state //! Molecular weight of species \c k. //! @param k index of species \c k //! @returns the molecular weight of species \c k. - doublereal molecularWeight(size_t k) const; + CT_API doublereal molecularWeight(size_t k) const; //! Copy the vector of molecular weights into vector weights. //! @param weights Output vector of molecular weights (kg/kmol) - void getMolecularWeights(vector_fp& weights) const; + CT_API void getMolecularWeights(vector_fp& weights) const; //! Copy the vector of molecular weights into array weights. //! @param weights Output array of molecular weights (kg/kmol) - void getMolecularWeights(doublereal* weights) const; + CT_API void getMolecularWeights(doublereal* weights) const; //! Return a const reference to the internal vector of molecular weights. //! units = kg / kmol - const vector_fp& molecularWeights() const; + CT_API const vector_fp& molecularWeights() const; //! Return a const reference to the internal vector of molecular weights. //! units = kmol / kg - const vector_fp& inverseMolecularWeights() const; + CT_API const vector_fp& inverseMolecularWeights() const; //! Copy the vector of species charges into array charges. //! @param charges Output array of species charges (elem. charge) - void getCharges(double* charges) const; + CT_API void getCharges(double* charges) const; //! @name Composition //! @{ @@ -461,38 +461,38 @@ class Phase //! @param threshold Exclude species with mole fractions less than or //! equal to this threshold. //! @return Map of species names to mole fractions - compositionMap getMoleFractionsByName(double threshold=0.0) const; + CT_API compositionMap getMoleFractionsByName(double threshold=0.0) const; //! Return the mole fraction of a single species //! @param k species index //! @return Mole fraction of the species - double moleFraction(size_t k) const; + CT_API double moleFraction(size_t k) const; //! Return the mole fraction of a single species //! @param name String name of the species //! @return Mole fraction of the species - double moleFraction(const std::string& name) const; + CT_API double moleFraction(const std::string& name) const; //! Get the mass fractions by name. //! @param threshold Exclude species with mass fractions less than or //! equal to this threshold. //! @return Map of species names to mass fractions - compositionMap getMassFractionsByName(double threshold=0.0) const; + CT_API compositionMap getMassFractionsByName(double threshold=0.0) const; //! Return the mass fraction of a single species //! @param k species index //! @return Mass fraction of the species - double massFraction(size_t k) const; + CT_API double massFraction(size_t k) const; //! Return the mass fraction of a single species //! @param name String name of the species //! @return Mass Fraction of the species - double massFraction(const std::string& name) const; + CT_API double massFraction(const std::string& name) const; //! Get the species mole fraction vector. //! @param x On return, x contains the mole fractions. Must have a //! length greater than or equal to the number of species. - void getMoleFractions(double* const x) const; + CT_API void getMoleFractions(double* const x) const; //! Set the mole fractions to the specified values. //! There is no restriction on the sum of the mole fraction vector. @@ -500,18 +500,18 @@ class Phase //! its contents. //! @param x Array of unnormalized mole fraction values (input). Must //! have a length greater than or equal to the number of species, m_kk. - virtual void setMoleFractions(const double* const x); + CT_API virtual void setMoleFractions(const double* const x); //! Set the mole fractions to the specified values without normalizing. //! This is useful when the normalization condition is being handled by //! some other means, for example by a constraint equation as part of a //! larger set of equations. //! @param x Input vector of mole fractions. Length is m_kk. - virtual void setMoleFractions_NoNorm(const double* const x); + CT_API virtual void setMoleFractions_NoNorm(const double* const x); //! Get the species mass fractions. //! @param[out] y Array of mass fractions, length nSpecies() - void getMassFractions(double* const y) const; + CT_API void getMassFractions(double* const y) const; //! Return a const pointer to the mass fraction array const double* massFractions() const { @@ -523,14 +523,14 @@ class Phase //! must be greater than or equal to the number of //! species. The Phase object will normalize this vector //! before storing its contents. - virtual void setMassFractions(const double* const y); + CT_API virtual void setMassFractions(const double* const y); //! Set the mass fractions to the specified values without normalizing. //! This is useful when the normalization condition is being handled by //! some other means, for example by a constraint equation as part of a //! larger set of equations. //! @param y Input vector of mass fractions. Length is m_kk. - virtual void setMassFractions_NoNorm(const double* const y); + CT_API virtual void setMassFractions_NoNorm(const double* const y); //! Get the species concentrations (kmol/m^3). /*! @@ -538,7 +538,7 @@ class Phase * kmol/m^3. The length of the vector must be greater than * or equal to the number of species within the phase. */ - virtual void getConcentrations(double* const c) const; + CT_API virtual void getConcentrations(double* const c) const; //! Concentration of species k. //! If k is outside the valid range, an exception will be thrown. @@ -547,7 +547,7 @@ class Phase * * @returns the concentration of species k (kmol m-3). */ - virtual double concentration(const size_t k) const; + CT_API virtual double concentration(const size_t k) const; //! Set the concentrations to the specified values within the phase. //! We set the concentrations here and therefore we set the overall density @@ -559,14 +559,14 @@ class Phase //! species in kmol/m3. For surface phases, c[k] is the //! concentration in kmol/m2. The length of the vector //! is the number of species in the phase. - virtual void setConcentrations(const double* const conc); + CT_API virtual void setConcentrations(const double* const conc); //! Set the concentrations without ignoring negative concentrations - virtual void setConcentrationsNoNorm(const double* const conc); + CT_API virtual void setConcentrationsNoNorm(const double* const conc); //! @} //! Set the state of the object with moles in [kmol] - virtual void setMolesNoTruncate(const double* const N); + CT_API virtual void setMolesNoTruncate(const double* const N); //! Elemental mass fraction of element m /*! @@ -585,7 +585,7 @@ class Phase * * @return the elemental mass fraction of element m. */ - doublereal elementalMassFraction(const size_t m) const; + CT_API doublereal elementalMassFraction(const size_t m) const; //! Elemental mole fraction of element m /*! @@ -605,12 +605,12 @@ class Phase * valid range, an exception will be thrown. * @return the elemental mole fraction of element m. */ - doublereal elementalMoleFraction(const size_t m) const; + CT_API doublereal elementalMoleFraction(const size_t m) const; //! Returns a const pointer to the start of the moleFraction/MW array. //! This array is the array of mole fractions, each divided by the mean //! molecular weight. - const double* moleFractdivMMW() const; + CT_API const double* moleFractdivMMW() const; //! Dimensionless electrical charge of a single molecule of species k //! The charge is normalized by the the magnitude of the electron charge @@ -620,7 +620,7 @@ class Phase } //! Charge density [C/m^3]. - doublereal chargeDensity() const; + CT_API doublereal chargeDensity() const; //! Returns the number of spatial dimensions (1, 2, or 3) size_t nDim() const { @@ -670,20 +670,20 @@ class Phase //! Molar density (kmol/m^3). //! @return The molar density of the phase - virtual double molarDensity() const; + CT_API virtual double molarDensity() const; //! Molar volume (m^3/kmol). //! @return The molar volume of the phase - virtual double molarVolume() const; + CT_API virtual double molarVolume() const; //! Set the internally stored density (kg/m^3) of the phase. //! Note the density of a phase is an independent variable. //! @param[in] density_ density (kg/m^3). - virtual void setDensity(const double density_); + CT_API virtual void setDensity(const double density_); //! Set the internally stored molar density (kmol/m^3) of the phase. //! @param[in] molarDensity Input molar density (kmol/m^3). - virtual void setMolarDensity(const double molarDensity); + CT_API virtual void setMolarDensity(const double molarDensity); //! Set the internally stored pressure (Pa) at constant temperature and //! composition @@ -823,7 +823,7 @@ class Phase //! Set behavior when adding a species containing undefined elements to add //! those elements to the phase. This is the default behavior. - void addUndefinedElements(); + CT_API void addUndefinedElements(); //! Set the behavior when adding a species containing undefined elements to //! throw an exception. diff --git a/include/cantera/thermo/ThermoFactory.h b/include/cantera/thermo/ThermoFactory.h index d8d13c5d45e..048f7ed5244 100644 --- a/include/cantera/thermo/ThermoFactory.h +++ b/include/cantera/thermo/ThermoFactory.h @@ -34,20 +34,10 @@ class ThermoFactory : public Factory { public: //! Static function that creates a static instance of the factory. - static ThermoFactory* factory() { - std::unique_lock lock(thermo_mutex); - if (!s_factory) { - s_factory = new ThermoFactory; - } - return s_factory; - } + static ThermoFactory* factory(); //! delete the static instance of this factory - virtual void deleteFactory() { - std::unique_lock lock(thermo_mutex); - delete s_factory; - s_factory = 0; - } + virtual void deleteFactory(); //! Create a new thermodynamic property manager. /*! @@ -62,28 +52,21 @@ class ThermoFactory : public Factory static ThermoFactory* s_factory; //! Private constructors prevents usage - ThermoFactory(); + CT_API ThermoFactory(); //! Decl for locking mutex for thermo factory singleton static std::mutex thermo_mutex; }; //! @copydoc ThermoFactory::newThermoPhase -inline ThermoPhase* newThermoPhase(const std::string& model) -{ - return ThermoFactory::factory()->create(model); -} +ThermoPhase* newThermoPhase(const std::string& model); //! Create a new ThermoPhase instance. /*! * @param model String to look up the model against * @returns a shared pointer to a new ThermoPhase instance matching the model string. */ -inline shared_ptr newThermo(const std::string& model) -{ - ThermoPhase* tptr = ThermoFactory::factory()->create(model); - return shared_ptr (tptr); -} +shared_ptr CT_API newThermo(const std::string& model); //! Create a new ThermoPhase object and initialize it /*! @@ -93,7 +76,7 @@ inline shared_ptr newThermo(const std::string& model) * which will be used as the default location from which to read species * definitions. */ -unique_ptr newPhase(const AnyMap& phaseNode, +unique_ptr CT_API newPhase(const AnyMap& phaseNode, const AnyMap& rootNode=AnyMap()); //! Create and Initialize a ThermoPhase object from an input file. @@ -107,7 +90,7 @@ unique_ptr newPhase(const AnyMap& phaseNode, * If this is blank, the first phase in the file is used. * @returns an initialized ThermoPhase object. */ -ThermoPhase* newPhase(const std::string& infile, std::string id=""); +ThermoPhase CT_API * newPhase(const std::string& infile, std::string id=""); //! Initialize a ThermoPhase object /*! diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index 0c383e50ffa..6f4e7ce5cfd 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -505,7 +505,7 @@ class ThermoPhase : public Phase * @param mu Output vector of species electrochemical * potentials. Length: m_kk. Units: J/kmol */ - void getElectrochemPotentials(doublereal* mu) const; + CT_API void getElectrochemPotentials(doublereal* mu) const; //! Returns an array of partial molar enthalpies for the species //! in the mixture. Units (J/kmol) @@ -1196,13 +1196,13 @@ class ThermoPhase : public Phase * Fuel and oxidizer composition are interpreted * as mole or mass fractions (default: molar) */ - void setMixtureFraction(double mixFrac, const double* fuelComp, + CT_API void setMixtureFraction(double mixFrac, const double* fuelComp, const double* oxComp, ThermoBasis basis=ThermoBasis::molar); //! @copydoc ThermoPhase::setMixtureFraction - void setMixtureFraction(double mixFrac, const std::string& fuelComp, + CT_API void setMixtureFraction(double mixFrac, const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis=ThermoBasis::molar); //! @copydoc ThermoPhase::setMixtureFraction - void setMixtureFraction(double mixFrac, const compositionMap& fuelComp, + CT_API void setMixtureFraction(double mixFrac, const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar); //! @} //! @name Compute Mixture Fraction @@ -1240,15 +1240,15 @@ class ThermoPhase : public Phase * based on a single element (default: "Bilger") * @returns mixture fraction (kg fuel / kg mixture) */ - double mixtureFraction(const double* fuelComp, const double* oxComp, + CT_API double mixtureFraction(const double* fuelComp, const double* oxComp, ThermoBasis basis=ThermoBasis::molar, const std::string& element="Bilger") const; //! @copydoc ThermoPhase::mixtureFraction - double mixtureFraction(const std::string& fuelComp, const std::string& oxComp, + CT_API double mixtureFraction(const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis=ThermoBasis::molar, const std::string& element="Bilger") const; //! @copydoc ThermoPhase::mixtureFraction - double mixtureFraction(const compositionMap& fuelComp, const compositionMap& oxComp, + CT_API double mixtureFraction(const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar, const std::string& element="Bilger") const; //! @} @@ -1269,13 +1269,13 @@ class ThermoPhase : public Phase * Fuel and oxidizer composition are interpreted * as mole or mass fractions (default: molar) */ - void setEquivalenceRatio(double phi, const double* fuelComp, const double* oxComp, + CT_API void setEquivalenceRatio(double phi, const double* fuelComp, const double* oxComp, ThermoBasis basis=ThermoBasis::molar); //! @copydoc ThermoPhase::setEquivalenceRatio - void setEquivalenceRatio(double phi, const std::string& fuelComp, + CT_API void setEquivalenceRatio(double phi, const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis=ThermoBasis::molar); //! @copydoc ThermoPhase::setEquivalenceRatio - void setEquivalenceRatio(double phi, const compositionMap& fuelComp, + CT_API void setEquivalenceRatio(double phi, const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar); //! @} @@ -1306,13 +1306,13 @@ class ThermoPhase : public Phase * @see mixtureFraction for the definition of the Bilger mixture fraction * @see equivalenceRatio() for the computation of \f$ \phi \f$ without arguments */ - double equivalenceRatio(const double* fuelComp, const double* oxComp, + CT_API double equivalenceRatio(const double* fuelComp, const double* oxComp, ThermoBasis basis=ThermoBasis::molar) const; //! @copydoc ThermoPhase::equivalenceRatio - double equivalenceRatio(const std::string& fuelComp, const std::string& oxComp, + CT_API double equivalenceRatio(const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis=ThermoBasis::molar) const; //! @copydoc ThermoPhase::equivalenceRatio - double equivalenceRatio(const compositionMap& fuelComp, + CT_API double equivalenceRatio(const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar) const; //! @} @@ -1361,13 +1361,13 @@ class ThermoPhase : public Phase * as mole or mass fractions (default: molar) * @returns Stoichiometric Air to Fuel Ratio (kg oxidizer / kg fuel) */ - double stoichAirFuelRatio(const double* fuelComp, const double* oxComp, + CT_API double stoichAirFuelRatio(const double* fuelComp, const double* oxComp, ThermoBasis basis=ThermoBasis::molar) const; //! @copydoc ThermoPhase::stoichAirFuelRatio - double stoichAirFuelRatio(const std::string& fuelComp, const std::string& oxComp, + CT_API double stoichAirFuelRatio(const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis=ThermoBasis::molar) const; //! @copydoc ThermoPhase::stoichAirFuelRatio - double stoichAirFuelRatio(const compositionMap& fuelComp, + CT_API double stoichAirFuelRatio(const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar) const; //! @} @@ -1453,7 +1453,7 @@ class ThermoPhase : public Phase * * @ingroup equilfunctions */ - void equilibrate(const std::string& XY, const std::string& solver="auto", + CT_API void equilibrate(const std::string& XY, const std::string& solver="auto", double rtol=1e-9, int max_steps=50000, int max_iter=100, int estimate_equil=0, int log_level=0); diff --git a/include/cantera/zeroD/ReactorFactory.h b/include/cantera/zeroD/ReactorFactory.h index 3993ac0ff97..bfc3f9f9c8c 100644 --- a/include/cantera/zeroD/ReactorFactory.h +++ b/include/cantera/zeroD/ReactorFactory.h @@ -52,7 +52,7 @@ class ReactorFactory : public Factory //! Create a Reactor object of the specified type //! @ingroup ZeroD -inline ReactorBase* newReactor(const std::string& model) +inline ReactorBase CT_API * newReactor(const std::string& model) { return ReactorFactory::factory()->newReactor(model); } diff --git a/interfaces/cython/SConscript b/interfaces/cython/SConscript index ef34af3f786..c13ba295b0b 100644 --- a/interfaces/cython/SConscript +++ b/interfaces/cython/SConscript @@ -44,6 +44,11 @@ for pyxfile in multi_glob(localenv, "cantera", "pyx"): f"#build/temp-py/{pyxfile.name.split('.')[0]}", cythonized) cython_obj.append(obj) +if not env['system_fmt']: + # Workaround until we can figure out why all the necessary symbols aren't + # being exported from fmt + cython_obj.extend(localenv['fmt_targets']) + module_ext = localenv["py_module_ext"] ext = localenv.LoadableModule(f"cantera/_cantera{module_ext}", cython_obj, LIBPREFIX="", SHLIBSUFFIX=module_ext, @@ -61,7 +66,7 @@ env['python_extension'] = ext localenv.Depends(mod, [ext, dataFiles, setup_cfg, readme, license, "setup.py", "pyproject.toml", "cantera/test/README.txt", "cantera/examples/README.txt"]) -localenv.Depends(ext, localenv['cantera_staticlib']) +localenv.Depends(ext, localenv['cantera_shlib']) for f in (multi_glob(localenv, 'cantera', 'py') + multi_glob(localenv, 'cantera/*', 'py')): diff --git a/interfaces/cython/cantera/reaction.pxd b/interfaces/cython/cantera/reaction.pxd index 30efbbfd79c..d199e52f664 100644 --- a/interfaces/cython/cantera/reaction.pxd +++ b/interfaces/cython/cantera/reaction.pxd @@ -256,6 +256,12 @@ cdef class CustomRate(ReactionRate): cdef CxxCustomFunc1Rate* cxx_object(self) cdef Func1 _rate_func # prevent premature garbage collection +cdef class InterfaceRateBase(ArrheniusRateBase): + cdef CxxInterfaceRateBase* interface + +cdef class StickRateBase(InterfaceRateBase): + cdef CxxStickingCoverage* stick + cdef class ExtensibleRate(ReactionRate): cdef public list _delegates cdef set_cxx_object(self, CxxReactionRate* rate=*) @@ -264,12 +270,6 @@ cdef class ExtensibleRateData: cdef public list _delegates cdef set_cxx_object(self, CxxReactionDataDelegator* rate) -cdef class InterfaceRateBase(ArrheniusRateBase): - cdef CxxInterfaceRateBase* interface - -cdef class StickRateBase(InterfaceRateBase): - cdef CxxStickingCoverage* stick - cdef class ThirdBody: cdef shared_ptr[CxxThirdBody] _third_body cdef CxxThirdBody* third_body diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index 88fb63500d7..134cb8c755d 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -1285,7 +1285,7 @@ def setup_python_env(env): plat = info['plat'].replace('-', '_').replace('.', '_') numpy_include = info["numpy_include"] env.Prepend(CPPPATH=[Dir('#include'), inc, numpy_include]) - env.Prepend(LIBS=env['cantera_libs']) + env.Prepend(LIBS=env['cantera_shared_libs']) # Fix the module extension for Windows from the sysconfig library. # See https://github.com/python/cpython/pull/22088 and diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index fd6edb4c92d..b9f5e04a01a 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -106,6 +106,33 @@ ThermoFactory::ThermoFactory() reg("Peng-Robinson", []() { return new PengRobinson(); }); } +ThermoFactory* ThermoFactory::factory() +{ + std::unique_lock lock(thermo_mutex); + if (!s_factory) { + s_factory = new ThermoFactory; + } + return s_factory; +} + +void ThermoFactory::deleteFactory() +{ + std::unique_lock lock(thermo_mutex); + delete s_factory; + s_factory = 0; +} + +ThermoPhase* newThermoPhase(const std::string& model) +{ + return ThermoFactory::factory()->create(model); +} + +shared_ptr newThermo(const std::string& model) +{ + ThermoPhase* tptr = ThermoFactory::factory()->create(model); + return shared_ptr (tptr); +} + ThermoPhase* ThermoFactory::newThermoPhase(const std::string& model) { return create(model);