Modelica does not require causality to be assigned in equations. This means that a Modelica solver, such as Dymola, must be able to solve an equation independent on which of the variables are inputs and which are unknowns. To test this in Dymola an example based on flying a spaceship, as is done in the book Project Hail Mary, has been created.
Simple example
Instead of diving into complex relativity equations, let’s begin with a simple example:
y2 = 1 – y1
In the equation above y2 = 1 – y1. So, if y1 were the input to the model then this equation could be used directly to solve y2, however if y2 was the input then y1 would be calculated using the same equation.
Balanced systems
For a system to be “balanced” there must be as many equations as unknowns.
So, in this example the input u1 will be assigned to y1 and other times u2 will be assigned to y2. This introduces a problem as both u1 and u2 must be able to be inputs. So, how is the system balanced as there appear to be too many knowns and not enough unknowns?
A solution is to introduce a dummy unknown variable, so when y1 is set to the input value then y2 will be set to the unknown variable and when y2 is set to the input then y1 will be set to the unknown variable.
A simple model where this is implemented is in Figure 1:

In Figure 1, when switch is true then y1 is set to u1, otherwise y2 is set to the unknown variable dummy and vice versa when switch is false to keep the system balanced so there is one unkown (i.e. dummy) and one equation (i.e. y2 = 1 – y1).
Spaceship equations
In the story Project Hail Mary the spaceship travels to Tau Ceti with an acceleration equal to 1.5*g (approximately 14.7 m/s2), arriving at Tau Ceti with a low velocity by accelerating for half of the trip and decelerating for the other half.
Relativistic equations are necessary for spaceships traveling at significant fractions of the speed of light, as Newtonian mechanics becomes inaccurate at such speeds. The equations used were obtained from The Relativistic Rocket.
Of importance in the story is the amount of travel time it will take to get to Tau Ceti, the amount of time measured on earth and later in the story the amount of time to travel to other locations. So, a space travel calculator is required.
An equation with the relationship between distance and travel time is:

In Equation 1, c is the speed of light and a is the acceleration. This equation is used with the if statement in Figure 1 to switch which output is being calculated from Equation 1.
The space travel calculator
A space travel calculator was created using Equation 1 to calculate either the distance traveled or the elapsed time in the ship. The model is in Figure 2.

In the model above, the squares on the left are buttons that can be toggled, to increase or decrease the distance traveled or increase or decrease the time in the ship. The acceleration value a is a parameter set in the rocket component. The active component determines if the distance or the time in the ship are currently an input. The value of the input is calculated by integrating up or down depending on which buttons are pressed, this is done in the integators component. The rocket component contains the relativistic equation.
An example of the animation being used is in Animation 1:
In Animation 1, we see that this rocket would take about 2.8 years (travel time) to go 4.3 light years; this is the approximate distance to Proxima Centauri. Then it takes about 3.9 years (travel time) to go 11.8 light years; this is the approximate distance to Tau Ceti.
With this rocket it would take less than 14 years (travel time) to go 26000 light years; this is the approximate distance to the super massive black hole in the center of the Milky Way. However, the time measured from earth would be about 26000 years.
Discussion
This fantastical example demonstrates how an equation can be used in an acausal way in Modelica. In this example a “hidden variable” (i.e. dummy) is used to balance the system.
Using an equation in an acausal way can introduce non-linear equations into the system. In the space travel example, it would be better to calculate y1 and y2 within the if block in Figure 1. For example, the rocket component (in Figure 2) could be re-written as:

In some cases, it may be difficult or impossible to calculate the inverse of the equation so re-writing the equations as in Figure 3 may not be a good option.
To obtain the code from this post please click here
Written by: Garron Fish – Chief Engineer
Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion