Equation

Equations governing the behavior of the objects in the model and their interactions are defined in classes extending the numerous.multiphysics.Equation. Once created an equation object can easily be added to any item or subsystem. To define an equation two things are needed:

  • Describe the variables needed for the equation
  • Define a function that implements the equation and decorate it with the @equation decorator

Here we will describe how to create an equation object using numerous simulation engine.

Creating variable description

We start by stating a description that will be used to create a set of numerous.engine.Variable needed for out equation. In the constructor of the equation we can use add methods for this.

class Bouncing(Equation):
    def __init__(self, g=9.82, f_loss=5, x=1, y=0):
        super().__init__(tag='bouncing_eq')
        self.add_constant('g', g)
        self.add_constant('f_loss', f_loss)
        self.add_state('x', x)
        self.add_state('y', y)
        self.add_parameter('direction', 1)

There are 3 types of variables that can be added in such way: 1. Constant. 2. Parameter. 3. State. Adding state will although create a derivative that will be used during the solver steps. Each method requires a name of the variable and its initial value. Variable name should be unique inside the equation.

Note that some of this types are incompatible with direct assignments of values after creation. If assignments are incompatible error will be raised - like assign to STATE or CONSTANT.

Writing equations

Inside the numerous.multiphysics.Equation one or more functions can be defined and decorated with @equation. This decorator tells the numerous engine that it needs to execute this function and let it operate on the equations scope in each solver step.

@equation
def eval(self, scope):
    scope.x_dot = scope.y
    scope.y_dot = -scope.g

numerous.engine.Scope is a collection of all variables registered in the equation as well as global variables. it is possible to access variables scope.<Local Variable Name> for globals scope.globals.<Global Variable Name>.

Adding equations to a namespace is discussed in Item.