Commit Graph

10163 Commits

Author SHA1 Message Date
Bryan Weber
82c323f3f8 Refactor dimensions tests 2023-04-25 18:14:19 -04:00
Bryan Weber
c02f01725d [Units/Test] Refactor test suite to use pytest
This increases the line coverage to near 100%, uses pint's testing
assertions rather than rolling our own, and uses parameterize
extensively to reduce boilerplate in testing as many properties as
possible.
2023-04-25 18:14:19 -04:00
Bryan Weber
b1c1f865a8 Missing a license header 2023-04-25 18:14:19 -04:00
Bryan Weber
a832a712ba [Units] Refactor setter to use a loop
Rather than checking each value individually with try/except, use the
ito method and try to convert within a loop. This simplifies testing for
the error condition and looks a little cleaner.
2023-04-25 18:14:19 -04:00
Bryan Weber
c178c7c6c4 [Units] Pass through kwargs in constructor
Allow setting the backed of the Water instance. Fix a typo in the R134a
instance.
2023-04-25 18:14:19 -04:00
Bryan Weber
d28809f7ac [Test] Add branch coverage to Python 2023-04-25 18:14:19 -04:00
Bryan Weber
0aec8761f4 [Cython] Fix a typo in an error message 2023-04-25 18:14:19 -04:00
Bryan Weber
f1a61f8d16 [CI] Run examples from installed wheel
This lets us check whether the wheel is built properly and includes all
the files necessary for the package to function.
2023-04-25 18:14:19 -04:00
Bryan Weber
82a24baa73 [Examples] Add example keywords for units 2023-04-25 18:14:19 -04:00
Bryan Weber
08997ddd53 [Cython] Move units package to with_units
The units package shadowed the units Cython module. This made Cython
very unhappy and we couldn't import anything from Cantera.
2023-04-25 18:14:19 -04:00
Bryan Weber
a6eda3d083 [Cython] Fix setuptools warning about data
The include_package_data config option is redundant with explicitly
listing the package data, so setuptools was generating warnings. Since
we explicitly list everything, this can be removed.
2023-04-25 18:14:19 -04:00
Bryan Weber
930586ec6b [Units] Add application-level registry
This supports pickling and unpickling of quantities carrying Pint units.
2023-04-25 18:14:19 -04:00
Bryan Weber
65518d5ae8 [Doc] Add default python_module key into env
This prevents KeyError failures if sphinx_docs=y and python_package=n
2023-04-25 18:14:19 -04:00
hallaali
72ac6d5cc9 Update rankine_units.py 2023-04-25 18:14:19 -04:00
Bryan Weber
4ef563edb0 add pint dependency to CI 2023-04-25 18:14:19 -04:00
hallaali
a474076adf fix capitalization error 2023-04-25 18:14:19 -04:00
Bryan Weber
5af39ca105 Fix up tests for units module
* Remove unnecessary tests of the underlying implementation that
  duplicate functionality in the upstream tests.
* Move some dimensionality tests into the PureFluid tests where the
  saturation and critical attributes exist.
* Remove unused imports
2023-04-25 18:14:19 -04:00
Bryan Weber
83058ed676 Add critical_density units 2023-04-25 18:14:19 -04:00
Bryan Weber
e4bd04f2a4 Use numpy.isclose to compare array Quantities
The existing assertArrayNear method was causing units to be stripped
from the array Quantities. Avoiding numpy.asarray conversions and
using numpy.isclose prevents that from happening.
2023-04-25 18:14:19 -04:00
Bryan Weber
09faa1e438 Refactor setter and getter templates for units
* To allow setting properties on the upstream classes, __setattr__ is
  implemented and checks whether the attribute is defined on this
  class. This requires setting the phase instance directly into the
  __dict__ attribute to avoid a recursion error.
* Class inheritance is not used here because it is not easy to set
  attributes on the super class. By design, super() does not allow
  setting properties, only getting. Furthermore, since the base
  PureFluid class is defined in Cython, the attributes of that class
  cannot be set by subclasses at all, again by design.
* The PureFluid class implemented here does not inherit from the
  Solution class implemented here because eventually this Solution class
  will include methods and properties related to kinetics and transport,
  which are not implemented for PureFluid. The base PureFluid class is a
  subclass of ThermoPhase only, whereas the base Solution class is a
  subclass of ThermoPhase, Kinetics, and Transport.
* To reflect the distinction between Solution and ThermoPhase, the
  template variables are renamed.
* Several methods of the PureFluid are getters only, despite having
  three properties. These attributes are fixed here. TPQ is the only
  three-property attribute with a setter.
* Setter methods now raise a CanteraError if the unit conversion to base
  units fails due to an AttributeError.
2023-04-25 18:14:19 -04:00
Bryan Weber
24e7f0ea74 Refactor PureFluid derived classes as functions
Since the only overridden method was __init__, it makes more sense for
these to be functions than subclasses.
2023-04-25 18:14:19 -04:00
hallaali
f5076248f5 fix tests and update unit examples 2023-04-25 18:14:19 -04:00
hallaali
a299ab7824 Create Python examples with units
These examples use the units module to implement the existing examples,
but demonstrate how alternative units can be used for the input and
output quantities.
2023-04-25 18:14:19 -04:00
hallaali
07e5b82ba1 Create test_units.py 2023-04-25 18:14:19 -04:00
hallaali
7289feaa94 Implement unit conversion file into Cantera
Template file added to Sconscript to autogenerate code in
solution.py.in
2023-04-25 18:14:19 -04:00
Ray Speth
da34f8f618 [Doc] Fix some Doxygen warnings 2023-04-21 18:44:56 -05:00
Ray Speth
248b8172ce [Kinetics] Don't use m_grt as temporary array for other quantities 2023-04-21 18:44:56 -05:00
Ray Speth
80dc64c875 [Kinetics] Consolidate update of rate coefficients and rates of progress 2023-04-21 18:44:56 -05:00
Ray Speth
b5d456545b [Kinetics] Merge GasKinetics into BulkKinetics 2023-04-21 18:44:56 -05:00
Ray Speth
9f0333cfeb [Doc] Clarify use case for Arrhenius::setRateParameters 2023-04-21 18:44:56 -05:00
Ray Speth
13b8e1036a [Transport] Remove unused member variables 2023-04-21 18:44:56 -05:00
Ray Speth
0a0c75b377 [Python] Remove unused "wrapArrhenius" function 2023-04-21 18:44:56 -05:00
Ray Speth
707c569a3d [Kinetics] Deprecate reacting phase not in first position
Standardize on the behavior implemented by the newSolution and
newInterface constructors.
2023-04-21 18:44:56 -05:00
Ray Speth
e82f932119 [Python] Clarify use of unit conversion functions 2023-04-18 09:33:15 -05:00
Ray Speth
8f3b106fdf Update ExtensibleReaction example to model additional methods 2023-04-18 09:33:15 -05:00
Ray Speth
1760a3145f Implement ExtensibleRate.validate 2023-04-18 09:33:15 -05:00
Ray Speth
e053f58e61 [Kinetics] Make Solution object available while adding reactions 2023-04-18 09:33:15 -05:00
Ray Speth
b2120c513b [Delegator] Move handling of Solution wrapper name to ExtensionManager 2023-04-18 09:33:15 -05:00
Ray Speth
7537d15d0f Make functions with signature void(string&, void*) delegatable 2023-04-18 09:33:15 -05:00
Ray Speth
3e07f34f4f Update gitignore 2023-04-18 09:33:15 -05:00
Ray Speth
f1f0895ece [Python] Implement output unit conversions for AnyMap 2023-04-18 09:33:15 -05:00
Ray Speth
d29cd1b5bc [Kinetics] Simplify falloff serialization 2023-04-18 09:33:15 -05:00
Ray Speth
131ac1c421 Distinguish between rate units and units in rate parameterization
These differ specifically in the case of sticking reactions, where the
rate coefficient has units like m^3/kmol/s, depending on the reactant
orders while the sticking coefficient itself is dimensionless.
2023-04-18 09:33:15 -05:00
Ray Speth
20977ef95f [Test] Avoid modifying shared Solution object 2023-04-18 09:33:15 -05:00
Ray Speth
5edba4e473 Add tests for rate coefficient units 2023-04-18 09:33:15 -05:00
Ray Speth
2def1d89b3 Fix setting of Reaction.rate_units 2023-04-18 09:33:15 -05:00
Ray Speth
ee0d7dd3d5 Fix calculateRateCoeffUnits for falloff reactions
The forward rate constants for falloff and chemically activated reactions
already incorporate the third-body dependency, so the units should only
reflect the explicit reactants. This was being compensated for when
setting the units of the high/low pressure rate expressions, so it did
not affect any results.
2023-04-18 09:33:15 -05:00
Ray Speth
b676438d1d Include AnyMap in Python docs 2023-04-18 09:33:15 -05:00
Ray Speth
22ddb168fd [Python] Add basic serialization support for ExtensibleRate 2023-04-18 09:33:15 -05:00
Ray Speth
6de0d02de0 Centralize serialization of ReactionRate 'type' attribute 2023-04-18 09:33:15 -05:00