Title: | Interface to Use the Modelling Framework 'SIMPLACE' |
---|---|
Description: | Interface to interact with the modelling framework 'SIMPLACE' and to parse the results of simulations. |
Authors: | Gunther Krauss [aut, cre] |
Maintainer: | Gunther Krauss <[email protected]> |
License: | GPL-2 |
Version: | 5.1.2 |
Built: | 2024-11-08 05:44:18 UTC |
Source: | https://github.com/gk-crop/simplace_rpkg |
Call to the shutDown method of the simulation.
closeProject(simplace)
closeProject(simplace)
simplace |
handle to the SimplaceWrapper object returned by |
No return value, called for the side effect of closing the simulation project
Creates a simulation from the opened project and substitutes the values of the parameters given in the parameter list. Simulation won't be queued by default.
createSimulation(simplace, parameterList = NULL, queue = FALSE)
createSimulation(simplace, parameterList = NULL, queue = FALSE)
simplace |
handle to the SimplaceWrapper object returned by |
parameterList |
a list with the parameter name as key and parametervalue as value |
queue |
boolean - simulation is added to queue if true, else start new queue |
id of the created simulation
runSimulations
, resetSimulationQueue
Checks directories if they contain simplace_core, simplace_modules and optionally simplace_run (or a data directory given by the user) and returns the first match. There is no check whether the installation is really working.
findFirstSimplaceInstallation( directories = c(), tryStandardDirs = TRUE, simulationsDir = "simplace_run", ignoreSimulationsDir = FALSE )
findFirstSimplaceInstallation( directories = c(), tryStandardDirs = TRUE, simulationsDir = "simplace_run", ignoreSimulationsDir = FALSE )
directories |
a list of additional directories where to look - |
tryStandardDirs |
whether to check for typical installation directories (default) |
simulationsDir |
directory that contains user simulations (e.g. simplace_run) |
ignoreSimulationsDir |
don't check for the simulation dir |
Beside the checks for some standard directories (like home directory, current working dir and drives c: to g:) and their subdirectories (workspace, simplace, java/simplace) the user can give a vector of additional directories. Directories given by the user are checked first.
matching directory/ies as character vector
Checks directories if they contain simplace_core, simplace_modules and optionally simplace_run (or a data directory given by the user) and returns the matches. There is no check whether the installation is really working.
findSimplaceInstallations( directories = c(), tryStandardDirs = TRUE, firstMatchOnly = FALSE, simulationsDir = "simplace_run", ignoreSimulationsDir = FALSE, verbose = TRUE )
findSimplaceInstallations( directories = c(), tryStandardDirs = TRUE, firstMatchOnly = FALSE, simulationsDir = "simplace_run", ignoreSimulationsDir = FALSE, verbose = TRUE )
directories |
a list of additional directories where to look - |
tryStandardDirs |
whether to check for typical installation directories (default) |
firstMatchOnly |
returns only the first installation found |
simulationsDir |
directory that contains user simulations (e.g. simplace_run) |
ignoreSimulationsDir |
don't check for the simulation dir |
verbose |
prints messages if no or more than one installation found |
Beside the checks for some standard directories (like home directory, current working dir and drives c: to g:) and their subdirectories (workspace, simplace, java/simplace) the user can give a vector of additional directories.
matching directory/ies as character vector
Get the datatypes of each variable (i.e. data column). The output is a named character vector, where each element is named by the variables name.
getDatatypesOfResult(result)
getDatatypesOfResult(result)
result |
handle to the data container returned by |
named character vector with the datatypes
The output is a JavaObject containing the variable names,
data types, units and the values. Output can be converted
with resultToList
or resultToDataframe
to R objects. Only MEMORY outputs are accessible. For CSV or
database outputs you have to read the data by generic methods.
getResult(simplace, outputId, simulationId = nullString)
getResult(simplace, outputId, simulationId = nullString)
simplace |
handle to the SimplaceWrapper object returned by |
outputId |
id of the output. Only MEMORY outputs are accessible. |
simulationId |
id of the simulation |
handle to the data container which has to be processed afterwards
Get the directories (work-, output-, projects- and data-dir)
getSimplaceDirectories(simplace)
getSimplaceDirectories(simplace)
simplace |
handle to the SimplaceWrapper object returned by |
character vector with the directories
Returns a vector with the IDs of the simulations. IDs are required to get the output of the simulations.
getSimulationIDs(simplace)
getSimulationIDs(simplace)
simplace |
handle to the SimplaceWrapper object |
character vector with the IDs
Get the units of each variable (i.e. data column) in a human readable format. The output is a named character vector, where each element is named by the variables name.
getUnitsOfResult(result)
getUnitsOfResult(result)
result |
handle to the data container returned by |
named character vector with the units
Initializes the JVM and creates the SimplaceWrapper object which is used to interact with Simplace.
initSimplace( InstallationDir = findFirstSimplaceInstallation(), WorkDir = paste0(InstallationDir, "simplace_run/simulation/"), OutputDir = paste0(InstallationDir, "simplace_run/output/"), ProjectsDir = nullString, DataDir = nullString, additionalClasspaths = c(), javaparameters = getOption("java.parameters"), force.init = TRUE )
initSimplace( InstallationDir = findFirstSimplaceInstallation(), WorkDir = paste0(InstallationDir, "simplace_run/simulation/"), OutputDir = paste0(InstallationDir, "simplace_run/output/"), ProjectsDir = nullString, DataDir = nullString, additionalClasspaths = c(), javaparameters = getOption("java.parameters"), force.init = TRUE )
InstallationDir |
directory where simplace_core, simplace_modules and simplace_run are located |
WorkDir |
working directory where solutions, projects and data resides (_WORKDIR_) |
OutputDir |
directory for output (_OUTPUTDIR_) |
ProjectsDir |
optional directory for project data (_PROJECTSDIR_) |
DataDir |
optional directory for data (_DATADIR_) |
additionalClasspaths |
vector with class paths relative to InstallationDir that are to be added |
javaparameters |
parameters that are passed to the java virtual machine |
force.init |
(re)initialize a running JVM, see |
handle to the SimplaceWrapper object
Initialises Simplace with work- and outputdir for different settings
initSimplaceDefault(setting = "run")
initSimplaceDefault(setting = "run")
setting |
one of "run", "modules"," lapclient" or "wininstall" |
handle to the SimplaceWrapper object
Initializes a project. Solution is mandatory, project is optional. Solution and project files can be specified by giving absolute paths or paths relative to the simplace directory. Instead of using solution and project files, one can use the content of the solution / project directly as a string or a "xml_document" class.
openProject(simplace, solution, project = nullString, parameterList = NULL)
openProject(simplace, solution, project = nullString, parameterList = NULL)
simplace |
handle to the SimplaceWrapper object returned by |
solution |
solution file with absolute path or path relative to workdir |
project |
project file with absolute path or path relative to workdir, can be omitted to run solution only |
parameterList |
a list with the parameter name as key and parametervalue as value |
invisibly a list with java FWSimsession object as well as the solution, project and parameterList
Simulation list is cleared
resetSimulationQueue(simplace)
resetSimulationQueue(simplace)
simplace |
handle to the SimplaceWrapper object returned by |
No return value, called for the side effect of clearing the simulation list
createSimulation
, runSimulations
All scalar output columns are transformed to appropriate R objects and then glued together in a dataframe. Array outputs columns are ignored.
resultToDataframe(result, expand = FALSE, from = NULL, to = NULL)
resultToDataframe(result, expand = FALSE, from = NULL, to = NULL)
result |
handle to the data container returned by |
expand |
if true columns with arrays are partially expanded |
from |
start of the result range, if to/from are not set, full result is returned |
to |
end of the result range, if to/from are not set, full result is returned |
data.frame with scalar output columns
resultToList
returns the output columns as list
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameter <- list(vTempLimit = 32) simid <- createSimulation(simplace,parameter) runSimulations(simplace) result <- getResult(simplace,"DIAGRAM_OUT", simid); closeProject(simplace) resultframe <- resultToDataframe(result) resultframe[3,] ## End(Not run)
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameter <- list(vTempLimit = 32) simid <- createSimulation(simplace,parameter) runSimulations(simplace) result <- getResult(simplace,"DIAGRAM_OUT", simid); closeProject(simplace) resultframe <- resultToDataframe(result) resultframe[3,] ## End(Not run)
Converts all scalar output columns to appropriate R lists. Columns containing arrays are left unchanged, unless expand is TRUE.
resultToList(result, expand = FALSE, from = NULL, to = NULL)
resultToList(result, expand = FALSE, from = NULL, to = NULL)
result |
handle to the data container returned by |
expand |
if true columns with arrays are partially expanded |
from |
start of the result range, if to/from are not set, full result is returned |
to |
end of the result range, if to/from are not set, full result is returned |
list with output columns
resultToDataframe
returns the scalar output columns as data.frame
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameter <- list(vTempLimit = 32) simid <- createSimulation(simplace,parameter) runSimulations(simplace) closeProject(simplace) result <- getResult(simplace,"DIAGRAM_OUT", simid); resultlist <- resultToList(result) resultlist$CURRENT.DATE ## End(Not run)
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameter <- list(vTempLimit = 32) simid <- createSimulation(simplace,parameter) runSimulations(simplace) closeProject(simplace) result <- getResult(simplace,"DIAGRAM_OUT", simid); resultlist <- resultToList(result) resultlist$CURRENT.DATE ## End(Not run)
Runs the simulation(s) as defined in the solution and project files. There is no accessible MEMORY output, but one can load the CSV or database output.
runProject(simplace)
runProject(simplace)
simplace |
handle to the SimplaceWrapper object returned by |
No return value, called for the side effect of running opened project
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution, Project) runProject(simplace) closeProject(simplace) ## End(Not run)
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution, Project) runProject(simplace) closeProject(simplace) ## End(Not run)
Run the created simulations from the queue. If the queue is empty, the last created simulation will be run.
runSimulations(simplace, selectsimulation = FALSE)
runSimulations(simplace, selectsimulation = FALSE)
simplace |
handle to the SimplaceWrapper object returned by |
selectsimulation |
if true keeps a selected simulation |
No return value, called for the side effect of running the simulation
createSimulation
, resetSimulationQueue
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameters <- list() parameters$vBaseLUE <- 3.0 s1 <- createSimulation(simplace, parameters,queue=TRUE) parameters$vBaseLUE <- 3.2 s2 <- createSimulation(simplace, parameters,queue=TRUE) runSimulations(simplace) parameters$vBaseLUE <- 2.8 s3 <- createSimulation(simplace, parameters,queue=TRUE) runSimulations(simplace) closeProject(simplace) ## End(Not run)
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameters <- list() parameters$vBaseLUE <- 3.0 s1 <- createSimulation(simplace, parameters,queue=TRUE) parameters$vBaseLUE <- 3.2 s2 <- createSimulation(simplace, parameters,queue=TRUE) runSimulations(simplace) parameters$vBaseLUE <- 2.8 s3 <- createSimulation(simplace, parameters,queue=TRUE) runSimulations(simplace) closeProject(simplace) ## End(Not run)
Sets values of arbitrary SimVariables in a simplace simulation. Useful if you want to couple simplace with another simulation and interchange values daily.
setAllSimulationValues(simplace, parameterLists = NULL)
setAllSimulationValues(simplace, parameterLists = NULL)
simplace |
handle to the SimplaceWrapper object returned by |
parameterLists |
a list of parameter lists for each simulation |
No return value, called for the side effect of changing parameters in all simulations
## Not run: for(i in 1:365) { params <- list() params[[1]] <- list(vBaseLUE=3.0 + i/2000) params[[2]] <- list(vBaseLUE=3.0 - i/2000) setAllSimulationValues(simplace,params) stepAllSimulations(simplace) } ## End(Not run)
## Not run: for(i in 1:365) { params <- list() params[[1]] <- list(vBaseLUE=3.0 + i/2000) params[[2]] <- list(vBaseLUE=3.0 - i/2000) setAllSimulationValues(simplace,params) stepAllSimulations(simplace) } ## End(Not run)
Sets the check level. OFF does no check at all, STRICT the most severe.
You have to call initSimplace
first.
setCheckLevel(simplace, level)
setCheckLevel(simplace, level)
simplace |
handle to the SimplaceWrapper object returned by |
level |
is a string with possible values: "CUSTOM,"STRICT","INTENSE","LAZY","OFF","ONLY" |
No return value, called for the side effect of setting the check level
## Not run: setCheckLevel(simplace, "STRICT") ## End(Not run)
## Not run: setCheckLevel(simplace, "STRICT") ## End(Not run)
Sets the level of logger output - FATAL is least verbose,
TRACE most verbose. You have to call initSimplace
first.
setLogLevel(level)
setLogLevel(level)
level |
is a string with possible values: FATAL, ERROR, WARN, INFO, DEBUG, TRACE |
No return value, called for the side effect of setting the log level
## Not run: setLogLevel("INFO") ## End(Not run)
## Not run: setLogLevel("INFO") ## End(Not run)
You have to call the function after initSimplace
but before openProject
.
setProjectLines(simplace, lines)
setProjectLines(simplace, lines)
simplace |
handle to the SimplaceWrapper object returned by |
lines |
either a vector of integers or a string of numbers separated by commas |
No return value, called for the side effect of selecting project to be run
## Not run: setProjectLines(simplace, "1,3,6,9-17,33") setProjectLines(simplace, c(1,2,3,9:17,33)) ## End(Not run)
## Not run: setProjectLines(simplace, "1,3,6,9-17,33") setProjectLines(simplace, c(1,2,3,9:17,33)) ## End(Not run)
One can specify all or only some of the directories. Only the directories specified will be set.
setSimplaceDirectories( simplace, WorkDir = nullString, OutputDir = nullString, ProjectsDir = nullString, DataDir = nullString )
setSimplaceDirectories( simplace, WorkDir = nullString, OutputDir = nullString, ProjectsDir = nullString, DataDir = nullString )
simplace |
handle to the SimplaceWrapper object returned by |
WorkDir |
working directory where solutions, projects and data resides (_WORKDIR_) |
OutputDir |
directory for output (_OUTPUTDIR_) |
ProjectsDir |
optional directory for project data (_PROJECTSDIR_) |
DataDir |
optional directory for data (_DATADIR_) |
No return value, called for the side effect of setting framework directories
Sets values of arbitrary SimVariables in a simplace simulation. Useful if you want to couple simplace with another simulation and interchange values daily.
setSimulationValues(simplace, parameterList = NULL, simulationNumber = 1)
setSimulationValues(simplace, parameterList = NULL, simulationNumber = 1)
simplace |
handle to the SimplaceWrapper object returned by |
parameterList |
a list with the parameter name as key and parametervalue as value |
simulationNumber |
number of simulation in the queue whose parameters should be set (default first simulation) |
No return value, called for the side effect of changing parameters in the current simulation
## Not run: for(i in 1:365) { param <- list(vBaseLUE=3.0 + i/2000) setSimulationValues(simplace,param) stepSimulation(simplace) } ## End(Not run)
## Not run: for(i in 1:365) { param <- list(vBaseLUE=3.0 + i/2000) setSimulationValues(simplace,param) stepSimulation(simplace) } ## End(Not run)
Sets the number of processors that are used parallel.
The function can be used only after initSimplace
has been
called.
setSlotCount(count)
setSlotCount(count)
count |
number of processors |
No return value, called for the side effect of setting the number of processors used for simulation runs
Interface to interact with the modelling framework 'SIMPLACE' and to parse the results of simulations
Package needs a Java Runtime Environment as well as an installation of 'SIMPLACE'. See www.simplace.net for more information about 'SIMPLACE'.
Gunther Krauss
Useful links:
## Not run: SimplaceInstallationDir <- "D:/java/simplace/" SimplaceWorkDir <- "D:/java/simplace/simplace_run/simulation/" SimplaceOutputDir <- "D:/java/simplace/simplace_run/output/" Solution <- "D:/java/simplace/simplace_run/simulation/gk/solution/complete/Complete.sol.xml" simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameter <- list() parameter$vTempLimit <- 32 simid <- createSimulation(simplace,parameter) runSimulations(simplace) result <- getResult(simplace,"DIAGRAM_OUT", simid); closeProject(simplace) resultlist <- resultToList(result) resultframe <- resultToDataframe(result) ## End(Not run)
## Not run: SimplaceInstallationDir <- "D:/java/simplace/" SimplaceWorkDir <- "D:/java/simplace/simplace_run/simulation/" SimplaceOutputDir <- "D:/java/simplace/simplace_run/output/" Solution <- "D:/java/simplace/simplace_run/simulation/gk/solution/complete/Complete.sol.xml" simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) parameter <- list() parameter$vTempLimit <- 32 simid <- createSimulation(simplace,parameter) runSimulations(simplace) result <- getResult(simplace,"DIAGRAM_OUT", simid); closeProject(simplace) resultlist <- resultToList(result) resultframe <- resultToDataframe(result) ## End(Not run)
Performs count
steps of the simulation and returns the values from
the actual variable map. Can be called consecutively.
stepAllSimulations(simplace, count = 1, filter = NULL, parameterLists = NULL)
stepAllSimulations(simplace, count = 1, filter = NULL, parameterLists = NULL)
simplace |
handle to the SimplaceWrapper object returned by |
count |
number of steps to be performed |
filter |
vector of the variable names to be included in the result. If not set, all variables are returned |
parameterLists |
a list of parameter lists for each simulation |
handle to an array of data containers which has to be processed afterwards
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) createSimulation(simplace) vm <- stepAllSimulations(simplace,count=22) vm_s <- stepAllSimulations(simplace,filter=c("CURRENT.DATE","LintulBiomass.sWSO"),count=18) closeProject(simplace) ## End(Not run)
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) createSimulation(simplace) vm <- stepAllSimulations(simplace,count=22) vm_s <- stepAllSimulations(simplace,filter=c("CURRENT.DATE","LintulBiomass.sWSO"),count=18) closeProject(simplace) ## End(Not run)
Performs count
steps of the simulation and returns the values from
the actual variable map. Can be called consecutively.
stepSimulation( simplace, count = 1, filter = NULL, parameterList = NULL, simulationNumber = 1 )
stepSimulation( simplace, count = 1, filter = NULL, parameterList = NULL, simulationNumber = 1 )
simplace |
handle to the SimplaceWrapper object returned by |
count |
number of steps to be performed |
filter |
vector of the variable names to be included in the result. If not set, all variables are returned |
parameterList |
list of parameter values indexed by parameter name |
simulationNumber |
number of simulation in the queue that should be run stepwise (default first simulation) |
handle to the data container which has to be processed afterwards
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) createSimulation(simplace) vm <- stepSimulation(simplace,count=22) vm_s <- stepSimulation(simplace,filter=c("CURRENT.DATE","LintulBiomass.sWSO"),count=18) closeProject(simplace) ## End(Not run)
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) createSimulation(simplace) vm <- stepSimulation(simplace,count=22) vm_s <- stepSimulation(simplace,filter=c("CURRENT.DATE","LintulBiomass.sWSO"),count=18) closeProject(simplace) ## End(Not run)
Converts the varMap to a list. All elements are converted to appropriate R objects. Arrays are expanded to vectors by default.
varmapToList(varmap, expand = TRUE)
varmapToList(varmap, expand = TRUE)
varmap |
the varMap returned by |
expand |
if |
list with parameter name as key and parameter value as value
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) createSimulation(simplace) varmap <- stepSimulation(simplace,count=22) closeProject(simplace) varlist <- varmapToList(varmap) varlist$startdate - 365 varlist$LintulBiomass.sWSO ## End(Not run)
## Not run: simplace <- initSimplace(SimplaceInstallationDir,SimplaceWorkDir,SimplaceOutputDir) openProject(simplace, Solution) createSimulation(simplace) varmap <- stepSimulation(simplace,count=22) closeProject(simplace) varlist <- varmapToList(varmap) varlist$startdate - 365 varlist$LintulBiomass.sWSO ## End(Not run)