# MV-7000: Model Differential Equations Using MotionView and MotionSolve

In this tutorial, you will build a model and apply solver variables and differential equations before running the model.

Differential equations are very versatile and have many different applications in modeling multibody systems. User-defined dynamic states are commonly used to create low pass filters, apply time lags to signals, model simple feedback loops, and integrate signals. The signal may be used to:
• define forces.
• used as independent variables for interpolating through splines or curves.
• used as input signals for generic control modeling elements.
• define program output signals.

The MotionSolve expressions and user-subroutines allow you to define fairly complex user-defined dynamic states.

The expression type is used when the algorithm defining the differential equation is simple enough to be expressed as a simple formula. In many situations, the dynamic state is governed by substantial logic and data manipulation. In such cases, it is preferable to use a programming language to define the value of a differential equation. The user-defined subroutine, DIFSUB, allows you to accomplish this.

## Build and Analyze a Simplified Model

In the following exercise, you will build and analyze a simplified model of a pressure vessel blown down using MotionView and MotionSolve. The following steps outline the process.

1. Specify the following parameters (state variables) as solver variables:
$\begin{array}{l}k=1.4\\ A=0.047\\ V=18.3\\ \frac{{C}_{p}}{R}=3.5\end{array}$
2. Model the following differential equations:
(1) $\frac{-{\stackrel{˙}{P}}_{T}}{{P}_{T}}+\frac{{C}_{P}}{R}\frac{{\stackrel{˙}{T}}_{T}}{{T}_{T}}=0$ (2) $\frac{{\stackrel{˙}{P}}_{T}}{{P}_{T}}-\frac{{\stackrel{˙}{T}}_{T}}{{T}_{T}}-\frac{{\stackrel{˙}{m}}_{T}}{{m}_{T}}=0$ (3) ${\stackrel{˙}{m}}_{T}=-A\sqrt{\frac{k{m}_{T}{P}_{T}}{V}}{\left(\frac{2}{k+1}\right)}^{\frac{k+1}{2\left(k-1\right)}}$

The three states of the system are PT, TT and mT.

3. Specify the initial conditions for the system as:
$\begin{array}{l}{P}_{T}\left(0\right)=2000\\ {T}_{T}\left(0\right)=560\\ m\left(0\right)=2.5602e-04\\ {\stackrel{˙}{P}}_{T}=-5.8875e+04\\ {\stackrel{˙}{T}}_{T}=-4.7100e+03\\ \stackrel{˙}{m}=-0.0054\end{array}$
4. Run the model in MotionSolve and post-process the results in HyperGraph.

A solver variable defines an explicit, algebraic state in MotionSolve. The algebraic state may be a function of the state of the system or any other solver variables that are defined. Recursive or implicit definitions are not allowed at this time.

Two types of solver variables are available. The first, and probably the most convenient, is the expression valued variable. The second is the user-subroutine valued variable.

The expression method is used when the algorithm defining the algebraic state is simple. In many situations, the algebraic state is governed by substantial logic and data manipulation. In those cases, it is preferable to use a programming language to define the value of a solver variable. The user-defined subroutine, VARSUB, enables you to do this.

Solver variables are quite versatile and have many different applications in modeling multibody systems. They are commonly used to create signals of interest in the simulation. The signal may then be used to define forces, independent variables for interpolation, inputs to generic control elements, and output signals.

MotionSolve expressions and user-subroutines allow for fairly complex algebraic states to be defined.

1. Launch a new session of MotionView.
2. From the Project Browser, right-click Model and select Add > Control Entity > Solver Variable (or right-click Solver Variables from the toolbar).
The Add Solver Variable dialog is displayed.
3. In the Label field, assign the label K to the solver variable.
4. In the Variable field, assign a variable name to the solver variable or leave the default name.
5. Click OK.
6. From the Properties tab, under Type, select Linear and enter a value of 1.4 in the field.
7. Repeat steps 1 through 6 to create the three remaining solver variables:
(4) $\begin{array}{l}A=0.047\\ V=18.3\\ \frac{{C}_{p}}{R}=3.5\end{array}$

## Model Differential Equations

1. From the Project Browser, right-click Model and select Add General MDL Entity > Solver Differential Equation (or right-click Solver Differential Equation, $\frac{\partial }{\partial t}$ from the toolbar.
The Add SolverDiff dialog is displayed.
2. In the Label field, assign a label to the solver diff or leave the default label.
3. In the Variable field, assign a variable name to the solver diff or leave the default name.
4. Click Apply twice.
5. Click OK.
Three solver differential equations will be created.

Next, you will model the first differential equation:

$\frac{-{\stackrel{˙}{P}}_{T}}{{P}_{T}}+\frac{{C}_{p}}{R}\frac{{\stackrel{˙}{T}}_{T}}{{T}_{T}}=0$

This is an implicit differential equation that has a constant ($\frac{{C}_{p}}{R}$). The initial condition of the differential equation (IC) and its first derivative (IC dot) are known (given).

1. Select SolverDiff 0.
2. From the Properties tab, select Implicit and specify IC and IC dot as 2000 and -58875, respectively.
3. Select the type as Expression.
4. To access the expression builder, click in the text field and select F(x) from the trio of buttons at the top of the panel.
This will display the Expression Builder. In this dialog, you can enter expressions in text boxes without extensive typing and memorization. It can be used to construct mathematical expressions.
5. Populate the expression as shown in the image below:
-DIF1 ({diff_0.id})/DIF({diff_0.id})+{sv_3.value.lin}*DIF1({diff_1.id})/DIF({diff_1.id})
6. Optional: You can use the model tree to access entity variables in your model. As you can see for the above expression, to refer to the ID of the differential equation, browse for it from the list-tree on the Properties tab and select the ID. Click Apply.
The name of the selected entity or property is inserted into the expression.
7. Click OK.
The new expression is displayed in the text box on the panel.
8. Repeat steps 6 through 12 to modify the remaining two differential equations:
$\frac{{\stackrel{˙}{P}}_{T}}{{P}_{T}}-\frac{{\stackrel{˙}{T}}_{T}}{{T}_{T}}-\frac{{\stackrel{˙}{m}}_{T}}{{m}_{T}}=0$

Implicit: Yes

IC: 560

IC_dot: -4710

Value Expression:
DIF1({diff_0.id})/DIF({diff_0.id})-DIF1({diff_1.id})/DIF({diff_1.id})-DIF1({diff_2.id})/DIF({diff_2.id})

${\stackrel{˙}{m}}_{T}=-A\sqrt{\frac{k{m}_{T}{P}_{T}}{V}}{\left(\frac{2}{k+1}\right)}^{\frac{k+1}{2\left(k-1\right)}}$

Implicit: No

IC: 0.000256

Value Expression:
-{sv_1.value.lin} *sqrt(abs({sv_0.value.lin}*DIF({diff_2.id})*DIF({diff_0.id}) /{sv_2.value.lin}))*0.5787

## Run the Model in MotionSolve

1. Click Run on the toolbar.
The Run panel is displayed.
2. Specify the values as shown below:
3. From the Main tab, choose Save and run current model.
4. Click on the browser icon and specify a filename of your choice.
5. Click Save.
6. Click Check Model to check the model.
7. To run the model, click Run.
The solver will get invoked here.
8. Post-process the results using HyperGraph.