Quantity

nodimo.quantity.Q[source]

alias of Quantity

class nodimo.quantity.Quantity(name: str, dependent: bool = False, scaling: bool = False, **dimensions: Number)[source]

Base class for quantities.

Most basic type of physical quantity, with attributes that are useful in describing its dimensional properties.

Parameters:
namestr

Name (symbol) to be used as the quantity representation.

dependentbool, default=False

If True, the quantity is considered dependent in a relation of quantities

scalingbool, default=False

If True, the quantity can be used as scaling parameter.

**dimensionsNumber

The dimensions of the quantity given as keyword arguments.

Attributes:
namestr

Name (symbol) used as the quantity representation.

dimensionDimension

The quantity dimension.

is_dependentbool

If True, the quantity is considered dependent in a relation of quantities

is_scalingbool

If True, the quantity can be used as scaling parameter.

is_dimensionlessbool

If True, the quantity is dimensionless.

Methods

reduce()

Turns an unreduced quantity into a reduced quantity.

Raises:
TypeError

If the quantity name is not a string.

ValueError

If the quantity name is invalid.

ValueError

If the quantity is set as both dependent and scaling.

ValueError

If the quantity is set as scaling, but with no dimensions.

Examples

Considering the dimensions mass M, length L and time T, a force F can be defined as:

>>> from nodimo import Quantity
>>> F = Quantity('F', M=1, L=1, T=-2)

To define a dimensionless quantity A is sufficient to provide just its name:

>>> A = Quantity('A')

To use a greek letter in symbolic expressions, just provide its english representation as the name of the quantity:

>>> a = Quantity('alpha')
class nodimo.quantity.Constant(value: str | Number)[source]

Dimensionless constant.

Constants are most commonly just dimensionless numbers. Here, they can be represented by letters, which are be provided as the value parameter. If the value is a string of characters, the constant is printed in bold on the screen to avoid confusion with instances of Quantity.

Constants were implemented to allow the creation of expressions that contain dimensionless numbers. In general, these numbers are only useful in the mathematical equations that represent the model. In Nodimo, constants are used only for aesthetic purposes, mainly in product of quantities.

Attributes:
dimension
is_dependent
is_dimensionless
is_scaling
name

Methods

reduce

Examples

  • Drag coefficient

Dimensions: mass M, length L and time T.

Quantities: drag force Fd, fluid density rho, velocity V, reference area A, half and drag coefficient Cd.

In this example, the reduce parameter set to False is important to keep the constant in the denominator of the expression.

>>> from nodimo import Quantity, Power, Product
>>> from nodimo.quantity import Constant
>>> Fd = Quantity('F_D', M=1, L=1, T=-2)
>>> rho = Quantity('rho', M=1, L=-3)
>>> V = Quantity('V', L=1, T=-1)
>>> A = Quantity('A', L=2)
>>> half = Constant(1/2)
>>> half_inv = Power(half, -1, reduce=False)
>>> Cd = Product(Fd, half_inv, rho**-1, V**-2, A**-1, reduce=False)
class nodimo.quantity.One(*args, **kwargs)[source]

Dimensionless one.

Attributes:
dimension
is_dependent
is_dimensionless
is_scaling
name

Methods

reduce