This package relies on Rcpp and the CapsisBridgeClientLib C++ library to allow access to Capsis through gRPC calls.
export PKG_CONFIG_PATH=~/.local/lib/pkgconfigThe connection to the server is made through the MMInitialize function:
> MMInitialize("localhost:50002")
[1] 0
>
The argument string must contain the IP address and the port number separated by a colon.
The meta-models are embedded in a meta-model manager which can be loaded and saved. When loading a meta-model, the file must be located in a known directory on the server.
> MMLoad("D:\\projects\\java\\CapsisBridge\\javaserver\\data\\QC_FMU02664_MS2_NoChange_AliveVolume_ConiferousSpecies.zml")
-------------- load --------------
-------------- load OK -----------
[1] 0
>
Calling the CBGetStratumGroups method returns the available stratum groups in the meta-model manager instance. For example,
> MMGetStratumGroups()
-------------- getStratumGroups --------------
-------------- getStratumGroups OK -----------
-------------- getStratumGroups --------------
-------------- getStratumGroups OK -----------
[1] "RE1_NoChange" "RE1_Plus2Degrees" "RE1_Plus4Degrees" "RE1_Plus6Degrees" "RE2_NoChange"
[6] "RE2_Plus2Degrees" "RE2_Plus4Degrees" "RE2_Plus6Degrees" "RE3_NoChange" "RE3_Plus2Degrees"
[11] "RE3_Plus4Degrees" "RE3_Plus6Degrees" "RS2_NoChange" "RS2_Plus2Degrees" "RS2_Plus4Degrees"
[16] "RS2_Plus6Degrees"
>
Here the function returned 16 meta-models corresponding to different combinations of stratum groups (RE1, RE2, RE3, RS2) and climate scenarios (NoChange, Plus2Degrees, Plus4Degrees, Plus6Degrees).
The simulation can return different output types such as species specific volumes or basal areas. To get the available output types for a particular meta-model, use the MMGetPossibleOutputTypes with the name of the stratum group as argument:
> MMGetPossibleOutputTypes("RS2_Plus2Degrees")
-------------- getPossibleOutputTypes --------------
-------------- getPossibleOutputTypes OK -----------
-------------- getPossibleOutputTypes --------------
-------------- getPossibleOutputTypes OK -----------
[1] "Broadleaved" "Coniferous"
>
In this example, the meta-model of stratum group "RS2_Plus2Degrees" has two output types: the volume of broadleaved species and the volume or coniferous species.
The MMGetPrediction function makes it possible to obtain the prediction from a particular meta-model. For example, this call
> MMGetPrediction("RS2_Plus2Degrees", 50, 0, "Coniferous")
-------------- getPrediction --------------
-------------- getPrediction OK -----------
[1] 82.10176
>
returns the volume prediction at 50 years of age at the beginning of the simulation for coniferous species in the stratum group "RS2_Plus2Degrees".