Introduction¶
This first tutorial aims to describe basic usage of the main classes of nodimo:
We start by importing them:
[2]:
from nodimo import *
Quantity¶
Quantity or Q is the class used to create a quantity.
To create a force, specify its name (symbol) as a string and dimensions as keyword arguments. In the definition below, M, L and T represent the dimensions Mass, Length and Time, respectively
[3]:
F = Quantity('F', M=1, L=1, T=-2)
To create a dimensionless quantity, just give it the name:
[4]:
a = Q('a')
To display greek letters in the expressions, write the english representation as the name of the quantity:
[5]:
th = Quantity('theta')
th
[5]:
Important attributes of objects of this class to mentioned right now are dimension and is_dimensionless:
[6]:
F.dimension
[6]:
[7]:
a.is_dimensionless
[7]:
True
The other two attributes (is_dependent and is_scaling) will make sense during the creation of relations and models.
Power¶
Power is the class used to create the power of a quantity, which can also be created using the ** operator.
For example:
[8]:
a = Quantity('a', A=1, B=-2, C=1/2)
b = Power(a, 2)
b
[8]:
The dimension of this power quantity is:
[9]:
b.dimension
[9]:
Product¶
Product is the class used to create the product of a quantity, which can also be created using the * operator.
For example, to create the Reynold’s number:
[10]:
rho = Quantity('rho', M=1, L=-3)
V = Quantity('V', L=1, T=-1)
D = Quantity('D', L=1)
mu = Quantity('mu', M=1, L=-1, T=-1)
Re = Product(rho, V, D, mu**-1)
Re
[10]:
As expected, this product of quantities is dimensionless:
[11]:
Re.is_dimensionless
[11]:
True
DimensionalMatrix¶
DimensionalMatrix is the class used to create a dimensional matrix.
Using the quantities of the previous topic, we can build the dimensional matrix by:
[12]:
dmatrix = DimensionalMatrix(rho, V, D, mu)
dmatrix
[12]:
An important property of the dimensional matrix is the rank:
[13]:
dmatrix.rank
[13]:
3
Relation¶
Relation is the class used to create a relation between quantities. A relation must have one dependent quantity.
As an example, let’s build a relation between force, mass and acceleration, using the force as the dependent quantity:
[14]:
F = Quantity('F', M=1, L=1, T=-2, dependent=True)
m = Quantity('m', M=1)
a = Quantity('a', L=1, T=-2)
rel = Relation(F, m, a)
rel
[14]:
Model¶
The Model class is mainly used to create relations of dimensionless quantities from a given group of dimensional quantities. Like the relation, a model must have a dependent quantity. In addition, some of these quantities must have the scaling property, which means they can be used as transformation parameters to create the new group of dimensionless quantities. The number of scaling quantities must match the rank of the dimensional matrix formed by all the quantities that constitute the
model.
For the following example, generic quantities with generic dimensions are used:
[15]:
v1 = Q('v_1', A=1, B=0, C=-1, dependent=True)
v2 = Q('v_2', B=3, C=1)
v3 = Q('v_3', A=2, C=-2, scaling=True)
v4 = Q('v_4', A=0, B=-2, C=1, scaling=True)
v5 = Q('v_5', B=-3, C=4, scaling=True)
v6 = Q('v_6', A=4, B=-1, C=2)
model = Model(v1, v2, v3, v4, v5, v6)
To display not just the dimensional relation, but the newly created relation of dimensionless quantities, use the show method:
[16]:
model.show()
Each created relation is linked to a group of scaling quantities and stored in a dictionary.
To verify that all quantities in this new relation are dimensionless:
[17]:
for rel in model.relations.values():
for qty in rel:
assert qty.is_dimensionless
This completes a basic application of the main classes of nodimo. For more information about each one of them, consult the API documentation. For more applications, check the next tutorials.