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, lengthLand timeT, a forceFcan be defined as:>>> from nodimo import Quantity >>> F = Quantity('F', M=1, L=1, T=-2)
To define a dimensionless quantity
Ais 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, lengthLand timeT.Quantities: drag force
Fd, fluid densityrho, velocityV, reference areaA,halfand drag coefficientCd.In this example, the
reduceparameter set toFalseis 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)