Skip to content
Clément de La Bourdonnaye edited this page Aug 28, 2020 · 2 revisions

Physics is making use of iets3.opensource simpleTypes, which include numeric, boolean and string types with their literal. These types were extended with dimensions and vectors to be used in a physical context.

Using simpleTypes

simpleTypes define some really simple types :

  • boolean : define a boolean
  • string : define a string

On the numerical part, things might get tricky:

  • The main type to use in general cases is real
  • Number literals and expression involving them are given a number type, with a range and a precision. If you want to see if a type is some kind of number, use real, number would be for checking for specific ranges and precisions (and wont do miracle for expressions typed as plain real).
  • If a number literal matches a integer, it's number type would have for supertype int (usefull to check for integer values)
  • Both number and int are subtypes of real

Dimensions

Note: a unit system is already implemented in iets3.opensource typetags.units language. This unit system is different on some aspects :

  • it does not make use of already implemented typetags (too restrictive for this purpose)
  • conversion between units can only be done by a linear factor
  • it type the expressions using dimensions instead of units (so you can add values of same dimensions)

Definition of new units and dimension

In the Physics languages, the dimensions and units defined are located in the Physics.types language (accessory model units > BaseUnits).

Simple dimension

A simple dimension is a named concept, containing :

  • A default unit : with a name and a description, it will be the unit used on runtime and as a reference to convert from and to derived units.
  • Zero or more derived units : defined the same way as default unit, but require to provide a conversion ratio to the default unit.

Tips: as of the time of writing, you can switch the unit the ratio will be applied on (1 m = ratio km or 1 km = ratio m) using the contextual button when focusing the derived unit

dimension length 
  default: unit m ( metre ) 
  units: 
    unit km ( kilometre ) as 1 km = 1000 m
    unit cm ( centimetre ) as 1 m = 100 cm

Composite dimension

A composite is the same as a simple dimension, with few extra definitions to add :

  • The composition of the dimensions : which dimensions are combine in order to obtain the current dimension
  • The conversion ratio between the default unit, and the composition of the default units of the composing dimensions (1 kmh = 0.278 m*s^-1)

Upon runtime, there is no trace of those composite dimensions, since they all are converted back to their composing dimensions default unit.

For example, 1 kmh2 (kilometer per hour squared) could be reduced as : 1 kmh2 > 1 * 3600 kmh * s^-1 > 0.278 * 3600 m*s^-2

composite dimension energy 
  made of mass * length^2 * time^-2 
  default: unit J ( joule ) 
  units: 
    << ... >> 
  conversion: 1 kg*m^2*s^-2 = 1 J

Using dimensions

Dimensions in expressions

Using dimensions is a two step process :

  • Write / find a number literal (might not work on some user defined constants like PI)
  • Insert the unit right after the literal

You should get an expression looking like this : [3 m]. The brackets are used to separate the value inside and the units and the external expressions (to avoid multiplying the literal inside the unit expression instead of multiplying the whole expression).

From this point you can use the whole expression with usual operations (like +, -, /... outside brackets).

You can also specify a composite unit by multiplying the internal unit by another one, or specify a power to apply on the unit using the key ^. If you want to divide a unit by another, you can currently specify a negative power, like in m*s^-2 for acceleration.

Combination with other expressions

You can combine multiple dimensional values together as long as their dimension fits, like [3 mps] + [4 km] / [1 century] + [1 mm * s^-2] * [3 day].

You may also use a dimension expression with every expression typed as zero without any errors being raised : [3 mps] + 0 + ([1000 m] - [1 km]) + [5 day] * 0.

Dimensions in types

To add a dimension to a type, you can either:

  • Define your base type, then press [ on the right of your type, this should wrap it with a dimension type, in which you can specify dimensions.
  • Insert a dimension type, fill the base type and the dimensions.

Troubleshooting

In cannot add dimensions to my types

It might be either a caching issues (restarting MPS might save this one), a dependencies issue (make sure you have included Physics.dimensions and the model containing the unit definitions, Physics.units for Physics).

Vectors

Vectors, or coordinates, are another important type of the Physics language defining 3D coordinates. It is basically a type wrapping a numeric type.

The type of a given coordinate is computed according to its inner type (compatible with dimensions), and some operations are available between vectors and other expression (vectors and scalars).

Expressions

To define a vector, you may use one of the provided concepts, such as cartesian coordinates or spherical for example. All the angles must be defined with angle dimension (radians, degrees) but you may use any dimension for the component part (r, distance, x, y, z...). The type of the component will reflect on the vector type.

cartesian(x = [3 mm], y = [4 m], z = 0) / [30 s] + cylindrical(r = [3 mps], theta = [4 deg], z = [1 mps])

Note: zero is accepted as a component no matter what dimension the other components has, a vector full of 0 would fit with any expected dimension.

Types

The edition of a vector type is not really complicated, you first need to insert a vector type, then insert its nested component type. Here are some types you may find or use for vectors :

  • vector<real>
  • vector<real[speed*time^-1]>
  • vector<number[0|0]>
  • vector<int>

Clone this wiki locally