Working with SIMA

SIMA’s graphical user interface is easy to model with, but it is slow for repetitive tasks and for large systems with many similar components. SIMAPy, together with SIMA’s JSON export and import and the SIMA Runtime Engine (SRE), makes these scriptable.

1. JSON export

Every SIMA model can be represented in JSON.

To export a model, right-click it in the navigator:

Context menu of a supernode in the navigator

and select Export > JSON model export:

JSON export wizard

The result can be inspected and edited in a text editor.

supernode.json
{
    "name" : "RiserAnchor",
    "type" : "sima/riflex/SuperNode",
    "constraint" : "FIXED_PRESCRIBED",
    "automaticInitialPosition" : false,
    "xConstraint" : "FIXED",
    "yConstraint" : "FIXED",
    "zConstraint" : "FIXED",
    "rxConstraint" : "FIXED",
    "ryConstraint" : "FIXED",
    "rzConstraint" : "FIXED",
    "xInitial" : 0.0,
    "yInitial" : 0.0,
    "zInitial" : -50.0,
    "xStatic" : 0.0,
    "yStatic" : 0.0,
    "zStatic" : -100.0
}

The JSON file is backwards compatible: later versions of SIMA read it.

2. Python export

A model can also be exported as Python code that recreates it when run. Right-click the supernode and select Export > Python model export:

Python export in the context menu
supernode.py
import simapy.sima.riflex as riflex
riseranchor = riflex.SuperNode()
riseranchor.name = "RiserAnchor"
riseranchor.xConstraint = riflex.BoundaryCondition.FIXED
riseranchor.yConstraint = riflex.BoundaryCondition.FIXED
riseranchor.zConstraint = riflex.BoundaryCondition.FIXED
riseranchor.rxConstraint = riflex.BoundaryCondition.FIXED
riseranchor.ryConstraint = riflex.BoundaryCondition.FIXED
riseranchor.rzConstraint = riflex.BoundaryCondition.FIXED
riseranchor.zInitial = -50.0
riseranchor.zStatic = -100.0
riseranchor.rotation = -90.0

JSON and Python export work at any level in the navigator:

  • a single model element

  • several model elements (Ctrl-click, or a folder)

  • a whole task

3. JSON import in SIMAPy

A JSON file exported from SIMA can be read in Python. This script reads the supernode, makes several copies of it and writes them back to JSON for SIMA to import:

import numpy as np
from simapy.sima.riflex.supernode import SuperNode
from simapy.sima_reader import SIMAReader
from simapy.sima_writer import SIMAWriter
#SIMAReader will read the JSON file and return a list of Python objects
reader = SIMAReader()
contents = reader.read('supernode.json')
base_sn: SuperNode = contents[0]
supernodes = []
for i, x in enumerate(np.linspace(0.0, 10.0, 6)):
    # Copy imported supernode as starting point
    sn = base_sn.copy()
    # Adjust static position and name
    sn.xStatic = x
    sn.name = f'Anchor{i}'
    supernodes.append(sn)
# SIMAWriter will write the list of Python objects to a JSON file
writer = SIMAWriter()
writer.write(supernodes, 'supernodes.json')

To import the result, select the parent slender system in the RIFLEX task, right-click it and select Import > Import from JSON:

JSON import wizard

The imported supernodes:

Six imported supernodes in the 3D view

3.1. JSON and Python compatibility

  • SIMA migrates JSON files from earlier versions when it imports them. SIMAPy does not: it reads only JSON written by the SIMA version it matches.

  • Python code is not migrated. Code written for one SIMAPy version mostly works with the next, but attributes the data model removed or renamed must be changed by hand.

  • Because SIMA migrates the JSON, a script that writes JSON with an earlier SIMAPy still produces files that later versions of SIMA import.

4. SIMA data model

All SIMA models are based on an underlying data model, which says which attributes a model has. The supernode editor:

Supernode editor

To view the model, select Tools > Advanced > Show SIMA datamodel:

Data model view of the supernode

The SIMAPy classes have the same names and attributes.

5. SIMA Runtime Engine

The SIMA Runtime Engine (SRE) is SIMA without the user interface. It runs commands in batch, such as running a workflow or importing and exporting files. sre.exe is in the same installation folder as sima.exe.

sre.exe --help all lists the available commands:

Output of sre.exe --help all

sre.exe --help <command> shows the help for one command.

5.1. SIMA batch commands

To create batch commands in SIMA, select Tools > Advanced > Run SIMA batch command. The view runs the commands in the current workspace, and exports them to the clipboard or to a file that can be run itself.

SIMA batch command view

5.2. Run SRE from SIMAPy

run_condition imports the task, runs the condition and reads the results back, so the commands need not be written by hand:

from pathlib import Path
from simapy.sre import SIMA

sima = SIMA()          # or SIMA(exe=...) if SRE_EXE is not set
res = sima.run_condition(
    ".",
    stask=Path("riflex_task.json"),
    task="Simple_Flexible_Riser",
    condition="Initial",
    run_type="dynamic",
    variables={"hs": 3, "tp": 5},
)

run_workflow does the same for a workflow, but returns nothing. Open the file the workflow’s output node writes with open_results:

from simapy.results import open_results

sima.run_workflow(".", task="WorkflowTask", workflow="outer",
                  stask=Path("simple_workflow_run.stask"))
res = open_results("out.json")

For anything neither call covers, such as a storage root, pass the commands to sima.run:

storage = Path("storage").absolute()
sima.run(".", [
    "--storageroot", "task=ExternalStorage", f"root={storage}",
    "--run", "task=WorkflowTask", "workflow=workflow", "input=scale=2.0",
])

6. Plot the results

res.run is the condition, as SIMA’s post processor shows it. Signals are reached by the path SIMA shows them under, and the values are numpy arrays:

import matplotlib.pyplot as plt

fmax = res.run.signal("Dynamic/RiserLine/Force envelope curve/F-MAX")

plt.figure(figsize=(10, 5))
plt.plot(fmax.x, fmax.y, marker="o")
plt.title(fmax.name)
plt.xlabel(f"Distance along the line [{fmax.xunit}]")
plt.ylabel(f"{fmax.name} [{fmax.unit}]")
plt.tight_layout()
plt.savefig("fmax.png")

Values are in SI base units, and the axis labels take the units from the signal. Reading results covers the rest.

Maximum force along the riser