callOpenModelica: Call OpenModelica to simulate a model

Description Usage Arguments Value See Also Examples

View source: R/callOpenModelica.R

Description

Call OpenModelica to simulate a model. Includes the facility to run multiple simulations for different parameter values.

Usage

1
2
callOpenModelica(modelName, model, script=defaultScript(modelName),
values=NULL, omcCommand="omc",omcArgs="",omcModels="Modelica")

Arguments

modelName

a string for the name of the model to be simulated. [required]

model

a string representation of the model to be simulated. [required]

script

either (i) a string representation of the simulation script (see defaultScript) or (ii) a list with a component for the "prefix" for the start of the script and a component for "each" simulation for different parameter values (see defaultScriptWithParameter).

values

vector of numeric values to be passed for the parameter.

omcCommand

string representing the command to call omc.

omcArgs

string representing the arguments to omc that precedes the script and library arguments.

omcModels

string representing the other Modelica libraries required.

Value

A data.frame object from the simulation output with column names "time" and other columns as per the simulation.

See Also

See Also defaultScript, defaultScriptWithParameter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## Not run: 
model <- "
model CalledbyR
  Real x(start=1.0),y(start=2.0);
  parameter Real b = 2.0;
equation
  der(x) = -b*y;
  der(y) = x;
end CalledbyR;"

out <- callOpenModelica("CalledbyR", model)
plot(y~time, data=out, type="l")

out <- callOpenModelica("CalledbyR", model, script=defaultScript("CalledbyR",stopTime=10))
plot(y~time, data=out, type="l")

out <-  callOpenModelica("CalledbyR",
                     model,
                     script=defaultScriptWithParameter("CalledbyR", "b", stopTime=10),
                     values=c(0.5,1,2))
if (require(ggplot2))
    qplot(x=time, y=y, data=transform(out, value=factor(value)), color=value, geom="line")


## End(Not run)

mclements/ROpenModelica documentation built on May 22, 2019, 3:06 p.m.