The HOPSAN simulation package has been developed at the division of Fluid- and Mechanical Engineering Systems, Linköping University, since 1977. It was developed from the onset for modelling, simulation and analysis of hydraulic systems. Over the years it was developed to a more general environment for system development. As a result it is now a package with a comprehensive library of models, and a set of powerful analysis tools. HOPSAN has been used extensively at several companies and in a range of thesis projects and is freely available.
A unique feature of HOPSAN is that it does not make use of a centralised solver. Rather, the component-
and subsystem models have embedded solvers and are connected through so called bi-lateral delay
lines. These lines correspond to physical components with wave propagation, such as pipes, rods, hoses and wires.
The lines provide numerical robustness and the possibility to use large time steps in simulation. This leads to high simulation performance that scales linearly to
the model size and have predictable and consistent numerical properties.
The high and predictable performance of HOPSAN makes it suitable for real-time applications and optimisation. The optimisation algorithms that have been
implemented in HOPSAN provide the possibility to optimise the behaviour of a system, subject to constraints. Optimisation can also be used for off-line
parameter estimation, where the algorithm compares the results from a simulation with a measurement and minimises the differences.
To perform simulation experiments in an efficient way there is a powerful command interpreter. This enables, for instance, automated simulation series for
parameter variation studies. There are also interesting post processing tools such as frequency analysis and the possibility to transfer data to Matlab.
Although a great deal of progress has been made in tools for defining system-level models for simulation, creating the components at the detailed equation level is
still a rather unsupported task. This has been addressed in the HOPSAN case through the use of Mathematica as a code generator for component models.
Finally, HOPSAN is equipped with a flexible interface towards other simulation environments. The complete command interpreter and thus most of the functionality
of HOPSAN is available through a messagepassing solution which makes it possible to, for instance, perform coupled simulation with ease.
The HOPSAN software has a graphical user interface in which component models can be combined into
system models, such as the pump servo in Fig. 1. Each component picture represents a Fortran subroutine. The
code for such a model can be generated from the component generator in Mathematica, or by hand. Subsystems
can also be created from a system model using the HOPSAN graphical user interface by combining existing
components. The latter approach is suitable for beginners and can be used for example to create complex
pressure-compensated pumps and valves from standard components. Since the generated components
have embedded solvers, they can be run at their own, and possibly with a different (smaller) time step than
the over all simulation loop. This leads to improved simulation performance compared to the case where
one time step is used for all component models. The picture for a component can be customized by providing a Windows Meta File (WMF).

The component models can be grouped arbitrarily into libraries, which are shown graphically as in Fig. 2. The standard library contains

After simulation, the results can be plotted as shown
in Fig. 3 using a dedicated post-processing utility. This application can be used to combine and compare the
simulation results of different models and simulation
generations and be used to plot Bode and Nyquist diagrams
for any model part of interest.

Although a great deal of progress has been made in tools for defining system-level models for simulation,
creating the components at the detailed equation level is still a rather unsupported task.Particularly in the case
where the models have embedded solvers, it may take considerable effort and skill to create even rather simple
component models. The advent of symbolic math programs represents a breakthrough in this area since
they can be used to transform an equation-based representation into a mathematical implementation of the
component in an automated fashion. The use of symbolic math packages finally allows for the implementation
of efficient numerically robust methods even for highly non-linear systems.
In case the user needs a new model not existing in the library, he/she can make use of a component model
creator. In HOPSAN this is a program in Mathematica, see Fig. 4. The model and its documentation are written
in an acausal form, just by writing down the equations needed, from which the generator delivers a working
model. As Mathematica makes use of symbolic algebra the code generated will be very robust. For more details,
see (Krus, 1996). Below is an excerpt from a model describing a pressure relief valve.

Once the model is tested it can be connected to the user component library as a special purpose model. If the model is considered to be of general interest it can
later on be included in the standard component library.
In a contact between two parts of a physical system,the "information" of flow and pressure, in the hydraulic case, flows continuously in time in both directions. If the two parts are separated by an element of a certain length in space, the information will still propagate continuously but with a time delay between the two ends determined by the speed of sound and the element length. In the hydraulic case, such an element could be a volume, as is illustrated in Fig. 5. In the figure, q(t) is the incoming flow, p(t) is pressure and c(t) is the information flow through the element. The indexes 1 and 2 indicate the two parts that are connected.

The time delays present in physical systems is exploited for simulation in the method of bilateral delay
lines, first described in (Auslander, 1968). The equations describing these lines are explored below and
brought into the context of HOPSAN, as was shown in (Krus et al, 1990).
If an infinite number of inductance and capacitance elements are connected in series, and the relation between
pressure and flow, in the hydraulic case, are derived, the following expressions are found.
The time it takes for information to travel from one end to the other is denoted T. The parameter Zc is T over C where C is the capacitance of the line, which in this case is volume over bulk modulus. Let us now denote the old information from node 1 with c2 and from node 2 with c1. These "waves" of information are shown in Fig. 5 and are expressed below.
So, if two components in HOPSAN are connected by such a delay line, the pressure and flow in one of
them can be computed given the pressure and flow from the other the time T earlier. The components have
been made decoupled without worsening the overall numerical convergence. This allows for parallel computation,
see (Jansson et al, 1991). Also, increasing the time step results in increased lengths of the delay lines
and thus larger inertias, rather than the exponentially increasing numerical error that is often the result in
coupled simulation.
In order to optimise the servo system in Fig. 6, an object function has to be defined. This can to a large
extent be done in the graphical user interface. In this case the servo is optimised for control accuracy, load
pressure oscillation and power consumption. In general the requirements of a position servo are such that it
must reach a reference position in a certain time and after that the position error should be small.

If both input- and output spectra is known, thetransfer function can be calculated as


In the frequency domain the output spectra can be written as a function of the transfer function G and the input spectrum U.




In this way open and closed loop transfer functions
can be calculated directly from simulated results. Some
restrictions should be noted. The transfer function is
valid in a strict sense, only if the system is linear, which
is usually not the case, therefore care must be taken
when interpreting the results. Nevertheless, this has
been proven to be a very useful tool since it does not
rely on a simplified linear model. Figure 8 shows a
simulation of the hydraulic servo in Fig. 6 with the
corresponding open and closed loop transfer functions.
More details on the integrated use of frequency analysis
in measurements and simulation is found in (Krus et al,
1986; Krus et al 1989).
Through Matlab it is possible to connect also to other application such as ADAMS, which was exploited
in the simulation of a complete wheel loader. The models are shown in Fig. 9. In that project, the
hydraulics system was simulated in HOPSAN, the driveline in Simulink and the chassis in ADAMS. The
models were connected by delay lines to improve the numerical properties of the simulation. Without the
delay lines, the simulation produced an increasing numerical error, but with them, a fast simulation with a
satisfactory error level was produced, as is discussed in (Larsson, 2003).


The Excel connection, which consists of a small Visual Basic macro in Excel, has been used to perform
coupled simulation with Working Model. This is a solution that works for simpler mechanisms where
interactivity is of value. In the example below, the valve position is controlled during simulation by the user from the interface in Working Model.
