The ROpenFLUID package allows to use OpenFLUID within the GNU R environment. This package is available for OpenFLUID 1.7.2 and later versions. Only linux and windows systems are currently supported.
Prerequisites¶
- Have OpenFLUID 1.7.2 or later installed
- Download and install the R environment
- Install the RUnit package within the R environment. Open an R session and run the following command:
install.packages('RUnit')
Installation of the ROpenFLUID package¶
- Download the ROpenFLUID package corresponding to your OpenFLUID version
- Install the ROpenFLUID package within the R environment. Open an R session and run the following command:
install.packages('ROpenFLUID_x.x.x-x.tar.gz',repos=NULL)
in the previous command, replace x.x.x-x with the correct version number (e.g. 2.1.9-20190918)
Using OpenFLUID within R¶
- The ROpenFLUID package reference manual is available in the Manuals section.
- All OpenFLUID commands in R are prefixed by OpenFLUID. (''e.g. OpenFLUID.openDataset, OpenFLUID.runSimulation, ...'')
Examples¶
(The following commands are illustrated with the example "Primitives" delivered with OpenFLUID)
- Running a project as a black box. This command allows a low interaction level between R and OpenFLUID environnement, the pre- and post-processing of a simulation are performed without the ROpenFLUID package commands.
library("ROpenFLUID") # should be done only once
OpenFLUID.runProject("/path/to/openfluid/examples/Primitives")
- Opening an input dataset, running the simulation and visualising the temporal evolution of the variable "var1" of the unit "8" of class "unitsA"
ofsim = OpenFLUID.openDataset("/path/to/openfluid/examples/Primitives/IN")
OpenFLUID.setCurrentOutputDir("/path/to/openfluid/examples/Primitives/OUT")
OpenFLUID.addVariablesExportAsCSV(ofsim,"unitsA",8,"var1") # to export all variables of class "unitsA", do not specify either unit identifiers or variable names
OpenFLUID.runSimulation(ofsim)
var1A8 = OpenFLUID.loadResult(ofsim,"unitsA",8,"var1")
plot(var1A8$datetime,var1A8$var1,type="l")
- Modifying simulation default time step and running the simulation
OpenFLUID.setDefaultDeltaT(ofsim,1800)
OpenFLUID.runSimulation(ofsim)
- Modifying parameter "gmult" of the simulator "examples.primitives.unitsA.up" and running the simulation
gmult = as.numeric(OpenFLUID.getSimulatorParam(ofsim,"examples.primitives.unitsA.up","gmult")) # warning: the return type of this command is "character"
OpenFLUID.setSimulatorParam(ofsim,"examples.primitives.unitsA.up","gmult",0.5*gmult)
OpenFLUID.runSimulation(ofsim)
- Modifying attribute "inivar1" of the unit "8" of class "unitsA" and running the simulation
inivar1 = as.numeric(OpenFLUID.getAttribute(ofsim,"unitsA",8,"inivar1")) # warning: the return type of this command is "character"
OpenFLUID.setAttribute(ofsim,"unitsA",8,"inivar1",inivar1+1)
OpenFLUID.runSimulation(ofsim)