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 Simplace package in Julia:
julia> using Pkg; Pkg.add("Simplace")

Functions

Simplace.createSimulationFunction
simid = createSimulation(simplace, parameterList)

Creates a simulation and substitute parameters.

Returns the id of the currently created simulation.

Arguments

  • simplace handle to the framework returned by initSimplace
  • parameterList::Dict a dictionary where the keys correspond to parameter names
  • queue::Bool is 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)
source
Simplace.findSimplaceInstallationsFunction
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 folders
  • tryStandardDirs::Bool searches in common places like ~/workspace or d:/workspace/
  • firstMatchOnly::Bool returns only the first folder that matches
  • simulationDir::String name of the folder where simulations are stored
  • ignoreSimulationDir::Bool ignores the existance of simulationDir in candidate folder
source
Simplace.getResultFunction
result = getResult(simplace, outputId)

Fetch output from a simulation.

Arguments

  • simplace handle to the framework returned by initSimplace
  • outputId::String output id defined in the simulation setup (solution or project)
  • simulationId::String optional id of the simulation, default "" returns result of all simulations

Examples

runSimulations(sh)
result = getResult(sh, "PhenologyOutput")
data = resultToDict(result)
source
Simplace.initSimplaceFunction
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 subfolders simplace_core and simplace_modules

are located.

  • workDir::String - folder where simulation data and parameter files are located
  • outputDir::String - folder where simulation results are written
  • additionalClasspathList::Union{String, Vector{String}} - list of additional classpaths
  • javaParameters::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)
source
Simplace.initSimplaceDefaultFunction
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
source
Simplace.openProjectFunction
openProject(simplace, solution)

Opens a Simplace project from a solution and optional project file

Arguments

  • simplace handle to the framework returned by initSimplace
  • solution::String path to a solution file (.sol.xml)
  • project::String optional path to a project file (.proj.xml) - default "" means no project
  • parameterList::Dict a dictionary where the keys correspond to parameter names

Examples

param = Dict("startdate" => "2020-01-01", "vLUE" => 3.0)
openProject(sh, "Yield.sol.xml", "", param)
source
Simplace.resultToDictFunction
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.

source
Simplace.runSimulationsFunction
runSimulations(simplace, selectsimulation::Bool=false)

Run the created simulations in the simulation list.

source
Simplace.setLogLevelMethod
setLogLevel(level::String)

Sets the log level of the framework

Valid log levels - sorted by verbosity - are "FATAL", "ERROR", "WARN", "INFO" and "DEBUG".

source
Simplace.setProjectLinesMethod
setProjectLines(simplace, lines)

Sets the lines of the project data files that should be used when running a project.

Arguments

  • simplace handle to the framework returned by initSimplace
  • lines::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)
source
Simplace.setSimplaceDirectoriesMethod
setSimplaceDirectories(simplace; 
WorkDir::String = "", 
OutputDir::String = "", 
ProjectsDir::String = "", 
DataDir::String = "" )

Set working-, output-, projects- and data-directory

source
Simplace.stepAllSimulationsFunction
stepAllSimulations(simplace, 
count::Integer = 1,
filter::Vector{String} = Vector{String}(),
parameterList::Vector{<:Dict} = Vector{Dict}())

Runs all queued simulations for count days.

source
Simplace.stepSimulationFunction
stepSimulation(simplace, 
count::Integer = 1,
filter::Vector{String} = Vector{String}(),
parameterList::Dict = Dict(), 
simulationNumber::Integer = 1)

Performs a simulation for count days.

source
Simplace.varmapToDictFunction
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.

source

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