open-simulation-platform / cosim-cli

Command-line interface for libcosim
https://open-simulation-platform.github.io/cosim
Mozilla Public License 2.0
10 stars 4 forks source link

New subcommand: run-single #4

Closed kyllingstad closed 5 years ago

kyllingstad commented 5 years ago

This builds on the work in PR #3 and adds a new subcommand: run-single. It works pretty much as specified in Confluence, but with slightly more comprehensive documentation printed by help.

Some of its implementation is shared with run, so I've extracted those things into a separate header and based this PR on #3 instead of #1. ~I'll retarget it on master once #3 is merged.~

Here is some example output:

> cse help run-single
NAME
  cse run-single - Runs a simulation with a single subsimulator

SYNOPSIS
  cse run-single <uri_or_path> <initial_value...> [options...]

DESCRIPTION
  This command runs a simulation consisting of a single subsimulator.  This is
  mainly meant for testing and debugging.  The simulator is therefore run directly,
  without the overhead and extra machinery of a full co-simulation.

  The model to simulate can be specified with a URI, or, if it's a local FMU, by its
  path.  Using a path is equivalent to using a 'file' URI.

  Initial variable values may be specified after the model URI/path, by supplying a
  list of name=value pairs as individual command-line arguments.

  The simulation can be synchronised with real time by using the '--real-time'
  option, optionally specifying a target real-time factor (RTF).  The RTF is defined
  as 'elapsed logical time divided by elapsed real time in seconds'.  In other
  words:

  * RTF < 1 means slower than real time
  * RTF = 1 means real time
  * RTF > 1 means faster than real time

  Whether the target RTF can actually be reached depends on the simulation setup,
  most importantly the models being simulated, and the machine(s) on which the
  simulation is being executed.

  If '--real-time' is not specified, the default is to run as fast as possible,
  unconstrained by real time.

PARAMETERS
  uri_or_path           A model URI or FMU path.
  initial_value         Initial values for model variables, on the form
                        <name>=<value>.  Allowed values for boolean variables are
                        'true' or 'false'.

OPTIONS
  -b [ --begin-time ] arg (=0)            The logical time at which the simulation
                                          should start.
  -d [ --duration ] arg (=1)              The duration of the simulation, in
                                          logical time.  Excludes -e/--end-time.
  -e [ --end-time ] arg                   The logical end time of the simulation.
                                          Excludes -d/--duration.
  --real-time [=target_rtf(=1)]           Enables real-time-synchronised
                                          simulations.  A target RTF may optionally
                                          be specified, with a default value of 1.
  --output-file arg (=./model-output.csv) The file to which simulation results
                                          should be written.
  -s [ --step-size ] arg (=0.01)          The co-simulation step size.
  --help                                  Display a help message and exit.
  --version                               Display program version information and
                                          exit.
> cse  run-single -b 2 -d 2 cse-core/test/data/fmi1/identity.fmu realIn=3.14 stringIn="hello world"
10% complete, t=2.200000
20% complete, t=2.400000
30% complete, t=2.600000
40% complete, t=2.800000
50% complete, t=3.000000
60% complete, t=3.200000
70% complete, t=3.400000
80% complete, t=3.600000
90% complete, t=3.800000
100% complete, t=4.000000
> head -n4 model-output.csv
Time,realIn [0 real input],realOut [0 real output],integerIn [0 integer input],integerOut [0 integer output],booleanIn [0 boolean input],booleanOut [0 boolean output],stringIn [0 string input],stringOut [0 string output]
2.000000,3.14,3.14,0,0,false,false,hello world,hello world
2.010000,3.14,3.14,0,0,false,false,hello world,hello world
2.020000,3.14,3.14,0,0,false,false,hello world,hello world
kyllingstad commented 5 years ago

Warning: I've rebased this branch on master to resolve conflicts. (I know I said I wouldn't do that anymore, but due to the dependency of #4 on #3 it was the cleanest way.)