Book a Demo

Author Topic: Modelica Library integration with EA/SysML/SysPhS  (Read 19681 times)

fishy

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Modelica Library integration with EA/SysML/SysPhS
« on: November 20, 2025, 01:51:24 am »
Hi,
I am modeling a system that involves flows of multicomponent liquids.   I have managed to build and simulate simple models for single component fluid flow using the SysPhS library to generate blocks representing tanks, pipes, motors and pumps and SysMLSim Configurations to drive OpenModelica.
However, there is already a large library of active and passive components in the OpenModelica library.   I am trying to understand how to build blocks that can leverage that library, rather than re-create all the complex parametric models they contain from scratch in EA.   Really I just want SysML blocks that 'wrap' Modelica blocks, reproduce the properties/parameters and ports, but leave the underlying maths/parametrics to Modelica.
There are some simple examples on Sparx's website and YouTube showing how to use ModelicaBlocks from the SysPhS library as "pointers" Modelica Library items, but this looks at an electronics example using JK FlipFlops, and stops short of explaining how to setup all the constants, variables and ports defined on more sophisticated, non-electrical Library components, where some of the interfaces may be more complex than the templates available in the SysPhS library.   Has anyone done this, or can point me to a tutorial...?   I am particularly interested in Fluid components in the first instance.
Thanks,
« Last Edit: November 28, 2025, 02:27:51 am by fishy »
-Neil

fishy

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Modelica Library integration with EA/SysML/SysPhS
« Reply #1 on: November 28, 2025, 02:00:37 am »
An update on what I'm learning by experimentation:
Analogues of the Modelica block structures need to be set up in EA:   Blocks, contianing properties to represent Modelica parameters, and ports.
  • For blocks, stereotype them as ModelicaBlock and set the ModelicaBlock.Name property to the full classpath of the Modelica element you want to 'wrap'.   For example:  Modelica.Fluids.Pipes.StaticPipe for a block that calculates flow through a pipe
  • For properties, stereotype them as ModelicaParameter.   Use the ModelicaParameter.Name property to match the name of the parameter instance within the Modelica block - for example length or diameter as constant properties of the pipe.   That allows you to set a completely arbitrary name as the SysML parameter name if you want to - e.g. use d for diameter, or L for length.   If you don't use ModelicaParameter.Name, or don't apply the ModelicaParameter stereotyope, then the SysML name field must match the Modelica instance name exactly.
  • For ports, similar to parameters, use ModelicaPort and ModelicaPort.Name to match the interface name used by the Modelica block - e.g. port_a or port_b on a pipe.

One clear problem arises, which I can't see a workaround for:  If you stereotype a propery as both ModelicaParameter and PhSVariable, the SysMLSimConfiguration ignores this, and lists the property as a PhSConstant.   This means that the property then isn't available to choose as a plottable value, and as a consequence I can't see a way to extract varibles calculated by Modelica (e.g. flow through a pipe, or water level in a tank) and plot it from EA.

Another clear problem is the setting of typed Modelica properties via SysML parameters - e.g. specifying a Medium used in a flow calculation, such as water.   There isn't any easy way to do this as Modelica requires you to redeclare types that don't match the base class that a block is expecting.   For example, Modelica.Fluid.Vessels.OpenTank expects a Medium of type Modelica.Media.Interfaces.PartialMedum.   But the modelica object Modelica.Media.Water.StandardWater isn't of this type.   Setting Medium = 'redeclare package Medium = Modelica.Media.Water.StandardWater' as the EA initial value doesn't work - you still get the error:

Quote
Error: component tank1 contains the definition of a partial class Medium. (Expression: Modelica.Fluid.Vessels.OpenTank tank1(T_ambient=20,crossArea=1,height=3,p_ambient=101325) annotation(Documentation(info = ""), Placement(visible = true, transformation( origin = {-357, 30}, extent = {{0, 0}, { 152, 141}})));  ")"
Please redeclare it to any package compatible with Modelica.Media.Interfaces.PartialMedium.
« Last Edit: November 28, 2025, 02:29:59 am by fishy »
-Neil

fishy

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Modelica Library integration with EA/SysML/SysPhS
« Reply #2 on: January 16, 2026, 01:16:42 am »
One additional obstacle to widely leveraging the Modelica Standard Library is that (as of 17.1.1715) EA's Modelica code generation doesn't correctly declare multi-dimensional parameters - an issue described in this bug...

https://sparxsystems.com/forums/smf/index.php/topic,49209.0.html

...many Modelica Library functions and blocks rely on the passing of multi-dimensional structures.
-Neil