sdOutput: Class Representation of a Simulation Output

Description Usage Format Details Fields Public Methods Definition Examples

Description

Represents a model simulation output obtained with the sdSimulate function. It contains the output trajectory, the auxiliary equations trajectory, the input time series variables trajectory, the simulation diagnostics and the postProcess function return value.

Usage

1

Format

An object of class R6ClassGenerator of length 24.

Details

It has methods for saving the output, graphically visualizing the stored trajectories ($plot()) and for summarizing the trajectories ($summary()).

Fields

outputId

The output id, generated in the initialization as: "Simulation Output " + Sys.time().

model

The model simulated. A sdStaticModelClass, a sdModelClass or a sdCoupledModelClass object.

scenario

The sdScenarioClass object used in the simulation, if any.

outTrajectory

In case of a sdStaticModelClass: a data.frame with the algebraic equations trajectories of the simulation. This data.frame have up to as many rows as elements in the time sequence and as many columns as variables in the eq list plus an additional column (the first) for the time sequence values. The names of the eq list will be used to label the columns of the algebraic equations data.frame.

In case of a sdModelClass or a sdCoupledModelClass: a data.frame with the ODE output of the simulation. This data.frame have up to as many rows as elements in the time sequence and as many columns as variables in the state list plus the number of auxiliary values returned in the second and following elements of the return list from DifferentialEquations, plus an additional column (the first) for the time sequence values. There will be one row for each element in times unless the integrator returns with an unrecoverable error. If the state list and the auxiliary values have a names attribute, they will be used to label the columns of the output data.frame.

auxTrajectory

Just in case of a sdModelClass or a sdCoupledModelClass: A data.frame with the auxiliary equations trajectories of the simulation. This data.frame have up to as many rows as elements in the time sequence and as many columns as variables in the aux list plus an additional column (the first) for the time sequence values. The names of the aux list will be used to label the columns of the auxiliary equations data.frame.

timeSeriesTrajectory

A data.frame with the time series variables simulation trajectories. This data.frame have up to as many rows as elements in the time sequence and as many columns as variables in the interpolation_ list plus an additional column (the first) for the time sequence values. The names of the input time series variables will be used to label the columns of the time series data.frame.

diagnostics

A string with the simulation diagnostics, e.g. number of steps taken, the last step size, root informations, etc. See diagnostics for more informations.

postProcess

The return value of the model PostProcessVars function.

Public Methods Definition

$print()

Print the last 10 rows of the data.frames trajectories.

$summary()

Print the data.frame trajectories summary.

$plot(..., xlab = NULL, ylab = NULL, main = NULL, sub = NULL, type = "l", maxRow = 2, maxCol = 2, plotSymbol = 1, symbolSize = 2.5, legendPosition = "topright", multipleYAxis = F, units = T, col = c("black", "red", "blue", "green4", "darkorange", "darkmagenta", "khaki4", "cyan", "gold2", "hotpink"))

Plot the formulas given in the ... argument using the data.frames trajectories.

Arguments

...

A list of strings with each element describing a formula with the variables to plot.

The formulas must follow the standard: "y", "y1 y2 yn", "y ~ x" or "y1 y2 yn ~ x".

Where yn are the n variables names to be plotted in the y-axis, separated by a white space, or a single y variable name;

the symbol ~ is the separator to be used in the formulas when passing the x variable;

and x is the name of the variable to be plotted in the x-axis, by default the simulation time sequence will be used in the x-axis and no variable name need to be informed (e.g. omitting "~ x").

When plotting more than one variable in the y-axis consider using the argument multipleYAxis = TRUE.

xlab

A list with the labels for the plots x-axis. Must have the same length as the argument '...'.

ylab

A list with the labels for the plots y-axis. Must have the same length as the argument '...'. In case of plotting multiple y variables and setting multipleYAxis = TRUE the corresponding elements of this list must be a vector with the same length of y variables to be plotted (n).

main

A list with the overall titles for the plots. Must have the same length as the argument '...'.

sub

A list with the sub titles for the plots. Must have the same length as the argument '...'.

type

What type of plot should be drawn. See plot for the available options. Default is 'l', for lines.

maxRow

The number of rows in the plots layout. Default is 2.

maxCol

The number of columns in the plots layout. Default is 2.

plotSymbol

The line type (lty) or the character to be used in plotting points (pch). See par, the parameters 'lty' and 'pch', for the detailed information about the possible values and their interpretation. Default is 1.

symbolSize

The line width, a positive number, defaulting to 2.5. The interpretation is device-specific, and some devices do not implement line widths less than one. (See the help on the device for details of the interpretation and the help on par for other details in the parameter 'lwd'.)

legendPosition

A single keyword from the list "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center". This places the legend on the inside of the plot frame at the given location. Partial argument matching is used. Default is "topright".

multipleYAxis

Logical; if TRUE, plot one y-axis range per y variable. If FALSE plot all the y variables in the same y-axis range. Default is FALSE.

units

Logical; If TRUE, concatenate the unit value stored in the model default scenario to the x-axis and y-axis label, when there is one variable per axis or multipleYAxis = TRUE. Default is FALSE.

col

A vector with the color of points or lines appearing in the legend. A selection of colors is used as default. If the amount of variables to be plotted is greater than the length of the selected colors, extra colors from the colors function will be used.

$saveSimulationTrajectories(path = "directory")

Save the simulation trajectories to text files, and the model and the scenario to XML files inside the path directory.

Arguments

path

A string with the directory name to save the files. If missing uses the outputId to name the created directory in the current working directory.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## Let's load the Arenstorf model from the sdsim repository and then simulate
# it to explore the output object functionalities 
arenstorf <- sdLoadModel(file = "Arenstorf", repository = TRUE)
outaren <- sdSimulate(model = arenstorf)

# print the output object to visualize the simulation diagnostics and 
# the last 10 lines of the variables trajectories
outaren$print()

# print the summary of all the variables trajectories
outaren$summary()

# visualize the entire output trajectory until the max.print
outaren$outTrajectory

# visualize the circular rotation of the bodies and
# the coordinates derivatives over time,
# concatenating the units of the variables stored in the default scenario;
outaren$plot("y1 ~ y2", "dy1 dy2", units = TRUE,
             main = c("Rotation Coordinates", 
                      "Rotation Coordinates Derivatives"))

# use multipleYAxis = TRUE for a better visualization of the derivatives
outaren$plot("dy1 dy2", multipleYAxis = TRUE,
             main = "Rotation Coordinates Derivatives")

# save the simulation trajectories for further use
outaren$saveSimulationTrajectories("Arenstorf")

EmbrapaInformaticaAgropecuaria/sdsim documentation built on May 10, 2019, 9:58 a.m.