Skip to content

Commit

Permalink
[Doc] Add docstrings and versionadded for Units
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwweber authored and ischoegl committed May 30, 2022
1 parent b3a79a3 commit aef1843
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def ndim(self) -> int:
def shape(self) -> tuple[int, ...]:
"""The shape of the SolutionArray.
.. versionadded: 3.0
.. versionadded:: 3.0
:return: A tuple of integers with the number of elements in each dimension.
"""
Expand All @@ -679,7 +679,7 @@ def shape(self) -> tuple[int, ...]:
def size(self) -> int:
"""The number of elements in the SolutionArray.
.. versionadded: 3.0
.. versionadded:: 3.0
"""
return np.prod(self.shape)

Expand Down
4 changes: 2 additions & 2 deletions interfaces/cython/cantera/thermo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@ cdef class ThermoPhase(_SolutionBase):
:param basis:
Determines if ``fuel`` and ``oxidizer`` are given in mole
fractions (``basis='mole'``) or mass fractions (``basis='mass'``)
:param: diluent:
:param diluent:
Optional parameter. Required if dilution is used. Specifies the composition
of the diluent in mole/mass fractions as a string, array or dict
:param: fraction:
:param fraction:
Optional parameter. Dilutes the fuel/oxidizer mixture with the diluent
according to ``fraction``. Fraction can refer to the fraction of diluent in
the mixture (for example ``fraction="diluent:0.7`` will create a mixture
Expand Down
21 changes: 15 additions & 6 deletions interfaces/cython/cantera/units.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,29 @@ cdef class Units:
if name:
self.units = CxxUnits(stringify(name), True)

def __repr__(self):
return f"<Units({pystr(self.units.str())}) at {id(self):0x}>"
def __repr__(self) -> str:
return f"<Units({str(self)}) at {id(self):0x}>"

def __str__(self):
def __str__(self) -> str:
return pystr(self.units.str())

def dimension(self, primary):
def dimension(self, primary: str) -> float:
"""The dimension of the given unit component.

.. versionadded:: 3.0

:param primary:
A string with the desired unit component. One of ``"mass"``,
``"length"``, ``"time"``, ``"temperature"``, ``"current"``, or
``"quantity"``.
"""
return self.units.dimension(stringify(primary))

@property
def dimensions(self) -> Dict[str, str]:
"""A dictionary of the primary unit components to their dimensions.

.. versionadded: 3.0
.. versionadded:: 3.0
"""
dimensions = ("mass", "length", "time", "temperature", "current", "quantity")
return {d: self.dimension(d) for d in dimensions}
Expand All @@ -41,7 +50,7 @@ cdef class Units:
def factor(self) -> float:
"""The factor required to convert from this unit to Cantera's base units.

.. versionadded: 3.0
.. versionadded:: 3.0
"""
return self.units.factor()

Expand Down

0 comments on commit aef1843

Please sign in to comment.