Simplace Documentation
Simplace is a Julia package to interact with the modeling framework Simplace.
Installing the Simplace Framework
For installing Simplace, please consult the webpage www.simplace.net. Notice that Simplace version 5.1, svn revision >=403 is required.
A brief guide to install Simplace:
- If you don't have installed Java, please install an appropriate version of the (JRE or JDK) from openjdk.org or adoptium.net (recommended).
- Get Simplace from www.simplace.net
- Install the
Simplacepackage in Julia:
julia> using Pkg; Pkg.add("Simplace")Functions
Simplace.closeProject — Method
closeProject(simplace)Closes the actual Simplace project
Simplace.createSimulation — Function
simid = createSimulation(simplace, parameterList)Creates a simulation and substitute parameters.
Returns the id of the currently created simulation.
Arguments
simplacehandle to the framework returned byinitSimplaceparameterList::Dicta dictionary where the keys correspond to parameter namesqueue::Boolis the simulation added to existing list or does it starts a new list
Examples
Create two simulations and run them
createSimulation(sh, Dict("vLUE" => 3.0))
createSimulation(sh, Dict("vLUE" => 3.2))
runSimulations(sh)Create a new simulation, but remove previous simulations
createSimulation(sh, Dict("vLUE" => 3.1), false)
runSimulations(sh)
Simplace.findFirstSimplaceInstallation — Function
installDir = findFirstSimplaceInstallation()Finds first installation of Simplace
Simplace.findSimplaceInstallations — Function
installDirs = findSimplaceInstallations()Returns a list of simplace installation folders.
The function checks in common locations if there are simplace_core, simplace_modules and (optionally) simplace_run subfolders.
One can give also a list of own candidate folders. Using autodetection makes the scripts more portable.
Arguments
directories::Union{String, Vector{String}}List of potential folderstryStandardDirs::Boolsearches in common places like~/workspaceord:/workspace/firstMatchOnly::Boolreturns only the first folder that matchessimulationDir::Stringname of the folder where simulations are storedignoreSimulationDir::Boolignores the existance ofsimulationDirin candidate folder
Simplace.getDatatypesOfResult — Method
dtypes = getDatatypesOfResult(result)Get the datatypes of the simulation result variables
Simplace.getResult — Function
result = getResult(simplace, outputId)Fetch output from a simulation.
Arguments
simplacehandle to the framework returned byinitSimplaceoutputId::Stringoutput id defined in the simulation setup (solution or project)simulationId::Stringoptional id of the simulation, default "" returns result of all simulations
Examples
runSimulations(sh)
result = getResult(sh, "PhenologyOutput")
data = resultToDict(result)Simplace.getSimplaceDirectories — Method
dirs = getSimplaceDirectories(simplace)Get the directories (work-, output-, projects- and data-dir)
Simplace.getSimulationIDs — Method
ids = getSimulationIDs(simplace)Get IDs of the simulations in the simulation list
Simplace.getUnitsOfResult — Method
units = getUnitsOfResult(result)Get the units of the simulation result variables
Simplace.getVariablenamesOfResult — Method
names = getVariablenamesOfResult(result)Get the variable names of simulation result
Simplace.initSimplace — Function
sh = initSimplace(installDir, workDir, outputDir)Initializes the Java Virtual Machine and instantiates the SimplaceWrapper object.
The function returns a handle to the Simplace framework which has to be used for subsequent function calls to the framework.
Arguments
installDir::String- folder where the subfolderssimplace_coreandsimplace_modules
are located.
workDir::String- folder where simulation data and parameter files are locatedoutputDir::String- folder where simulation results are writtenadditionalClasspathList::Union{String, Vector{String}} - list of additional classpathsjavaParameters::Union{String, Vector{String}}- parameters to initialise the JVM (e.g. amount of memory the JVM should use)
Examples
sh = initSimplace("~/ws/", "~/ws/simplace_run/simulation/", "~/output/")
openProject(sh, "~/ws/simplace_run/simulation/example/Simulation.sol.xml")
runProject(sh)
closeProject(sh)Simplace.initSimplaceDefault — Function
sh = initSimplaceDefault(setting)Initialises Simplace with work- and outputdir for different settings.
Available settings are "run", "modules", "lapclient" and "wininstall".
- run: use first simplace installation with workdir "simplace_run/simulation/" (default)
- modules: use first simplace installation with workdir "simplace_modules/test/"
- lapclient: use first simplace installation with workdir "lapclient/data/"
- wininstall: use the local or system installation of Simplace GUI with workdir "SIMPLACE_WORK" in the users home directory
Simplace.openProject — Function
openProject(simplace, solution)Opens a Simplace project from a solution and optional project file
Arguments
simplacehandle to the framework returned byinitSimplacesolution::Stringpath to a solution file (.sol.xml)project::Stringoptional path to a project file (.proj.xml) - default "" means no projectparameterList::Dicta dictionary where the keys correspond to parameter names
Examples
param = Dict("startdate" => "2020-01-01", "vLUE" => 3.0)
openProject(sh, "Yield.sol.xml", "", param)Simplace.resetSimulationQueue — Method
resetSimulationQueue(simplace)Clears the list of simulations
Simplace.resultToDict — Function
data = resultToDict(result, from::Integer = 0, to::Integer = 0)Convert simulation result to Dict()
If from and to are given, then only the according subset of data is returned. If the expand argument is set to false, then array values are not converted but returned as java object arrays.
Simplace.runProject — Method
runProject(simplace)Runs the opened project
Simplace.runSimulations — Function
runSimulations(simplace, selectsimulation::Bool=false)Run the created simulations in the simulation list.
Simplace.setAllSimulationValues — Function
setAllSimulationValues(simplace,
parameterList::Vector{<:Dict} = Vector{Dict}())Set the values for all simulations.
Simplace.setCheckLevel — Method
setCheckLevel(simplace, level::String)Sets the check level of the framework
Simplace.setLogLevel — Method
setLogLevel(level::String)Sets the log level of the framework
Valid log levels - sorted by verbosity - are "FATAL", "ERROR", "WARN", "INFO" and "DEBUG".
Simplace.setProjectLines — Method
setProjectLines(simplace, lines)Sets the lines of the project data files that should be used when running a project.
Arguments
simplacehandle to the framework returned byinitSimplacelines::String- string with line numbers or ranges of lines, separated by comma, e.g."2,5,7,10-15,30"
Examples
setProjectLines(sh, "2,5,7,10-15,30")
runProject(sh)Simplace.setSimplaceDirectories — Method
setSimplaceDirectories(simplace;
WorkDir::String = "",
OutputDir::String = "",
ProjectsDir::String = "",
DataDir::String = "" )Set working-, output-, projects- and data-directory
Simplace.setSimulationValues — Function
setSimulationValues(simplace, parameterList::Dict = Dict(),
simulationNumber::Integer = 1)Set the values of a simulation.
Simplace.setSlotCount — Method
setSlotCount(count::Integer)Sets number of used CPUs
Simplace.stepAllSimulations — Function
stepAllSimulations(simplace,
count::Integer = 1,
filter::Vector{String} = Vector{String}(),
parameterList::Vector{<:Dict} = Vector{Dict}())Runs all queued simulations for count days.
Simplace.stepSimulation — Function
stepSimulation(simplace,
count::Integer = 1,
filter::Vector{String} = Vector{String}(),
parameterList::Dict = Dict(),
simulationNumber::Integer = 1)Performs a simulation for count days.
Simplace.varmapToDict — Function
varmapToDict(varmap, expand = true)Convert simulation result to Dict()
If the expand argument is set to false, then array values are not converted but returned as java object arrays.
Examples
Running a project
using Simplace
# directory where simplace is installed
installDir = "d:/simplace/"
# configure path and choose simulation setup (solution, project)
workDir = joinpath(installDir, "simplace_run/simulation/")
outputDir = joinpath(installDir, "simplace_run/output/")
sol = joinpath(workDir, "gk/solution/complete/Complete.sol.xml")
proj = joinpath(workDir, "gk/project/complete/CompleteSensitivity.proj.xml")
# initialise simplace
sh = initSimplace(installDir, workDir, outputDir)
sess = openProject(sh, sol, proj)
runProject(sh)
closeProject(sh)Run a solution with changed parameters
using Simplace
# Directory where simplace is installed
installDir = "d:/simplace/"
workDir = joinpath(installDir, "simplace_run/simulation/")
outputDir = joinpath(installDir, "simplace_run/output/")
sol = joinpath(workDir, "gk/solution/complete/Complete.sol.xml")
# initialise simplace
sh = initSimplace(installDir, workDir, outputDir)
sess = openProject(sh, sol, "", Dict("enddate" => "1999-12-31"))
# create a simulation that starts in 1995 and set the light use efficiency parameter to 3.2
simid=createSimulation(sh, Dict("startdate" => "1995-01-01", "vBaseLUE" => 3.2))
setLogLevel("WARN")
runSimulations(sh)
setLogLevel("INFO")
closeProject(sh)
# fetch the result (java object) and convert it into a Julia Dict()
res = getResult(sh, "DIAGRAM_OUT", simid)
d = resultToDict(res)
print(d["AnthesisDate"])Using default locations for framework and simulations
If you keep the Simplace installation and simulations data in standard folders (e.g. ~/workspace/ or D:/workspace/ etc.), you can omit the specification of folders.
using Simplace
# define filenames relative to workdir
sol = "gk/solution/complete/Complete.sol.xml"
proj = "gk/project/complete/CompleteSensitivity.proj.xml"
# initialise simplace - it will auto-detect the framework location
sh = initSimplace()
sess = openProject(sh, sol, proj)
runProject(sh)
closeProject(sh)Index
Simplace.closeProjectSimplace.createSimulationSimplace.findFirstSimplaceInstallationSimplace.findSimplaceInstallationsSimplace.getDatatypesOfResultSimplace.getResultSimplace.getSimplaceDirectoriesSimplace.getSimulationIDsSimplace.getUnitsOfResultSimplace.getVariablenamesOfResultSimplace.initSimplaceSimplace.initSimplaceDefaultSimplace.openProjectSimplace.resetSimulationQueueSimplace.resultToDictSimplace.runProjectSimplace.runSimulationsSimplace.setAllSimulationValuesSimplace.setCheckLevelSimplace.setLogLevelSimplace.setProjectLinesSimplace.setSimplaceDirectoriesSimplace.setSimulationValuesSimplace.setSlotCountSimplace.stepAllSimulationsSimplace.stepSimulationSimplace.varmapToDict